Skip to content

Instantly share code, notes, and snippets.

@jeserkin
Last active April 18, 2020 12:48
Show Gist options
  • Save jeserkin/2e417326418cde2b06bd97dbb79a3ec2 to your computer and use it in GitHub Desktop.
Save jeserkin/2e417326418cde2b06bd97dbb79a3ec2 to your computer and use it in GitHub Desktop.
Jest config to support testing in both IDE and CLI
module.exports = {
testMatch: ['**/+(*.)+(spec).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest'
},
resolver: '@nrwl/jest/plugins/resolver',
moduleFileExtensions: ['ts', 'js', 'html'],
collectCoverage: true,
coverageReporters: ['html', 'lcov', 'text'],
verbose: true,
coverageThreshold: {
global: {
statements: 100,
branches: 100,
functions: 100,
lines: 100
}
}
};
if (process.env.IDE) {
const fs = require('fs');
let path = '<rootDir>';
try {
if (fs.existsSync(process.cwd() + '/src/test-setup.ts')) {
path = process.cwd();
}
}
catch (e) {
}
module.exports.globals = {
'ts-jest': {
tsConfig: `${path}/tsconfig.spec.json`,
stringifyContentPathRegex: '\\.html$',
astTransformers: [
'jest-preset-angular/InlineHtmlStripStylesTransformer',
],
},
};
module.exports.setupFilesAfterEnv = [`${path}/src/test-setup.ts`];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment