-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
98e5bbc
commit e29f37e
Showing
7 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/jest/src/migrations/update-8-3-0/test-files/jest.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'] | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/jest/src/migrations/update-8-3-0/update-8-3-0.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters