debian-mirror-gitlab/jest.config.js

96 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-07-07 11:18:12 +05:30
const IS_EE = require('./config/helpers/is_ee_env');
2019-02-15 15:39:39 +05:30
const reporters = ['default'];
2019-07-31 22:56:46 +05:30
// To have consistent date time parsing both in local and CI environments we set
2019-12-21 20:55:43 +05:30
// the timezone of the Node process. https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/27738
2019-07-31 22:56:46 +05:30
process.env.TZ = 'GMT';
2019-02-15 15:39:39 +05:30
if (process.env.CI) {
reporters.push([
'jest-junit',
{
output: './junit_jest.xml',
},
]);
}
2019-12-21 20:55:43 +05:30
let testMatch = ['<rootDir>/spec/frontend/**/*_spec.js'];
if (IS_EE) {
testMatch.push('<rootDir>/ee/spec/frontend/**/*_spec.js');
}
2019-09-30 21:07:59 +05:30
// workaround for eslint-import-resolver-jest only resolving in test files
// see https://github.com/JoinColony/eslint-import-resolver-jest#note
2019-12-21 20:55:43 +05:30
const { filename: parentModuleName } = module.parent;
const isESLint = parentModuleName && parentModuleName.includes('/eslint-import-resolver-jest/');
2019-09-30 21:07:59 +05:30
if (isESLint) {
testMatch = testMatch.map(path => path.replace('_spec.js', ''));
}
2019-12-26 22:10:19 +05:30
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)$': '<rootDir>/spec/frontend/__mocks__/file_mock.js',
'emojis(/.*).json': '<rootDir>/fixtures/emojis$1.json',
'^spec/test_constants$': '<rootDir>/spec/frontend/helpers/test_constants',
2020-03-13 15:44:24 +05:30
'^jest/(.*)$': '<rootDir>/spec/frontend/$1',
2019-12-26 22:10:19 +05:30
};
2020-01-01 13:55:28 +05:30
const collectCoverageFrom = ['<rootDir>/app/assets/javascripts/**/*.{js,vue}'];
2019-12-26 22:10:19 +05:30
if (IS_EE) {
const rootDirEE = '<rootDir>/ee/app/assets/javascripts$1';
Object.assign(moduleNameMapper, {
'^ee(/.*)$': rootDirEE,
'^ee_component(/.*)$': rootDirEE,
'^ee_else_ce(/.*)$': rootDirEE,
2020-03-13 15:44:24 +05:30
'^ee_jest/(.*)$': '<rootDir>/ee/spec/frontend/$1',
2019-12-26 22:10:19 +05:30
});
2020-01-01 13:55:28 +05:30
collectCoverageFrom.push(rootDirEE.replace('$1', '/**/*.{js,vue}'));
2019-12-26 22:10:19 +05:30
}
2019-02-15 15:39:39 +05:30
// eslint-disable-next-line import/no-commonjs
module.exports = {
2020-01-01 13:55:28 +05:30
clearMocks: true,
2019-09-30 21:07:59 +05:30
testMatch,
2019-02-15 15:39:39 +05:30
moduleFileExtensions: ['js', 'json', 'vue'],
2019-12-26 22:10:19 +05:30
moduleNameMapper,
2020-01-01 13:55:28 +05:30
collectCoverageFrom,
2019-02-15 15:39:39 +05:30
coverageDirectory: '<rootDir>/coverage-frontend/',
coverageReporters: ['json', 'lcov', 'text-summary', 'clover'],
cacheDirectory: '<rootDir>/tmp/cache/jest',
modulePathIgnorePatterns: ['<rootDir>/.yarn-cache/'],
reporters,
2019-12-26 22:10:19 +05:30
setupFilesAfterEnv: ['<rootDir>/spec/frontend/test_setup.js', 'jest-canvas-mock'],
2019-02-15 15:39:39 +05:30
restoreMocks: true,
transform: {
2019-07-07 11:18:12 +05:30
'^.+\\.(gql|graphql)$': 'jest-transform-graphql',
2019-02-15 15:39:39 +05:30
'^.+\\.js$': 'babel-jest',
'^.+\\.vue$': 'vue-jest',
},
2019-07-07 11:18:12 +05:30
transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'],
timers: 'fake',
testEnvironment: '<rootDir>/spec/frontend/environment.js',
testEnvironmentOptions: {
IS_EE,
},
2019-02-15 15:39:39 +05:30
};
2019-12-21 20:55:43 +05:30
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);
}