Repository URL to install this package:
|
Version:
5.0.0 ▾
|
import { defaults as tsjPreset } from 'ts-jest/presets'
import { JestConfig } from '../declarations/JestConfig'
import { fromFileNamesToFirstExistingPath } from './deps.file'
function resolveTsConfig() {
return fromFileNamesToFirstExistingPath(
'./tsconfig.test.json',
'./tsconfig.json'
)
}
/**
* @see https://github.com/jpavon/react-scripts-ts/blob/master/scripts/test.js#L43
* @todo could `dopemerge`
* @todo should take in cli args as options too...
*/
const setupJestConfig = (dirName = '<rootDir>') => {
const jestConfig: JestConfig = {
verbose: true,
setupFilesAfterEnv: ['@skava/tests/setup.js'],
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'],
testMatch: [
// dirName + '/**/test/*.(j|t)s?(x)',
dirName + '/__tests__/**/*.(j|t)s?(x)',
dirName + '/src/**/__tests__/**/*.(j|t)s?(x)',
dirName + '/src/**/?(*.)(spec|test).(j|t)s?(x)',
],
testPathIgnorePatterns: [
// dirName + '/*/__todo/*.(j|t)s?(x)',
dirName + '/__tests__/deps/*.(j|t)s?(x)',
dirName + '/__tests__/fixtures/*.(j|t)s?(x)',
],
testEnvironment: 'node',
transform: {
// "^.+\\.tsx?$": require('path').resolve(__dirname, "./jest/typescriptTransform.js"),
// "^(?!.*\\.(js|jsx|mjs|css|json)$)": require('path').resolve(__dirname, "./jest/fileTransform.js)"),
'^.+\\.tsx?$': '@skava/tests/dist/jest/typescriptTransform.js',
// '^(?!.*\\.(js|jsx|mjs|css|json)$)': '@skava/tests/dist/jest/fileTransform.js',
...tsjPreset.transform,
},
moduleNameMapper: {
'^react-native$': 'react-native-web',
// @todo
// xmobx: resolveToRoot('node_modules/xmobx'),
},
moduleFileExtensions: [
'web.ts',
'ts',
'web.tsx',
'tsx',
'web.js',
'js',
'web.jsx',
'jsx',
'mjs',
'json',
'node',
],
globals: {
'ts-jest': {
// @todo may want this to resolve to root/
tsConfigFile: resolveTsConfig(),
// tsConfig: require(resolveTsConfig()),
/**
* @todo fixme
*/
// diagnostics: false,
diagnostics: {
warnOnly: true,
},
},
},
}
return jestConfig
}
const jestConfig = setupJestConfig()
process.env.FORCE_TRANSPILE_NODE_MODULES =
process.env.FORCE_TRANSPILE_NODE_MODULES === undefined
? undefined
: process.env.FORCE_TRANSPILE_NODE_MODULES
if (!process.env.FORCE_TRANSPILE_NODE_MODULES) {
jestConfig.transformIgnorePatterns = [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$',
]
}
export { setupJestConfig }
export { jestConfig }