Skip to content

Commit 01930d6

Browse files
alan-agius4vikerman
authored andcommitted
test: file override should happen before migration being run
1 parent a5e6b10 commit 01930d6

File tree

1 file changed

+48
-39
lines changed

1 file changed

+48
-39
lines changed

packages/schematics/angular/migrations/update-8/differential-loading_spec.ts

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@
99
import { EmptyTree } from '@angular-devkit/schematics';
1010
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
1111

12-
1312
describe('Migration to version 8', () => {
1413
describe('Migrate ES5 projects to enable differential loading', () => {
1514
const tsConfigPath = '/tsconfig.json';
1615
const oldTsConfig = {
1716
compilerOptions: {
1817
module: 'es2015',
1918
moduleResolution: 'node',
20-
typeRoots: [
21-
'node_modules/@types',
22-
],
19+
typeRoots: ['node_modules/@types'],
2320
},
2421
};
2522

@@ -32,15 +29,18 @@ describe('Migration to version 8', () => {
3229

3330
beforeEach(async () => {
3431
tree = new UnitTestTree(new EmptyTree());
35-
tree = await schematicRunner.runExternalSchematicAsync(
36-
require.resolve('../../collection.json'), 'ng-new',
37-
{
38-
name: 'migration-test',
39-
version: '1.2.3',
40-
directory: '.',
41-
},
42-
tree,
43-
).toPromise();
32+
tree = await schematicRunner
33+
.runExternalSchematicAsync(
34+
require.resolve('../../collection.json'),
35+
'ng-new',
36+
{
37+
name: 'migration-test',
38+
version: '1.2.3',
39+
directory: '.',
40+
},
41+
tree,
42+
)
43+
.toPromise();
4444
tree.overwrite(tsConfigPath, JSON.stringify(oldTsConfig, null, 2));
4545
});
4646

@@ -81,24 +81,24 @@ describe('Migration to version 8', () => {
8181
});
8282

8383
it(`should create 'downlevelIteration' property when doesn't exists`, () => {
84-
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
8584
const compilerOptions = {
8685
...oldTsConfig.compilerOptions,
8786
};
8887

8988
tree.overwrite(tsConfigPath, JSON.stringify({ compilerOptions }, null, 2));
89+
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
9090
const { downlevelIteration } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
9191
expect(downlevelIteration).toBe(true);
9292
});
9393

9494
it(`should update 'downlevelIteration' to true when it's false`, () => {
95-
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
9695
const compilerOptions = {
9796
...oldTsConfig.compilerOptions,
9897
downlevelIteration: false,
9998
};
10099

101100
tree.overwrite(tsConfigPath, JSON.stringify({ compilerOptions }, null, 2));
101+
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());
102102
const { downlevelIteration } = JSON.parse(tree2.readContent(tsConfigPath)).compilerOptions;
103103
expect(downlevelIteration).toBe(true);
104104
});
@@ -119,14 +119,18 @@ describe('Migration to version 8', () => {
119119
it(`should remove 'target' and 'module' from non workspace extended tsconfig.json`, () => {
120120
const appTsConfig = '/tsconfig.app.json';
121121
const specsTsConfig = '/tsconfig.spec.json';
122-
const tsConfig = JSON.stringify({
123-
extends: '../../tsconfig.json',
124-
compilerOptions: {
125-
moduleResolution: 'node',
126-
target: 'es2015',
127-
module: 'es2015',
122+
const tsConfig = JSON.stringify(
123+
{
124+
extends: '../../tsconfig.json',
125+
compilerOptions: {
126+
moduleResolution: 'node',
127+
target: 'es2015',
128+
module: 'es2015',
129+
},
128130
},
129-
}, null, 2);
131+
null,
132+
2,
133+
);
130134

131135
tree.overwrite(appTsConfig, tsConfig);
132136
tree.overwrite(specsTsConfig, tsConfig);
@@ -136,21 +140,26 @@ describe('Migration to version 8', () => {
136140
expect(appCompilerOptions.target).toBeUndefined();
137141
expect(appCompilerOptions.module).toBeUndefined();
138142

139-
const { compilerOptions: specsCompilerOptions }
140-
= JSON.parse(tree2.readContent(specsTsConfig));
143+
const { compilerOptions: specsCompilerOptions } = JSON.parse(
144+
tree2.readContent(specsTsConfig),
145+
);
141146
expect(specsCompilerOptions.target).toBeUndefined();
142147
expect(specsCompilerOptions.module).toBeUndefined();
143148
});
144149

145150
it(`should update 'target' and 'module' to non workspace non-extended tsconfig.json`, () => {
146151
const appTsConfig = '/tsconfig.app.json';
147-
const tsConfig = JSON.stringify({
148-
compilerOptions: {
149-
moduleResolution: 'node',
150-
target: 'es5',
151-
module: 'es5',
152+
const tsConfig = JSON.stringify(
153+
{
154+
compilerOptions: {
155+
moduleResolution: 'node',
156+
target: 'es5',
157+
module: 'es5',
158+
},
152159
},
153-
}, null, 2);
160+
null,
161+
2,
162+
);
154163

155164
tree.overwrite(appTsConfig, tsConfig);
156165

@@ -162,11 +171,15 @@ describe('Migration to version 8', () => {
162171

163172
it(`should add 'target' and 'module' to non workspace non-extended tsconfig.json`, () => {
164173
const appTsConfig = '/tsconfig.app.json';
165-
const tsConfig = JSON.stringify({
166-
compilerOptions: {
167-
moduleResolution: 'node',
174+
const tsConfig = JSON.stringify(
175+
{
176+
compilerOptions: {
177+
moduleResolution: 'node',
178+
},
168179
},
169-
}, null, 2);
180+
null,
181+
2,
182+
);
170183

171184
tree.overwrite(appTsConfig, tsConfig);
172185

@@ -179,11 +192,7 @@ describe('Migration to version 8', () => {
179192
it(`should not update projects which browser builder is not 'build-angular:browser'`, () => {
180193
tree.delete('/browserslist');
181194
const config = JSON.parse(tree.readContent('angular.json'));
182-
config
183-
.projects['migration-test']
184-
.architect
185-
.build
186-
.builder = '@dummy/builders:browser';
195+
config.projects['migration-test'].architect.build.builder = '@dummy/builders:browser';
187196

188197
tree.overwrite('angular.json', JSON.stringify(config));
189198
const tree2 = schematicRunner.runSchematic('migration-07', {}, tree.branch());

0 commit comments

Comments
 (0)