const IS_EE = require('./config/helpers/is_ee_env'); 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', { output: './junit_jest.xml', }, ]); } let testMatch = ['/spec/frontend/**/*_spec.js']; if (IS_EE) { testMatch.push('/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 = { '^~(/.*)$': '/app/assets/javascripts$1', '^ee_component(/.*)$': '/app/assets/javascripts/vue_shared/components/empty_component.js', '^ee_else_ce(/.*)$': '/app/assets/javascripts$1', '^helpers(/.*)$': '/spec/frontend/helpers$1', '^vendor(/.*)$': '/vendor/assets/javascripts$1', '\\.(jpg|jpeg|png|svg)$': '/spec/frontend/__mocks__/file_mock.js', 'emojis(/.*).json': '/fixtures/emojis$1.json', '^spec/test_constants$': '/spec/frontend/helpers/test_constants', '^jest/(.*)$': '/spec/frontend/$1', }; const collectCoverageFrom = ['/app/assets/javascripts/**/*.{js,vue}']; if (IS_EE) { const rootDirEE = '/ee/app/assets/javascripts$1'; Object.assign(moduleNameMapper, { '^ee(/.*)$': rootDirEE, '^ee_component(/.*)$': rootDirEE, '^ee_else_ce(/.*)$': rootDirEE, '^ee_jest/(.*)$': '/ee/spec/frontend/$1', }); collectCoverageFrom.push(rootDirEE.replace('$1', '/**/*.{js,vue}')); } // eslint-disable-next-line import/no-commonjs module.exports = { clearMocks: true, testMatch, moduleFileExtensions: ['js', 'json', 'vue'], moduleNameMapper, collectCoverageFrom, coverageDirectory: '/coverage-frontend/', coverageReporters: ['json', 'lcov', 'text-summary', 'clover'], cacheDirectory: '/tmp/cache/jest', modulePathIgnorePatterns: ['/.yarn-cache/'], reporters, setupFilesAfterEnv: ['/spec/frontend/test_setup.js', 'jest-canvas-mock'], restoreMocks: true, transform: { '^.+\\.(gql|graphql)$': 'jest-transform-graphql', '^.+\\.js$': 'babel-jest', '^.+\\.vue$': 'vue-jest', }, transformIgnorePatterns: ['node_modules/(?!(@gitlab/ui)/)'], timers: 'fake', testEnvironment: '/spec/frontend/environment.js', testEnvironmentOptions: { IS_EE, }, }; 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); }