1
0
Fork 0
mirror of https://gitlab.com/bramw/baserow.git synced 2025-04-07 22:35:36 +00:00

Allow configuring the testApp with an optional setup function to be used by applications extending baserow.

This commit is contained in:
Nigel Gott 2022-02-02 14:22:19 +00:00
parent 21fd41de38
commit 7cfcb015a6
4 changed files with 22 additions and 36 deletions

View file

@ -1,4 +1,9 @@
// The main jest config file used to run all of our tests.
module.exports = {
// The rootDir used by jest must be the root of the repository so the premium tests
// and frontend code are contained within jest's rootDir. This is because:
// - Jest cannot collect coverage for files outside of its rootDir
// - Jest struggles to run tests which are outside of its rootDir.
rootDir: '..',
roots: ['<rootDir>/web-frontend/', '<rootDir>/premium/web-frontend'],
moduleDirectories: ['<rootDir>/web-frontend/node_modules/'],

View file

@ -12,7 +12,7 @@
"start": "nuxt start --hostname 0.0.0.0",
"eslint": "eslint -c .eslintrc.js --ext .js,.vue . ../premium/web-frontend",
"stylelint": "stylelint **/*.scss ../premium/web-frontend/**/*.scss --syntax scss",
"jest": "jest -i --verbose false",
"jest": "jest --verbose false",
"test": "yarn jest"
},
"dependencies": {
@ -64,6 +64,7 @@
"eslint-plugin-vue": "^7.14.0",
"flush-promises": "^1.0.2",
"jest": "^26.6.3",
"jest-serializer-vue": "^2.0.2",
"jsdom": "^16.6.0",
"jsdom-global": "^3.0.2",
"node-mocks-http": "^1.7.6",
@ -72,7 +73,6 @@
"stylelint": "^13.13.1",
"stylelint-config-standard": "^22.0.0",
"stylelint-webpack-plugin": "^3.0.1",
"vue-jest": "^3.0.3",
"jest-serializer-vue": "^2.0.2"
"vue-jest": "^3.0.3"
}
}

View file

@ -12,7 +12,7 @@ import flushPromises from 'flush-promises'
* Uses the real baserow plugins to setup a Vuex store and baserow registry
* correctly.
*/
function _createBaserowStoreAndRegistry(app, vueContext) {
function _createBaserowStoreAndRegistry(app, vueContext, extraPluginSetupFunc) {
const store = new vueContext.vuex.Store({})
setupCore({ store, app }, (name, dep) => {
@ -26,10 +26,14 @@ function _createBaserowStoreAndRegistry(app, vueContext) {
store.$client = app.client
store.app = app
app.$store = store
setupDatabasePlugin({
const setupContext = {
store,
app,
})
}
setupDatabasePlugin(setupContext)
if (extraPluginSetupFunc) {
extraPluginSetupFunc(setupContext)
}
return store
}
@ -59,7 +63,7 @@ function _createBaserowStoreAndRegistry(app, vueContext) {
*
*/
export class TestApp {
constructor() {
constructor(extraPluginSetupFunc = null) {
this.mock = new MockAdapter(axios, { onNoMatch: 'throwException' })
// In the future we can extend this stub realtime implementation to perform
// useful testing of realtime interaction in the frontend!
@ -88,7 +92,11 @@ export class TestApp {
},
}
this._vueContext = bootstrapVueContext()
this.store = _createBaserowStoreAndRegistry(this._app, this._vueContext)
this.store = _createBaserowStoreAndRegistry(
this._app,
this._vueContext,
extraPluginSetupFunc
)
this._initialCleanStoreState = _.cloneDeep(this.store.state)
this.mockServer = new MockServer(this.mock, this.store)
this.failTestOnErrorResponse = true

View file

@ -2423,11 +2423,6 @@ ansi-regex@^5.0.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75"
integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==
ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
@ -6924,16 +6919,6 @@ jest-jasmine2@^26.6.3:
pretty-format "^26.6.2"
throat "^5.0.0"
jest-junit@^13.0.0:
version "13.0.0"
resolved "https://registry.yarnpkg.com/jest-junit/-/jest-junit-13.0.0.tgz#479be347457aad98ae8a5983a23d7c3ec526c9a3"
integrity sha512-JSHR+Dhb32FGJaiKkqsB7AR3OqWKtldLd6ZH2+FJ8D4tsweb8Id8zEVReU4+OlrRO1ZluqJLQEETm+Q6/KilBg==
dependencies:
mkdirp "^1.0.4"
strip-ansi "^6.0.1"
uuid "^8.3.2"
xml "^1.0.1"
jest-leak-detector@^26.6.2:
version "26.6.2"
resolved "https://registry.yarnpkg.com/jest-leak-detector/-/jest-leak-detector-26.6.2.tgz#7717cf118b92238f2eba65054c8a0c9c653a91af"
@ -11126,13 +11111,6 @@ strip-ansi@^6.0.0:
dependencies:
ansi-regex "^5.0.0"
strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"
strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
@ -12049,7 +12027,7 @@ uuid@^3.3.2:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
uuid@^8.3.0, uuid@^8.3.2:
uuid@^8.3.0:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==
@ -12550,11 +12528,6 @@ xml-name-validator@^3.0.0:
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"
integrity sha512-A5CUptxDsvxKJEU3yO6DuWBSJz/qizqzJKOMIfUJHETbBw/sFaDxgd6fxm1ewUaM0jZ444Fc5vC5ROYurg/4Pw==
xml@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
integrity sha1-eLpyAgApxbyHuKgaPPzXS0ovweU=
xmlchars@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/xmlchars/-/xmlchars-2.2.0.tgz#060fe1bcb7f9c76fe2a17db86a9bc3ab894210cb"