fix(testing): disable collectCoverage by default (#1586)
* fix(testing): disable collectCoverage by default Disabling collectCoverage by default as this causes issues with latest version of Jest Temp fix #1531 * Adding back code coverage reporters * feat(nx): add migration to update collectCoverage to false in jest.config.js Added new migration script to update jest.config.js collectCoverage property to false * refactor(nx): move migrations to @nrwl/jest Move the collectCoverage migration to the jest package * chore: refactor to use AST utils
This commit is contained in:
parent
98e5bbc100
commit
e29f37ef22
@ -139,7 +139,6 @@
|
||||
"node_modules",
|
||||
"<rootDir>/build/packages/angular/spec"
|
||||
],
|
||||
"collectCoverage": true,
|
||||
"coverageReporters": [
|
||||
"html"
|
||||
],
|
||||
|
||||
@ -1,3 +1,9 @@
|
||||
{
|
||||
"schematics": {}
|
||||
"schematics": {
|
||||
"update-8.3.0": {
|
||||
"version": "8.3.0",
|
||||
"description": "Update jest.config.js",
|
||||
"factory": "./src/migrations/update-8-3-0/update-8-3-0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
module.exports = {
|
||||
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||
transform: {
|
||||
'^.+\\.(ts|js|html)$': 'ts-jest'
|
||||
},
|
||||
resolver: '@nrwl/jest/plugins/resolver',
|
||||
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||
collectCoverage: true,
|
||||
coverageReporters: ['html']
|
||||
};
|
||||
@ -0,0 +1,35 @@
|
||||
import { Tree, mergeWith, url } from '@angular-devkit/schematics';
|
||||
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
|
||||
|
||||
import * as path from 'path';
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
describe('Update 8.3.0', () => {
|
||||
let initialTree: Tree;
|
||||
let schematicRunner: SchematicTestRunner;
|
||||
|
||||
beforeEach(async () => {
|
||||
initialTree = Tree.empty();
|
||||
schematicRunner = new SchematicTestRunner(
|
||||
'@nrwl/jest',
|
||||
path.join(__dirname, '../../../migrations.json')
|
||||
);
|
||||
});
|
||||
|
||||
it('should collectCoverage to false in the jest.config.js', async () => {
|
||||
initialTree.create(
|
||||
'jest.config.js',
|
||||
readFileSync(
|
||||
path.join(__dirname, './test-files/jest.config.js')
|
||||
).toString()
|
||||
);
|
||||
|
||||
const result = await schematicRunner
|
||||
.runSchematicAsync('update-8.3.0', {}, initialTree)
|
||||
.toPromise();
|
||||
|
||||
const updatedJestConfigFile = result.readContent('jest.config.js');
|
||||
|
||||
expect(updatedJestConfigFile).not.toContain('collectCoverage: true');
|
||||
});
|
||||
});
|
||||
40
packages/jest/src/migrations/update-8-3-0/update-8-3-0.ts
Normal file
40
packages/jest/src/migrations/update-8-3-0/update-8-3-0.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Rule, Tree } from '@angular-devkit/schematics';
|
||||
import { insert } from '@nrwl/workspace';
|
||||
import * as ts from 'typescript';
|
||||
import {
|
||||
getSourceNodes,
|
||||
RemoveChange
|
||||
} from '@nrwl/workspace/src/utils/ast-utils';
|
||||
|
||||
function updateJestConfig(host: Tree) {
|
||||
if (host.exists('jest.config.js')) {
|
||||
const contents = host.read('jest.config.js').toString();
|
||||
const sourceFile = ts.createSourceFile(
|
||||
'jest.config.js',
|
||||
contents,
|
||||
ts.ScriptTarget.Latest
|
||||
);
|
||||
const changes: RemoveChange[] = [];
|
||||
|
||||
getSourceNodes(sourceFile).forEach(node => {
|
||||
if (
|
||||
ts.isPropertyAssignment(node) &&
|
||||
ts.isIdentifier(node.name) &&
|
||||
node.name.text === 'collectCoverage'
|
||||
) {
|
||||
changes.push(
|
||||
new RemoveChange(
|
||||
'jest.config.js',
|
||||
node.getStart(sourceFile),
|
||||
node.getFullText(sourceFile)
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
insert(host, 'jest.config.js', changes);
|
||||
}
|
||||
}
|
||||
|
||||
export default function(): Rule {
|
||||
return updateJestConfig;
|
||||
}
|
||||
@ -5,6 +5,5 @@ module.exports = {
|
||||
},
|
||||
resolver: '@nrwl/jest/plugins/resolver',
|
||||
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||
collectCoverage: true,
|
||||
coverageReporters: ['html']
|
||||
};
|
||||
|
||||
@ -55,7 +55,6 @@ describe('Update 7.7.0', () => {
|
||||
},
|
||||
resolver: '@nrwl/builders/plugins/jest/resolver',
|
||||
moduleFileExtensions: ['ts', 'js', 'html'],
|
||||
collectCoverage: true,
|
||||
coverageReporters: ['html']
|
||||
};`
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user