9
9
import { EmptyTree } from '@angular-devkit/schematics' ;
10
10
import { SchematicTestRunner , UnitTestTree } from '@angular-devkit/schematics/testing' ;
11
11
12
-
13
12
describe ( 'Migration to version 8' , ( ) => {
14
13
describe ( 'Migrate ES5 projects to enable differential loading' , ( ) => {
15
14
const tsConfigPath = '/tsconfig.json' ;
16
15
const oldTsConfig = {
17
16
compilerOptions : {
18
17
module : 'es2015' ,
19
18
moduleResolution : 'node' ,
20
- typeRoots : [
21
- 'node_modules/@types' ,
22
- ] ,
19
+ typeRoots : [ 'node_modules/@types' ] ,
23
20
} ,
24
21
} ;
25
22
@@ -32,15 +29,18 @@ describe('Migration to version 8', () => {
32
29
33
30
beforeEach ( async ( ) => {
34
31
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 ( ) ;
44
44
tree . overwrite ( tsConfigPath , JSON . stringify ( oldTsConfig , null , 2 ) ) ;
45
45
} ) ;
46
46
@@ -81,24 +81,24 @@ describe('Migration to version 8', () => {
81
81
} ) ;
82
82
83
83
it ( `should create 'downlevelIteration' property when doesn't exists` , ( ) => {
84
- const tree2 = schematicRunner . runSchematic ( 'migration-07' , { } , tree . branch ( ) ) ;
85
84
const compilerOptions = {
86
85
...oldTsConfig . compilerOptions ,
87
86
} ;
88
87
89
88
tree . overwrite ( tsConfigPath , JSON . stringify ( { compilerOptions } , null , 2 ) ) ;
89
+ const tree2 = schematicRunner . runSchematic ( 'migration-07' , { } , tree . branch ( ) ) ;
90
90
const { downlevelIteration } = JSON . parse ( tree2 . readContent ( tsConfigPath ) ) . compilerOptions ;
91
91
expect ( downlevelIteration ) . toBe ( true ) ;
92
92
} ) ;
93
93
94
94
it ( `should update 'downlevelIteration' to true when it's false` , ( ) => {
95
- const tree2 = schematicRunner . runSchematic ( 'migration-07' , { } , tree . branch ( ) ) ;
96
95
const compilerOptions = {
97
96
...oldTsConfig . compilerOptions ,
98
97
downlevelIteration : false ,
99
98
} ;
100
99
101
100
tree . overwrite ( tsConfigPath , JSON . stringify ( { compilerOptions } , null , 2 ) ) ;
101
+ const tree2 = schematicRunner . runSchematic ( 'migration-07' , { } , tree . branch ( ) ) ;
102
102
const { downlevelIteration } = JSON . parse ( tree2 . readContent ( tsConfigPath ) ) . compilerOptions ;
103
103
expect ( downlevelIteration ) . toBe ( true ) ;
104
104
} ) ;
@@ -119,14 +119,18 @@ describe('Migration to version 8', () => {
119
119
it ( `should remove 'target' and 'module' from non workspace extended tsconfig.json` , ( ) => {
120
120
const appTsConfig = '/tsconfig.app.json' ;
121
121
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
+ } ,
128
130
} ,
129
- } , null , 2 ) ;
131
+ null ,
132
+ 2 ,
133
+ ) ;
130
134
131
135
tree . overwrite ( appTsConfig , tsConfig ) ;
132
136
tree . overwrite ( specsTsConfig , tsConfig ) ;
@@ -136,21 +140,26 @@ describe('Migration to version 8', () => {
136
140
expect ( appCompilerOptions . target ) . toBeUndefined ( ) ;
137
141
expect ( appCompilerOptions . module ) . toBeUndefined ( ) ;
138
142
139
- const { compilerOptions : specsCompilerOptions }
140
- = JSON . parse ( tree2 . readContent ( specsTsConfig ) ) ;
143
+ const { compilerOptions : specsCompilerOptions } = JSON . parse (
144
+ tree2 . readContent ( specsTsConfig ) ,
145
+ ) ;
141
146
expect ( specsCompilerOptions . target ) . toBeUndefined ( ) ;
142
147
expect ( specsCompilerOptions . module ) . toBeUndefined ( ) ;
143
148
} ) ;
144
149
145
150
it ( `should update 'target' and 'module' to non workspace non-extended tsconfig.json` , ( ) => {
146
151
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
+ } ,
152
159
} ,
153
- } , null , 2 ) ;
160
+ null ,
161
+ 2 ,
162
+ ) ;
154
163
155
164
tree . overwrite ( appTsConfig , tsConfig ) ;
156
165
@@ -162,11 +171,15 @@ describe('Migration to version 8', () => {
162
171
163
172
it ( `should add 'target' and 'module' to non workspace non-extended tsconfig.json` , ( ) => {
164
173
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
+ } ,
168
179
} ,
169
- } , null , 2 ) ;
180
+ null ,
181
+ 2 ,
182
+ ) ;
170
183
171
184
tree . overwrite ( appTsConfig , tsConfig ) ;
172
185
@@ -179,11 +192,7 @@ describe('Migration to version 8', () => {
179
192
it ( `should not update projects which browser builder is not 'build-angular:browser'` , ( ) => {
180
193
tree . delete ( '/browserslist' ) ;
181
194
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' ;
187
196
188
197
tree . overwrite ( 'angular.json' , JSON . stringify ( config ) ) ;
189
198
const tree2 = schematicRunner . runSchematic ( 'migration-07' , { } , tree . branch ( ) ) ;
0 commit comments