Skip to content

Commit 74734c9

Browse files
FrozenPandazvsavkin
authored andcommittedAug 29, 2018
feat(builders): add coverage and snapshot options for jest
1 parent 84686d9 commit 74734c9

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed
 

Diff for: ‎packages/builders/src/jest/jest.builder.spec.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,48 @@ describe('Jest Builder', () => {
4545
);
4646
});
4747

48-
it('should send the setupFile to jestCLI', () => {
48+
it('should send other options to jestCLI', () => {
49+
const runCLI = spyOn(jestCLI, 'runCLI').and.returnValue(
50+
Promise.resolve({
51+
results: {
52+
success: true
53+
}
54+
})
55+
);
56+
const root = normalize('/root');
57+
builder
58+
.run({
59+
root,
60+
builder: '',
61+
projectType: 'application',
62+
options: {
63+
jestConfig: './jest.config.js',
64+
tsConfig: './tsconfig.test.json',
65+
watch: false,
66+
codeCoverage: true,
67+
ci: true,
68+
updateSnapshot: true
69+
}
70+
})
71+
.toPromise();
72+
expect(runCLI).toHaveBeenCalledWith(
73+
{
74+
globals: JSON.stringify({
75+
'ts-jest': {
76+
tsConfigFile: path.relative(root, './tsconfig.test.json')
77+
},
78+
__TRANSFORM_HTML__: true
79+
}),
80+
watch: false,
81+
coverage: true,
82+
ci: true,
83+
updateSnapshot: true
84+
},
85+
['./jest.config.js']
86+
);
87+
});
88+
89+
it('should send the main to jestCLI', () => {
4990
const runCLI = spyOn(jestCLI, 'runCLI').and.returnValue(
5091
Promise.resolve({
5192
results: {

Diff for: ‎packages/builders/src/jest/jest.builder.ts

+6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export interface JestBuilderOptions {
1515
jestConfig: string;
1616
tsConfig: string;
1717
watch: boolean;
18+
ci?: boolean;
19+
codeCoverage?: boolean;
1820
setupFile?: string;
21+
updateSnapshot?: boolean;
1922
}
2023

2124
export default class JestBuilder implements Builder<JestBuilderOptions> {
@@ -25,6 +28,9 @@ export default class JestBuilder implements Builder<JestBuilderOptions> {
2528
const options = builderConfig.options;
2629
const config: any = {
2730
watch: options.watch,
31+
coverage: options.codeCoverage,
32+
ci: options.ci,
33+
updateSnapshot: options.updateSnapshot,
2834
globals: JSON.stringify({
2935
'ts-jest': {
3036
tsConfigFile: path.relative(builderConfig.root, options.tsConfig)

Diff for: ‎packages/builders/src/jest/schema.json

+18-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,25 @@
1919
},
2020
"watch": {
2121
"type": "boolean",
22-
"description": "Run tests when files change.",
22+
"description":
23+
"Run tests when files change. (https://jestjs.io/docs/en/cli#watch)",
2324
"default": false
25+
},
26+
"codeCoverage": {
27+
"type": "boolean",
28+
"description":
29+
"Export a code coverage report. (https://jestjs.io/docs/en/cli#coverage)"
30+
},
31+
"updateSnapshot": {
32+
"type": "boolean",
33+
"alias": "u",
34+
"description":
35+
"Re-record all failing snapshots. (https://jestjs.io/docs/en/cli#updatesnapshot)"
36+
},
37+
"ci": {
38+
"type": "boolean",
39+
"description":
40+
"Fail on missing snapshots. (https://jestjs.io/docs/en/cli#ci)"
2441
}
2542
},
2643
"required": ["jestConfig", "tsConfig"]

0 commit comments

Comments
 (0)
Please sign in to comment.