2020-05-24 23:13:21 +05:30
|
|
|
const IS_EE = require('./config/helpers/is_ee_env');
|
|
|
|
const isESLint = require('./config/helpers/is_eslint');
|
2021-11-11 11:23:49 +05:30
|
|
|
const IS_JH = require('./config/helpers/is_jh_env');
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
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';
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const { TEST_HOST } = require('./spec/frontend/__helpers__/test_constants');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
module.exports = (path, options = {}) => {
|
|
|
|
const {
|
|
|
|
moduleNameMapper: extModuleNameMapper = {},
|
|
|
|
moduleNameMapperEE: extModuleNameMapperEE = {},
|
2021-11-11 11:23:49 +05:30
|
|
|
moduleNameMapperJH: extModuleNameMapperJH = {},
|
2021-04-29 21:17:54 +05:30
|
|
|
} = options;
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const reporters = ['default'];
|
2023-05-27 22:25:52 +05:30
|
|
|
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',
|
2023-06-20 00:43:36 +05:30
|
|
|
|
|
|
|
// Library wrappers
|
|
|
|
'^vuex$': '<rootDir>/app/assets/javascripts/lib/utils/vue3compat/vuex.js',
|
|
|
|
'^vue-apollo$': '<rootDir>/app/assets/javascripts/lib/utils/vue3compat/vue_apollo.js',
|
|
|
|
'^vue-router$': '<rootDir>/app/assets/javascripts/lib/utils/vue3compat/vue_router.js',
|
2023-05-27 22:25:52 +05:30
|
|
|
});
|
|
|
|
Object.assign(globals, {
|
|
|
|
'vue-jest': {
|
|
|
|
experimentalCSSCompile: false,
|
|
|
|
compiler: require.resolve('./config/vue3migration/compiler'),
|
|
|
|
compilerOptions: {
|
2023-07-09 08:55:56 +05:30
|
|
|
whitespace: 'preserve',
|
2023-05-27 22:25:52 +05:30
|
|
|
compatConfig: {
|
|
|
|
MODE: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
// 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
|
|
|
|
process.env.TZ = 'GMT';
|
|
|
|
|
|
|
|
if (process.env.CI) {
|
|
|
|
reporters.push([
|
|
|
|
'jest-junit',
|
|
|
|
{
|
2021-01-03 14:25:43 +05:30
|
|
|
outputName: './junit_jest.xml',
|
|
|
|
addFileAttribute: 'true',
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const glob = `${path}/**/*@([._])spec.js`;
|
2020-05-24 23:13:21 +05:30
|
|
|
let testMatch = [`<rootDir>/${glob}`];
|
|
|
|
if (IS_EE) {
|
|
|
|
testMatch.push(`<rootDir>/ee/${glob}`);
|
|
|
|
}
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
if (IS_JH) {
|
|
|
|
testMatch.push(`<rootDir>/jh/${glob}`);
|
|
|
|
}
|
2020-05-24 23:13:21 +05:30
|
|
|
// workaround for eslint-import-resolver-jest only resolving in test files
|
|
|
|
// see https://github.com/JoinColony/eslint-import-resolver-jest#note
|
|
|
|
if (isESLint(module)) {
|
2021-04-17 20:07:23 +05:30
|
|
|
testMatch = testMatch.map((modulePath) => modulePath.replace('_spec.js', ''));
|
2020-05-24 23:13:21 +05:30
|
|
|
}
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
const TEST_FIXTURES_PATTERN = 'test_fixtures(/.*)$';
|
2023-06-20 00:43:36 +05:30
|
|
|
const TEST_FIXTURES_HOME = '/tmp/tests/frontend/fixtures';
|
|
|
|
const TEST_FIXTURES_HOME_EE = '/tmp/tests/frontend/fixtures-ee';
|
|
|
|
const TEST_FIXTURES_STATIC_HOME = '/spec/frontend/fixtures/static';
|
|
|
|
const TEST_FIXTURES_RAW_LOADER_PATTERN = `(${TEST_FIXTURES_HOME}|${TEST_FIXTURES_STATIC_HOME}).*\\.html$`;
|
2021-02-22 17:27:13 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const moduleNameMapper = {
|
2023-03-04 22:38:38 +05:30
|
|
|
'^~(/.*)\\?(worker|raw)$': '<rootDir>/app/assets/javascripts$1',
|
|
|
|
'^(.*)\\?(worker|raw)$': '$1',
|
2020-05-24 23:13:21 +05:30
|
|
|
'^~(/.*)$': '<rootDir>/app/assets/javascripts$1',
|
|
|
|
'^ee_component(/.*)$':
|
|
|
|
'<rootDir>/app/assets/javascripts/vue_shared/components/empty_component.js',
|
2021-11-11 11:23:49 +05:30
|
|
|
'^jh_component(/.*)$':
|
|
|
|
'<rootDir>/app/assets/javascripts/vue_shared/components/empty_component.js',
|
2021-01-03 14:25:43 +05:30
|
|
|
'^shared_queries(/.*)$': '<rootDir>/app/graphql/queries$1',
|
2020-05-24 23:13:21 +05:30
|
|
|
'^ee_else_ce(/.*)$': '<rootDir>/app/assets/javascripts$1',
|
2021-11-11 11:23:49 +05:30
|
|
|
'^jh_else_ce(/.*)$': '<rootDir>/app/assets/javascripts$1',
|
2022-01-26 12:08:38 +05:30
|
|
|
'^any_else_ce(/.*)$': '<rootDir>/app/assets/javascripts$1',
|
2021-03-08 18:12:59 +05:30
|
|
|
'^helpers(/.*)$': '<rootDir>/spec/frontend/__helpers__$1',
|
2020-05-24 23:13:21 +05:30
|
|
|
'^vendor(/.*)$': '<rootDir>/vendor/assets/javascripts$1',
|
2023-06-20 00:43:36 +05:30
|
|
|
[TEST_FIXTURES_PATTERN]: `<rootDir>${TEST_FIXTURES_HOME}$1`,
|
|
|
|
'^test_fixtures_static(/.*)$': `<rootDir>${TEST_FIXTURES_STATIC_HOME}$1`,
|
2020-05-24 23:13:21 +05:30
|
|
|
'\\.(jpg|jpeg|png|svg|css)$': '<rootDir>/spec/frontend/__mocks__/file_mock.js',
|
2023-04-23 21:23:45 +05:30
|
|
|
'\\.svg\\?url$': '<rootDir>/spec/frontend/__mocks__/file_mock.js',
|
2022-08-13 15:12:31 +05:30
|
|
|
'^public(/.*)$': '<rootDir>/public$1',
|
2020-05-24 23:13:21 +05:30
|
|
|
'emojis(/.*).json': '<rootDir>/fixtures/emojis$1.json',
|
2021-03-08 18:12:59 +05:30
|
|
|
'^spec/test_constants$': '<rootDir>/spec/frontend/__helpers__/test_constants',
|
2020-05-24 23:13:21 +05:30
|
|
|
'^jest/(.*)$': '<rootDir>/spec/frontend/$1',
|
2022-07-23 23:45:48 +05:30
|
|
|
'^ee_else_ce_jest/(.*)$': '<rootDir>/spec/frontend/$1',
|
2021-04-29 21:17:54 +05:30
|
|
|
'^jquery$': '<rootDir>/node_modules/jquery/dist/jquery.slim.js',
|
2023-03-04 22:38:38 +05:30
|
|
|
'^@sentry/browser$': '<rootDir>/app/assets/javascripts/sentry/sentry_browser_wrapper.js',
|
2023-06-20 00:43:36 +05:30
|
|
|
'^dexie$': '<rootDir>/node_modules/dexie/dist/dexie.min.js',
|
2021-04-29 21:17:54 +05:30
|
|
|
...extModuleNameMapper,
|
2023-05-27 22:25:52 +05:30
|
|
|
...vueModuleNameMappers,
|
2020-05-24 23:13:21 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
const collectCoverageFrom = ['<rootDir>/app/assets/javascripts/**/*.{js,vue}'];
|
|
|
|
|
|
|
|
if (IS_EE) {
|
|
|
|
const rootDirEE = '<rootDir>/ee/app/assets/javascripts$1';
|
2022-07-23 23:45:48 +05:30
|
|
|
const specDirEE = '<rootDir>/ee/spec/frontend/$1';
|
2020-05-24 23:13:21 +05:30
|
|
|
Object.assign(moduleNameMapper, {
|
|
|
|
'^ee(/.*)$': rootDirEE,
|
|
|
|
'^ee_component(/.*)$': rootDirEE,
|
|
|
|
'^ee_else_ce(/.*)$': rootDirEE,
|
2022-07-23 23:45:48 +05:30
|
|
|
'^ee_jest/(.*)$': specDirEE,
|
|
|
|
'^ee_else_ce_jest/(.*)$': specDirEE,
|
2022-01-26 12:08:38 +05:30
|
|
|
'^any_else_ce(/.*)$': rootDirEE,
|
|
|
|
'^jh_else_ee(/.*)$': rootDirEE,
|
2023-06-20 00:43:36 +05:30
|
|
|
[TEST_FIXTURES_PATTERN]: `<rootDir>${TEST_FIXTURES_HOME_EE}$1`,
|
2021-04-29 21:17:54 +05:30
|
|
|
...extModuleNameMapperEE,
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
collectCoverageFrom.push(rootDirEE.replace('$1', '/**/*.{js,vue}'));
|
|
|
|
}
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
if (IS_JH) {
|
2022-07-23 23:45:48 +05:30
|
|
|
// DO NOT add additional path to Jihu side, it might break things.
|
2021-11-11 11:23:49 +05:30
|
|
|
const rootDirJH = '<rootDir>/jh/app/assets/javascripts$1';
|
2022-07-23 23:45:48 +05:30
|
|
|
const specDirJH = '<rootDir>/jh/spec/frontend/$1';
|
2021-11-11 11:23:49 +05:30
|
|
|
Object.assign(moduleNameMapper, {
|
|
|
|
'^jh(/.*)$': rootDirJH,
|
|
|
|
'^jh_component(/.*)$': rootDirJH,
|
2022-07-23 23:45:48 +05:30
|
|
|
'^jh_jest/(.*)$': specDirJH,
|
2022-01-26 12:08:38 +05:30
|
|
|
// jh path alias https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74305#note_732793956
|
|
|
|
'^jh_else_ce(/.*)$': rootDirJH,
|
|
|
|
'^jh_else_ee(/.*)$': rootDirJH,
|
|
|
|
'^any_else_ce(/.*)$': rootDirJH,
|
2021-11-11 11:23:49 +05:30
|
|
|
...extModuleNameMapperJH,
|
|
|
|
});
|
|
|
|
|
|
|
|
collectCoverageFrom.push(rootDirJH.replace('$1', '/**/*.{js,vue}'));
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const coverageDirectory = () => {
|
|
|
|
if (process.env.CI_NODE_INDEX && process.env.CI_NODE_TOTAL) {
|
|
|
|
return `<rootDir>/coverage-frontend/jest-${process.env.CI_NODE_INDEX}-${process.env.CI_NODE_TOTAL}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '<rootDir>/coverage-frontend/';
|
|
|
|
};
|
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
const gfmParserDependencies = [
|
|
|
|
'rehype-.*',
|
|
|
|
'remark-.*',
|
|
|
|
'hast*',
|
|
|
|
'unist.*',
|
2022-07-23 23:45:48 +05:30
|
|
|
'markdown-table',
|
2022-06-21 17:19:12 +05:30
|
|
|
'mdast-util-.*',
|
|
|
|
'micromark.*',
|
|
|
|
'vfile.*',
|
|
|
|
'bail',
|
|
|
|
'trough',
|
|
|
|
'unified',
|
|
|
|
'is-plain-obj',
|
|
|
|
'decode-named-character-reference',
|
|
|
|
'character-entities*',
|
|
|
|
'property-information',
|
|
|
|
'space-separated-tokens',
|
|
|
|
'comma-separated-tokens',
|
|
|
|
'web-namespaces',
|
|
|
|
'zwitch',
|
|
|
|
'html-void-elements',
|
|
|
|
'ccount',
|
|
|
|
'escape-string-regexp',
|
|
|
|
];
|
|
|
|
|
|
|
|
const transformIgnoreNodeModules = [
|
2023-05-27 22:25:52 +05:30
|
|
|
'vue-test-utils-compat',
|
2022-06-21 17:19:12 +05:30
|
|
|
'@gitlab/ui',
|
|
|
|
'@gitlab/favicon-overlay',
|
2023-06-20 00:43:36 +05:30
|
|
|
'@gitlab/cluster-client',
|
2022-06-21 17:19:12 +05:30
|
|
|
'bootstrap-vue',
|
|
|
|
'three',
|
|
|
|
'monaco-editor',
|
|
|
|
'monaco-yaml',
|
2022-11-25 23:54:43 +05:30
|
|
|
'monaco-marker-data-provider',
|
|
|
|
'monaco-worker-manager',
|
2022-06-21 17:19:12 +05:30
|
|
|
'fast-mersenne-twister',
|
|
|
|
'prosemirror-markdown',
|
2022-08-27 11:52:29 +05:30
|
|
|
'marked',
|
2022-06-21 17:19:12 +05:30
|
|
|
'fault',
|
|
|
|
'dateformat',
|
|
|
|
'lowlight',
|
2022-08-27 11:52:29 +05:30
|
|
|
'vscode-languageserver-types',
|
2023-03-04 22:38:38 +05:30
|
|
|
'yaml',
|
2023-06-20 00:43:36 +05:30
|
|
|
'dexie',
|
2022-06-21 17:19:12 +05:30
|
|
|
...gfmParserDependencies,
|
|
|
|
];
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
return {
|
2023-05-27 22:25:52 +05:30
|
|
|
globals,
|
2020-05-24 23:13:21 +05:30
|
|
|
clearMocks: true,
|
|
|
|
testMatch,
|
2023-06-20 00:43:36 +05:30
|
|
|
moduleFileExtensions: ['js', 'json', 'vue', 'gql', 'graphql', 'yaml', 'yml', 'html'],
|
2020-05-24 23:13:21 +05:30
|
|
|
moduleNameMapper,
|
|
|
|
collectCoverageFrom,
|
|
|
|
coverageDirectory: coverageDirectory(),
|
|
|
|
coverageReporters: ['json', 'lcov', 'text-summary', 'clover'],
|
2021-04-29 21:17:54 +05:30
|
|
|
// We need ignore _worker code coverage since we are manually transforming it
|
|
|
|
coveragePathIgnorePatterns: ['<rootDir>/node_modules/', '_worker\\.js$'],
|
2020-05-24 23:13:21 +05:30
|
|
|
cacheDirectory: '<rootDir>/tmp/cache/jest',
|
|
|
|
modulePathIgnorePatterns: ['<rootDir>/.yarn-cache/'],
|
|
|
|
reporters,
|
2021-11-18 22:05:49 +05:30
|
|
|
resolver: './jest_resolver.js',
|
2023-05-27 22:25:52 +05:30
|
|
|
setupFilesAfterEnv,
|
2020-05-24 23:13:21 +05:30
|
|
|
restoreMocks: true,
|
2022-08-27 11:52:29 +05:30
|
|
|
slowTestThreshold: process.env.CI ? 6000 : 500,
|
2020-05-24 23:13:21 +05:30
|
|
|
transform: {
|
2022-11-25 23:54:43 +05:30
|
|
|
'^.+\\.(gql|graphql)$': './spec/frontend/__helpers__/graphql_transformer.js',
|
2021-04-29 21:17:54 +05:30
|
|
|
'^.+_worker\\.js$': './spec/frontend/__helpers__/web_worker_transformer.js',
|
2020-05-24 23:13:21 +05:30
|
|
|
'^.+\\.js$': 'babel-jest',
|
2023-05-27 22:25:52 +05:30
|
|
|
'^.+\\.vue$': VUE_JEST_TRANSFORMER,
|
2022-08-13 15:12:31 +05:30
|
|
|
'spec/frontend/editor/schema/ci/yaml_tests/.+\\.(yml|yaml)$':
|
|
|
|
'./spec/frontend/__helpers__/yaml_transformer.js',
|
2023-05-27 22:25:52 +05:30
|
|
|
'^.+\\.(md|zip|png|yml|yaml|sh|ps1)$': './spec/frontend/__helpers__/raw_transformer.js',
|
2023-06-20 00:43:36 +05:30
|
|
|
[TEST_FIXTURES_RAW_LOADER_PATTERN]: './spec/frontend/__helpers__/raw_transformer.js',
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
2022-06-21 17:19:12 +05:30
|
|
|
transformIgnorePatterns: [`node_modules/(?!(${transformIgnoreNodeModules.join('|')}))`],
|
2023-03-04 22:38:38 +05:30
|
|
|
fakeTimers: {
|
|
|
|
enableGlobally: true,
|
|
|
|
doNotFake: ['nextTick', 'setImmediate'],
|
|
|
|
legacyFakeTimers: true,
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
testEnvironment: '<rootDir>/spec/frontend/environment.js',
|
|
|
|
testEnvironmentOptions: {
|
|
|
|
IS_EE,
|
2021-11-11 11:23:49 +05:30
|
|
|
IS_JH,
|
2023-03-04 22:38:38 +05:30
|
|
|
url: TEST_HOST,
|
2020-05-24 23:13:21 +05:30
|
|
|
},
|
2022-08-27 11:52:29 +05:30
|
|
|
testRunner: 'jest-jasmine2',
|
2020-05-24 23:13:21 +05:30
|
|
|
};
|
|
|
|
};
|