diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-15 06:10:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-03-15 06:10:33 +0300 |
commit | 0555b45841cefbd64a7bff0d58f7cb3b5bd06d97 (patch) | |
tree | a4281f363c1e6743e0ebdb3d2f13002f08c5d418 /jest.config.base.js | |
parent | cd6194eb43ddf3df1e96dc836d06dce5f2b7c922 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'jest.config.base.js')
-rw-r--r-- | jest.config.base.js | 53 |
1 files changed, 46 insertions, 7 deletions
diff --git a/jest.config.base.js b/jest.config.base.js index 338d124144f..611853c019c 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -1,6 +1,15 @@ const IS_EE = require('./config/helpers/is_ee_env'); const isESLint = require('./config/helpers/is_eslint'); const IS_JH = require('./config/helpers/is_jh_env'); + +const { VUE_VERSION: EXPLICIT_VUE_VERSION } = process.env; +if (![undefined, '2', '3'].includes(EXPLICIT_VUE_VERSION)) { + throw new Error( + `Invalid VUE_VERSION value: ${EXPLICIT_VUE_VERSION}. Only '2' and '3' are supported`, + ); +} +const USE_VUE_3 = EXPLICIT_VUE_VERSION === '3'; + const { TEST_HOST } = require('./spec/frontend/__helpers__/test_constants'); module.exports = (path, options = {}) => { @@ -11,6 +20,38 @@ module.exports = (path, options = {}) => { } = options; const reporters = ['default']; + const VUE_JEST_TRANSFORMER = USE_VUE_3 ? '@vue/vue3-jest' : '@vue/vue2-jest'; + const setupFilesAfterEnv = [`<rootDir>/${path}/test_setup.js`, 'jest-canvas-mock']; + const vueModuleNameMappers = {}; + const globals = {}; + + if (EXPLICIT_VUE_VERSION) { + Object.assign(vueModuleNameMappers, { + '^@gitlab/ui/dist/([^.]*)$': [ + '<rootDir>/node_modules/@gitlab/ui/src/$1.vue', + '<rootDir>/node_modules/@gitlab/ui/src/$1.js', + ], + '^@gitlab/ui$': '<rootDir>/node_modules/@gitlab/ui/src/index.js', + }); + } + + if (USE_VUE_3) { + setupFilesAfterEnv.unshift(`<rootDir>/${path}/vue_compat_test_setup.js`); + Object.assign(vueModuleNameMappers, { + '^vue$': '@vue/compat', + '^@vue/test-utils$': '@vue/test-utils-vue3', + }); + Object.assign(globals, { + 'vue-jest': { + experimentalCSSCompile: false, + compilerOptions: { + compatConfig: { + MODE: 2, + }, + }, + }, + }); + } // To have consistent date time parsing both in local and CI environments we set // the timezone of the Node process. https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/27738 @@ -72,6 +113,7 @@ module.exports = (path, options = {}) => { '^jquery$': '<rootDir>/node_modules/jquery/dist/jquery.slim.js', '^@sentry/browser$': '<rootDir>/app/assets/javascripts/sentry/sentry_browser_wrapper.js', ...extModuleNameMapper, + ...vueModuleNameMappers, }; const collectCoverageFrom = ['<rootDir>/app/assets/javascripts/**/*.{js,vue}']; @@ -146,6 +188,7 @@ module.exports = (path, options = {}) => { ]; const transformIgnoreNodeModules = [ + 'vue-test-utils-compat', '@gitlab/ui', '@gitlab/favicon-overlay', 'bootstrap-vue', @@ -166,6 +209,7 @@ module.exports = (path, options = {}) => { ]; return { + globals, clearMocks: true, testMatch, moduleFileExtensions: ['js', 'json', 'vue', 'gql', 'graphql', 'yaml', 'yml'], @@ -179,14 +223,14 @@ module.exports = (path, options = {}) => { modulePathIgnorePatterns: ['<rootDir>/.yarn-cache/'], reporters, resolver: './jest_resolver.js', - setupFilesAfterEnv: [`<rootDir>/${path}/test_setup.js`, 'jest-canvas-mock'], + setupFilesAfterEnv, restoreMocks: true, slowTestThreshold: process.env.CI ? 6000 : 500, transform: { '^.+\\.(gql|graphql)$': './spec/frontend/__helpers__/graphql_transformer.js', '^.+_worker\\.js$': './spec/frontend/__helpers__/web_worker_transformer.js', '^.+\\.js$': 'babel-jest', - '^.+\\.vue$': '@vue/vue2-jest', + '^.+\\.vue$': VUE_JEST_TRANSFORMER, 'spec/frontend/editor/schema/ci/yaml_tests/.+\\.(yml|yaml)$': './spec/frontend/__helpers__/yaml_transformer.js', '^.+\\.(md|zip|png|yml|yaml|sh|ps1)$': './spec/frontend/__helpers__/raw_transformer.js', @@ -204,10 +248,5 @@ module.exports = (path, options = {}) => { url: TEST_HOST, }, testRunner: 'jest-jasmine2', - globals: { - '@vue/vue2-jest': { - experimentalCSSCompile: false, - }, - }, }; }; |