Skip to content

Commit 972381b

Browse files
FrozenPandazmentzerjmehrad-rafigh
authored
feat(testing): update to jest-preset-angular v8.0.0 (nrwl#2401)
* feat(testing): update to jest-preset-angular v8.0.0 part 1 Updates to jest-preset-angular to v8.0.0, includes migrations to fix any existing projects affected by the jest-preset-angular update. closes nrwl#1979 * feat(testing): update jest-preset-angular to v8.0.0 part 2 Closed issues: nrwl#1979, nrwl#2165 Co-authored-by: Joshua D. Mentzer <[email protected]> * feat(testing): update jest-preset-angular to v8.0.0 part 3 Co-authored-by: mentzerj <[email protected]> Co-authored-by: Mehrad Rafigh <[email protected]>
1 parent adc2b2a commit 972381b

File tree

15 files changed

+536
-301
lines changed

15 files changed

+536
-301
lines changed

.prettierrc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
2-
"singleQuote": true,
3-
"endOfLine": "lf"
4-
}
1+
{
2+
"singleQuote": true,
3+
"endOfLine": "lf"
4+
}

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ While developing you may want to try out the changes you have made. The easier w
8080
yarn create-playground
8181
```
8282

83-
You can then go to `tmp/nx` (this is set up to use Nx CLI) or `tmp/angular` (this is set up to use Angular CLI), where you will find an empty workspace with your changes in it, something this that:
83+
You can then go to `tmp/nx` (this is set up to use Nx CLI) or `tmp/angular` (this is set up to use Angular CLI), where you will find an empty workspace with your changes in it.:
8484

8585
```bash
8686
yarn create-playground

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@
147147
"jasmine-spec-reporter": "~4.2.1",
148148
"jest": "^24.1.0",
149149
"jest-jasmine2": "^24.1.0",
150-
"jest-preset-angular": "7.0.0",
151-
"jest-worker": "24.9.0",
150+
"jest-preset-angular": "8.0.0",
151+
"jest-worker": "^25.1.0",
152152
"karma": "~4.0.0",
153153
"karma-chrome-launcher": "~2.2.0",
154154
"karma-coverage-istanbul-reporter": "~2.0.1",

packages/angular/src/schematics/application/application.spec.ts

+73-44
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ describe('app', () => {
9191
expect(tsconfigE2E.extends).toEqual('./tsconfig.json');
9292
});
9393

