gitlab-org--gitlab-foss/jest.config.js

104 lines
3.3 KiB
JavaScript
Raw Normal View History

2019-03-28 08:38:29 -04:00
const IS_EE = require('./config/helpers/is_ee_env');
2018-08-29 16:45:53 -04:00
const reporters = ['default'];
2019-04-26 09:36:34 -04:00
// 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
2019-04-26 09:36:34 -04:00
process.env.TZ = 'GMT';
2018-08-29 16:45:53 -04:00
if (process.env.CI) {
reporters.push([
'jest-junit',
{
output: './junit_jest.xml',
},
]);
}
let testMatch = ['<rootDir>/spec/frontend/**/*_spec.js'];
if (IS_EE) {
testMatch.push('<rootDir>/ee/spec/frontend/**/*_spec.js');
}
// workaround for eslint-import-resolver-jest only resolving in test files
// see https://github.com/JoinColony/eslint-import-resolver-jest#note
const { filename: parentModuleName } = module.parent;
const isESLint = parentModuleName && parentModuleName.includes('/eslint-import-resolver-jest/');
if (isESLint) {
testMatch = testMatch.map(path => path.replace('_spec.js', ''));
}
const moduleNameMapper = {
'^~(/.*)$': '<rootDir>/app/assets/javascripts$1',
'^ee_component(/.*)$':
'<rootDir>/app/assets/javascripts/vue_shared/components/empty_component.js',
'^ee_else_ce(/.*)$': '<rootDir>/app/assets/javascripts$1',
'^helpers(/.*)$': '<rootDir>/spec/frontend/helpers$1',
'^vendor(/.*)$': '<rootDir>/vendor/assets/javascripts$1',
'\\.(jpg|jpeg|png|svg|css)$': '<rootDir>/spec/frontend/__mocks__/file_mock.js',
'emojis(/.*).json': '<rootDir>/fixtures/emojis$1.json',
'^spec/test_constants$': '<rootDir>/spec/frontend/helpers/test_constants',
'^jest/(.*)$': '<rootDir>/spec/frontend/$1',
};
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',
});
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/';
};
2018-08-29 16:45:53 -04:00
// eslint-disable-next-line import/no-commonjs
module.exports = {
clearMocks: true,
testMatch,
2018-12-10 06:08:55 -05:00
moduleFileExtensions: ['js', 'json', 'vue'],
moduleNameMapper,
collectCoverageFrom,
coverageDirectory: coverageDirectory(),
2018-08-29 16:45:53 -04:00
coverageReporters: ['json', 'lcov', 'text-summary', 'clover'],
cacheDirectory: '<rootDir>/tmp/cache/jest',
modulePathIgnorePatterns: ['<rootDir>/.yarn-cache/'],
reporters,
setupFilesAfterEnv: ['<rootDir>/spec/frontend/test_setup.js', 'jest-canvas-mock'],
restoreMocks: true,
2018-12-10 06:08:55 -05:00
transform: {
2019-02-26 07:26:15 -05:00
'^.+\\.(gql|graphql)$': 'jest-transform-graphql',
2018-12-10 06:08:55 -05:00
'^.+\\.js$': 'babel-jest',
'^.+\\.vue$': 'vue-jest',
},
transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui|bootstrap-vue|three|monaco-editor)/)'],
2019-03-21 13:04:33 -04:00
timers: 'fake',
testEnvironment: '<rootDir>/spec/frontend/environment.js',
2019-03-28 08:38:29 -04:00
testEnvironmentOptions: {
IS_EE,
},
2018-08-29 16:45:53 -04:00
};
const karmaTestFile = process.argv.find(arg => arg.includes('spec/javascripts/'));
if (karmaTestFile) {
console.error(`
Files in spec/javascripts/ and ee/spec/javascripts need to be run with Karma.
Please use the following command instead:
yarn karma -f ${karmaTestFile}
`);
process.exit(1);
}