feat(builders): add coverage and snapshot options for jest

This commit is contained in:
Jason Jean 2018-07-16 11:35:34 -04:00 committed by Victor Savkin
parent 84686d94c4
commit 74734c97f5
3 changed files with 66 additions and 2 deletions

View File

@ -45,7 +45,48 @@ describe('Jest Builder', () => {
);
});
it('should send the setupFile to jestCLI', () => {
it('should send other options to jestCLI', () => {
const runCLI = spyOn(jestCLI, 'runCLI').and.returnValue(
Promise.resolve({
results: {
success: true
}
})
);
const root = normalize('/root');
builder
.run({
root,
builder: '',
projectType: 'application',
options: {
jestConfig: './jest.config.js',
tsConfig: './tsconfig.test.json',
watch: false,
codeCoverage: true,
ci: true,
updateSnapshot: true
}
})
.toPromise();
expect(runCLI).toHaveBeenCalledWith(
{
globals: JSON.stringify({
'ts-jest': {
tsConfigFile: path.relative(root, './tsconfig.test.json')
},
__TRANSFORM_HTML__: true
}),
watch: false,
coverage: true,
ci: true,
updateSnapshot: true
},
['./jest.config.js']
);
});
it('should send the main to jestCLI', () => {
const runCLI = spyOn(jestCLI, 'runCLI').and.returnValue(
Promise.resolve({
results: {

View File

@ -15,7 +15,10 @@ export interface JestBuilderOptions {
jestConfig: string;
tsConfig: string;
watch: boolean;
ci?: boolean;
codeCoverage?: boolean;
setupFile?: string;
updateSnapshot?: boolean;
}
export default class JestBuilder implements Builder<JestBuilderOptions> {
@ -25,6 +28,9 @@ export default class JestBuilder implements Builder<JestBuilderOptions> {
const options = builderConfig.options;
const config: any = {
watch: options.watch,
coverage: options.codeCoverage,
ci: options.ci,
updateSnapshot: options.updateSnapshot,
globals: JSON.stringify({
'ts-jest': {
tsConfigFile: path.relative(builderConfig.root, options.tsConfig)

View File

@ -19,8 +19,25 @@
},
"watch": {
"type": "boolean",
"description": "Run tests when files change.",
"description":
"Run tests when files change. (https://jestjs.io/docs/en/cli#watch)",
"default": false
},
"codeCoverage": {
"type": "boolean",
"description":
"Export a code coverage report. (https://jestjs.io/docs/en/cli#coverage)"
},
"updateSnapshot": {
"type": "boolean",
"alias": "u",
"description":
"Re-record all failing snapshots. (https://jestjs.io/docs/en/cli#updatesnapshot)"
},
"ci": {
"type": "boolean",
"description":
"Fail on missing snapshots. (https://jestjs.io/docs/en/cli#ci)"
}
},
"required": ["jestConfig", "tsConfig"]