94+
it('should setup jest with serializers', async () => {
95+
const tree = await runSchematic('app', { name: 'myApp' }, appTree);
96+
97+
expect(tree.readContent('apps/my-app/jest.config.js')).toContain(
98+
`'jest-preset-angular/build/AngularSnapshotSerializer.js'`
99+
);
100+
expect(tree.readContent('apps/my-app/jest.config.js')).toContain(
101+
`'jest-preset-angular/build/HTMLCommentSerializer.js'`
102+
);
103+
});
104+
94105
it('should default the prefix to npmScope', async () => {
95106
const noPrefix = await runSchematic(
96107
'app',
@@ -350,53 +361,71 @@ describe('app', () => {
350361
});
351362
});
352363

353-
describe('--unit-test-runner karma', () => {
354-
it('should generate a karma config', async () => {
355-
const tree = await runSchematic(
356-
'app',
357-
{ name: 'myApp', unitTestRunner: 'karma' },
358-
appTree
359-
);
364+
describe('--unit-test-runner', () => {
365+
describe('default (jest)', () => {
366+
it('should generate jest.config.js with serializers', async () => {
367+
const tree = await runSchematic('app', { name: 'myApp' }, appTree);
360368

361-
expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeTruthy();
362-
expect(tree.exists('apps/my-app/karma.conf.js')).toBeTruthy();
363-
const workspaceJson = readJsonInTree(tree, 'workspace.json');
364-
expect(workspaceJson.projects['my-app'].architect.test.builder).toEqual(
365-
'@angular-devkit/build-angular:karma'
366-
);
367-
expect(
368-
workspaceJson.projects['my-app'].architect.lint.options.tsConfig
369-
).toEqual([
370-
'apps/my-app/tsconfig.app.json',
371-
'apps/my-app/tsconfig.spec.json'
372-
]);
373-
const tsconfigAppJson = readJsonInTree(
374-
tree,
375-
'apps/my-app/tsconfig.app.json'
376-
);
377-
expect(tsconfigAppJson.compilerOptions.outDir).toEqual(
378-
'../../dist/out-tsc'
379-
);
369+
expect(tree.readContent('apps/my-app/jest.config.js')).toContain(
370+
`'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js'`
371+
);
372+
expect(tree.readContent('apps/my-app/jest.config.js')).toContain(
373+
`'jest-preset-angular/build/AngularSnapshotSerializer.js'`
374+
);
375+
expect(tree.readContent('apps/my-app/jest.config.js')).toContain(
376+
`'jest-preset-angular/build/HTMLCommentSerializer.js'`
377+
);
378+
});
380379
});
381-
});
382380

383-
describe('--unit-test-runner none', () => {
384-
it('should not generate test configuration', async () => {
385-
const tree = await runSchematic(
386-
'app',
387-
{ name: 'myApp', unitTestRunner: 'none' },
388-
appTree
389-
);
390-
expect(tree.exists('apps/my-app/src/test-setup.ts')).toBeFalsy();
391-
expect(tree.exists('apps/my-app/src/test.ts')).toBeFalsy();
392-
expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy();
393-
expect(tree.exists('apps/my-app/jest.config.js')).toBeFalsy();
394-
expect(tree.exists('apps/my-app/karma.config.js')).toBeFalsy();
395-
const workspaceJson = readJsonInTree(tree, 'workspace.json');
396-
expect(workspaceJson.projects['my-app'].architect.test).toBeUndefined();
397-
expect(
398-
workspaceJson.projects['my-app'].architect.lint.options.tsConfig
399-
).toEqual(['apps/my-app/tsconfig.app.json']);
381+
describe('karma', () => {
382+
it('should generate a karma config', async () => {
383+
const tree = await runSchematic(
384+
'app',
385+
{ name: 'myApp', unitTestRunner: 'karma' },
386+
appTree
387+
);
388+
389+
expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeTruthy();
390+
expect(tree.exists('apps/my-app/karma.conf.js')).toBeTruthy();
391+
const workspaceJson = readJsonInTree(tree, 'workspace.json');
392+
expect(workspaceJson.projects['my-app'].architect.test.builder).toEqual(
393+
'@angular-devkit/build-angular:karma'
394+
);
395+
expect(
396+
workspaceJson.projects['my-app'].architect.lint.options.tsConfig
397+
).toEqual([
398+
'apps/my-app/tsconfig.app.json',
399+
'apps/my-app/tsconfig.spec.json'
400+
]);
401+
const tsconfigAppJson = readJsonInTree(
402+
tree,
403+
'apps/my-app/tsconfig.app.json'
404+
);
405+
expect(tsconfigAppJson.compilerOptions.outDir).toEqual(
406+
'../../dist/out-tsc'
407+
);
408+
});
409+
});
410+
411+
describe('none', () => {
412+
it('should not generate test configuration', async () => {
413+
const tree = await runSchematic(
414+
'app',
415+
{ name: 'myApp', unitTestRunner: 'none' },
416+
appTree
417+
);
418+
expect(tree.exists('apps/my-app/src/test-setup.ts')).toBeFalsy();
419+
expect(tree.exists('apps/my-app/src/test.ts')).toBeFalsy();
420+
expect(tree.exists('apps/my-app/tsconfig.spec.json')).toBeFalsy();
421+
expect(tree.exists('apps/my-app/jest.config.js')).toBeFalsy();
422+
expect(tree.exists('apps/my-app/karma.config.js')).toBeFalsy();
423+
const workspaceJson = readJsonInTree(tree, 'workspace.json');
424+
expect(workspaceJson.projects['my-app'].architect.test).toBeUndefined();
425+
expect(
426+
workspaceJson.projects['my-app'].architect.lint.options.tsConfig
427+
).toEqual(['apps/my-app/tsconfig.app.json']);
428+
});
400429
});
401430
});
402431

packages/angular/src/utils/versions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ export const angularDevkitVersion = '0.900.0-rc.12';
44
export const angularJsVersion = '1.6.6';
55
export const ngrxVersion = '8.5.0';
66
export const rxjsVersion = '~6.5.0';
7-
export const jestPresetAngularVersion = '7.0.0';
7+
export const jestPresetAngularVersion = '8.0.0';

packages/jest/migrations.json

+16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@
99
"version": "8.7.0",
1010
"description": "Update Jest testPathPattern option",
1111
"factory": "./src/migrations/update-8-7-0/update-8-7-0"
12+
},
13+
"update-9.0.0": {
14+
"version": "9.0.0-beta.1",
15+
"description": "Upgrades jest-preset-angular to 8.0.0",
16+
"factory": "./src/migrations/update-9-0-0/update-9-0-0"
17+
}
18+
},
19+
"packageJsonUpdates": {
20+
"9.0.0": {
21+
"version": "9.0.0-beta.1",
22+
"packages": {
23+
"jest-preset-angular": {
24+
"version": "8.0.0",
25+
"alwaysAddToPackageJson": false
26+
}
27+
}
1228
}
1329
}
1430
}

packages/jest/src/builders/jest/jest.impl.spec.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ describe('Jest Builder', () => {
5757
tsConfig: '/root/tsconfig.test.json',
5858
stringifyContentPathRegex: '\\.(html|svg)$',
5959
astTransformers: [
60-
'jest-preset-angular/InlineHtmlStripStylesTransformer'
60+
'jest-preset-angular/build/InlineFilesTransformer',
61+
'jest-preset-angular/build/StripStylesTransformer'
6162
]
6263
}
6364
}),
@@ -99,7 +100,8 @@ describe('Jest Builder', () => {
99100
tsConfig: '/root/tsconfig.test.json',
100101
stringifyContentPathRegex: '\\.(html|svg)$',
101102
astTransformers: [
102-
'jest-preset-angular/InlineHtmlStripStylesTransformer'
103+
'jest-preset-angular/build/InlineFilesTransformer',
104+
'jest-preset-angular/build/StripStylesTransformer'
103105
]
104106
}
105107
}),
@@ -142,7 +144,8 @@ describe('Jest Builder', () => {
142144
tsConfig: '/root/tsconfig.test.json',
143145
stringifyContentPathRegex: '\\.(html|svg)$',
144146
astTransformers: [
145-
'jest-preset-angular/InlineHtmlStripStylesTransformer'
147+
'jest-preset-angular/build/InlineFilesTransformer',
148+
'jest-preset-angular/build/StripStylesTransformer'
146149
]
147150
}
148151
}),
@@ -199,7 +202,8 @@ describe('Jest Builder', () => {
199202
tsConfig: '/root/tsconfig.test.json',
200203
stringifyContentPathRegex: '\\.(html|svg)$',
201204
astTransformers: [
202-
'jest-preset-angular/InlineHtmlStripStylesTransformer'
205+
'jest-preset-angular/build/InlineFilesTransformer',
206+
'jest-preset-angular/build/StripStylesTransformer'
203207
]
204208
}
205209
}),
@@ -251,7 +255,8 @@ describe('Jest Builder', () => {
251255
tsConfig: '/root/tsconfig.test.json',
252256
stringifyContentPathRegex: '\\.(html|svg)$',
253257
astTransformers: [
254-
'jest-preset-angular/InlineHtmlStripStylesTransformer'
258+
'jest-preset-angular/build/InlineFilesTransformer',
259+
'jest-preset-angular/build/StripStylesTransformer'
255260
]
256261
}
257262
}),
@@ -307,7 +312,8 @@ describe('Jest Builder', () => {
307312
tsConfig: '/root/tsconfig.test.json',
308313
stringifyContentPathRegex: '\\.(html|svg)$',
309314
astTransformers: [
310-
'jest-preset-angular/InlineHtmlStripStylesTransformer'
315+
'jest-preset-angular/build/InlineFilesTransformer',
316+
'jest-preset-angular/build/StripStylesTransformer'
311317
]
312318
}
313319
}),

packages/jest/src/builders/jest/jest.impl.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ function run(
7272
require.resolve('jest-preset-angular');
7373
Object.assign(tsJestConfig, {
7474
stringifyContentPathRegex: '\\.(html|svg)$',
75-
astTransformers: ['jest-preset-angular/InlineHtmlStripStylesTransformer']
75+
astTransformers: [
76+
'jest-preset-angular/build/InlineFilesTransformer',
77+
'jest-preset-angular/build/StripStylesTransformer'
78+
]
7679
});
7780
} catch (e) {}
7881

0 commit comments

Comments
 (0)