@namics/test-suite
Version:
jest test suite
97 lines (90 loc) • 3.04 kB
JavaScript
const fs = require('fs');
const chalk = require('chalk');
const path = require('path');
const paths = require('./paths');
module.exports = (resolve, rootDir, isEjecting) => {
// Use this instead of `paths.testsSetup` to avoid putting
// an absolute filename into configuration after ejecting.
const setupTestsFile = fs.existsSync(paths.testsSetup)
? '<rootDir>/src/setupTests.js'
: path.resolve(__dirname, 'enzymeConfig.js');
// in Jest configs. We need help from somebody with Windows to determine this.
const config = {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
setupFiles: [resolve('./src/polyfills.js')],
setupTestFrameworkScriptFile: setupTestsFile,
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs,ts,tsx}',
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs,ts,tsx}',
],
testEnvironment: 'node',
testURL: 'http://localhost',
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
'^.+\\.(js|jsx|mjs)$': resolve('./src/babelTransform.js'),
'^.+\\.css$': resolve('./src/cssTransform.js'),
'^(?!.*\\.(js|jsx|mjs|ts|tsx|css|json)$)': resolve('./src/fileTransform.js'),
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$',
'^.+\\.module\\.(css|sass|scss)$',
],
moduleNameMapper: {
'^react-native$': 'react-native-web',
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
},
moduleFileExtensions: ['web.js', 'js', 'json', 'web.jsx', 'jsx', 'node', 'mjs', 'ts', 'tsx'],
};
if (rootDir) {
config.rootDir = rootDir;
}
const overrides = Object.assign({}, require(paths.appPackageJson).jest);
const supportedKeys = [
'collectCoverageFrom',
'coverageReporters',
'coverageThreshold',
'resetMocks',
'resetModules',
'snapshotSerializers',
'watchPathIgnorePatterns',
];
if (overrides) {
supportedKeys.forEach(key => {
if (overrides.hasOwnProperty(key)) {
config[key] = overrides[key];
delete overrides[key];
}
});
const unsupportedKeys = Object.keys(overrides);
if (unsupportedKeys.length) {
const isOverridingSetupFile = unsupportedKeys.indexOf('setupTestFrameworkScriptFile') > -1;
if (isOverridingSetupFile) {
console.error(
chalk.red(
'We detected ' +
chalk.bold('setupTestFrameworkScriptFile') +
' in your package.json.\n\n' +
'Remove it from Jest configuration, and put the initialization code in ' +
chalk.bold('src/setupTests.js') +
'.\nThis file will be loaded automatically.\n'
)
);
} else {
console.error(
chalk.red(
'\nOut of the box, Test suite only supports overriding ' +
'these Jest options:\n\n' +
supportedKeys.map((key) => chalk.bold(' \u2022 ' + key)).join('\n') +
'.\n\n' +
'These options in your package.json Jest configuration ' +
'are not currently supported by Test suite:\n\n' +
unsupportedKeys.map((key) => chalk.bold(' \u2022 ' + key)).join('\n')
)
);
}
process.exit(1);
}
}
return config;
};
;