forked from nrwl/nx
/
update-8-8-0.spec.ts
155 lines (142 loc) · 4.69 KB
/
update-8-8-0.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { Tree } from '@angular-devkit/schematics';
import { readJsonInTree } from '@nrwl/workspace/src/utils/ast-utils';
import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
import * as path from 'path';
import { createEmptyWorkspace } from '@nrwl/workspace/testing';
import { serializeJson } from '@nrwl/workspace';
describe.only('Update 8.8.0', () => {
let initialTree: Tree;
let schematicRunner: SchematicTestRunner;
beforeEach(async () => {
initialTree = createEmptyWorkspace(Tree.empty());
schematicRunner = new SchematicTestRunner(
'@nrwl/jest',
path.join(__dirname, '../../../migrations.json')
);
initialTree.overwrite(
'package.json',
serializeJson({ devDependencies: { 'jest-preset-angular': '7.0.0' } })
);
initialTree.overwrite(
'workspace.json',
serializeJson({
projects: {
'angular-one': {
root: 'apps/angular-one/',
architect: {
test: {
builder: '@nrwl/jest:jest',
options: {
jestConfig: 'apps/angular-one/jest.config.js'
}
}
}
},
'angular-two': {
root: 'apps/angular-two/',
architect: {
test: {
builder: '@nrwl/jest:jest',
options: {
jestConfig: 'apps/angular-two/jest.config.js'
}
}
}
},
'non-angular-one': {
root: 'apps/non-angular-one/',
architect: {
test: {
builder: '@nrwl/jest:jest',
options: {
jestConfig: 'apps/non-angular-one/jest.config.js'
}
}
}
}
}
})
);
initialTree.create(
'apps/angular-one/jest.config.js',
`module.exports = {
name: 'angular-one',
preset: '../../jest.config.js',
coverageDirectory:
'../../coverage/apps/angular-one',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js'
]
};`
);
initialTree.create(
'apps/angular-two/jest.config.js',
`module.exports = {
name: 'angular-two',
preset: '../../jest.config.js',
coverageDirectory:
'../../coverage/apps/angular-two',
snapshotSerializers: [
'jest-preset-angular/AngularSnapshotSerializer.js',
'jest-preset-angular/HTMLCommentSerializer.js'
]
};`
);
initialTree.create(
'apps/non-angular-one/jest.config.js',
`module.exports = {
name: 'non-angular-one',
preset: '../../jest.config.js',
coverageDirectory:
'../../coverage/apps/non-angular-one',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html']
};`
);
});
it('should update jest-preset-angular to 8.0.0', async () => {
const result = await schematicRunner
.runSchematicAsync('update-8.8.0', {}, initialTree)
.toPromise();
const { devDependencies } = readJsonInTree(result, 'package.json');
expect(devDependencies['jest-preset-angular']).toEqual('8.0.0');
});
it(`it should add '/build' into jest-preset-angular snapshotSerializers in any jest.config.js where it exists`, async () => {
const result = await schematicRunner
.runSchematicAsync('update-8.8.0', {}, initialTree)
.toPromise();
const updateJestAngularOne = result.readContent(
'apps/angular-one/jest.config.js'
);
const updateJestAngularTwo = result.readContent(
'apps/angular-two/jest.config.js'
);
const updateJestNonAngularOne = result.readContent(
'apps/non-angular-one/jest.config.js'
);
expect(updateJestAngularOne).not.toContain(
'jest-preset-angular/AngularSnapshotSerializer.js'
);
expect(updateJestAngularOne).not.toContain(
'jest-preset-angular/HTMLCommentSerializer.js'
);
expect(updateJestAngularTwo).not.toContain(
'jest-preset-angular/AngularSnapshotSerializer.js'
);
expect(updateJestAngularTwo).not.toContain(
'jest-preset-angular/HTMLCommentSerializer.js'
);
expect(updateJestAngularOne).toContain(
'jest-preset-angular/build/AngularSnapshotSerializer.js'
);
expect(updateJestAngularOne).toContain(
'jest-preset-angular/build/HTMLCommentSerializer.js'
);
expect(updateJestAngularTwo).toContain(
'jest-preset-angular/build/AngularSnapshotSerializer.js'
);
expect(updateJestAngularTwo).toContain(
'jest-preset-angular/build/HTMLCommentSerializer.js'
);
});
});