debian-mirror-gitlab/jest.config.base.js

103 lines
3.6 KiB
JavaScript
Raw Normal View History

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-03-08 18:12:59 +05:30
module.exports = (path) => {
2020-05-24 23:13:21 +05:30
const reporters = ['default'];
// 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
},
]);
}
const glob = `${path}/**/*_spec.js`;
let testMatch = [`<rootDir>/${glob}`];
if (IS_EE) {
testMatch.push(`<rootDir>/ee/${glob}`);
}
// 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-03-08 18:12:59 +05:30
testMatch = testMatch.map((path) => path.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(/.*)$';
2020-05-24 23:13:21 +05:30
const moduleNameMapper = {
'^~(/.*)$': '<rootDir>/app/assets/javascripts$1',
'^ee_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-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',
2021-02-22 17:27:13 +05:30
[TEST_FIXTURES_PATTERN]: '<rootDir>/tmp/tests/frontend/fixtures$1',
2020-05-24 23:13:21 +05:30
'\\.(jpg|jpeg|png|svg|css)$': '<rootDir>/spec/frontend/__mocks__/file_mock.js',
'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',
2020-10-24 23:57:45 +05:30
'test_helpers(/.*)$': '<rootDir>/spec/frontend_integration/test_helpers$1',
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';
Object.assign(moduleNameMapper, {
'^ee(/.*)$': rootDirEE,
'^ee_component(/.*)$': rootDirEE,
'^ee_else_ce(/.*)$': rootDirEE,
'^ee_jest/(.*)$': '<rootDir>/ee/spec/frontend/$1',
2021-02-22 17:27:13 +05:30
[TEST_FIXTURES_PATTERN]: '<rootDir>/tmp/tests/frontend/fixtures-ee$1',
2020-05-24 23:13:21 +05:30
});
collectCoverageFrom.push(rootDirEE.replace('$1', '/**/*.{js,vue}'));
}
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/';
};
return {
clearMocks: true,
testMatch,
moduleFileExtensions: ['js', 'json', 'vue'],
moduleNameMapper,
collectCoverageFrom,
coverageDirectory: coverageDirectory(),
coverageReporters: ['json', 'lcov', 'text-summary', 'clover'],
cacheDirectory: '<rootDir>/tmp/cache/jest',
modulePathIgnorePatterns: ['<rootDir>/.yarn-cache/'],
reporters,
2020-10-24 23:57:45 +05:30
setupFilesAfterEnv: [`<rootDir>/${path}/test_setup.js`, 'jest-canvas-mock'],
2020-05-24 23:13:21 +05:30
restoreMocks: true,
transform: {
'^.+\\.(gql|graphql)$': 'jest-transform-graphql',
'^.+\\.js$': 'babel-jest',
'^.+\\.vue$': 'vue-jest',
2021-02-22 17:27:13 +05:30
'^.+\\.(md|zip|png)$': 'jest-raw-loader',
2020-05-24 23:13:21 +05:30
},
2020-07-28 23:09:34 +05:30
transformIgnorePatterns: [
2021-03-08 18:12:59 +05:30
'node_modules/(?!(@gitlab/ui|@gitlab/favicon-overlay|bootstrap-vue|three|monaco-editor|monaco-yaml|fast-mersenne-twister)/)',
2020-07-28 23:09:34 +05:30
],
2020-05-24 23:13:21 +05:30
timers: 'fake',
testEnvironment: '<rootDir>/spec/frontend/environment.js',
testEnvironmentOptions: {
IS_EE,
},
};
};