@@ -41,8 +41,8 @@ describe('Library Schematic', () => {
41
41
workspaceTree = schematicRunner . runSchematic ( 'workspace' , workspaceOptions ) ;
42
42
} ) ;
43
43
44
- it ( 'should create files' , ( ) => {
45
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
44
+ it ( 'should create files' , async ( ) => {
45
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
46
46
const files = tree . files ;
47
47
expect ( files ) . toEqual ( jasmine . arrayContaining ( [
48
48
'/projects/foo/karma.conf.js' ,
@@ -60,81 +60,81 @@ describe('Library Schematic', () => {
60
60
] ) ) ;
61
61
} ) ;
62
62
63
- it ( 'should create a package.json named "foo"' , ( ) => {
64
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
63
+ it ( 'should create a package.json named "foo"' , async ( ) => {
64
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
65
65
const fileContent = getFileContent ( tree , '/projects/foo/package.json' ) ;
66
66
expect ( fileContent ) . toMatch ( / " n a m e " : " f o o " / ) ;
67
67
} ) ;
68
68
69
- it ( 'should have the latest Angular major versions in package.json named "foo"' , ( ) => {
70
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
69
+ it ( 'should have the latest Angular major versions in package.json named "foo"' , async ( ) => {
70
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
71
71
const fileContent = getJsonFileContent ( tree , '/projects/foo/package.json' ) ;
72
72
const angularVersion = latestVersions . Angular . replace ( '~' , '' ) . replace ( '^' , '' ) ;
73
73
expect ( fileContent . peerDependencies [ '@angular/core' ] ) . toBe ( `^${ angularVersion } ` ) ;
74
74
} ) ;
75
75
76
- it ( 'should create a README.md named "foo"' , ( ) => {
77
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
76
+ it ( 'should create a README.md named "foo"' , async ( ) => {
77
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
78
78
const fileContent = getFileContent ( tree , '/projects/foo/README.md' ) ;
79
79
expect ( fileContent ) . toMatch ( / # F o o / ) ;
80
80
} ) ;
81
81
82
- it ( 'should create a tsconfig for library' , ( ) => {
83
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
82
+ it ( 'should create a tsconfig for library' , async ( ) => {
83
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
84
84
const fileContent = getJsonFileContent ( tree , '/projects/foo/tsconfig.lib.json' ) ;
85
85
expect ( fileContent ) . toBeDefined ( ) ;
86
86
} ) ;
87
87
88
- it ( 'should create a ng-package.json with ngPackage conf' , ( ) => {
89
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
88
+ it ( 'should create a ng-package.json with ngPackage conf' , async ( ) => {
89
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
90
90
const fileContent = getJsonFileContent ( tree , '/projects/foo/ng-package.json' ) ;
91
91
expect ( fileContent . lib ) . toBeDefined ( ) ;
92
92
expect ( fileContent . lib . entryFile ) . toEqual ( 'src/my-index.ts' ) ;
93
93
expect ( fileContent . dest ) . toEqual ( '../../dist/foo' ) ;
94
94
} ) ;
95
95
96
- it ( 'should use default value for baseDir and entryFile' , ( ) => {
97
- const tree = schematicRunner . runSchematic ( 'library' , {
96
+ it ( 'should use default value for baseDir and entryFile' , async ( ) => {
97
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , {
98
98
name : 'foobar' ,
99
- } , workspaceTree ) ;
99
+ } , workspaceTree ) . toPromise ( ) ;
100
100
expect ( tree . files ) . toContain ( '/projects/foobar/src/public-api.ts' ) ;
101
101
} ) ;
102
102
103
- it ( `should add library to workspace` , ( ) => {
104
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
103
+ it ( `should add library to workspace` , async ( ) => {
104
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
105
105
106
106
const workspace = getJsonFileContent ( tree , '/angular.json' ) ;
107
107
expect ( workspace . projects . foo ) . toBeDefined ( ) ;
108
108
expect ( workspace . defaultProject ) . toBe ( 'foo' ) ;
109
109
} ) ;
110
110
111
- it ( 'should set the prefix to lib if none is set' , ( ) => {
112
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
111
+ it ( 'should set the prefix to lib if none is set' , async ( ) => {
112
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
113
113
114
114
const workspace = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
115
115
expect ( workspace . projects . foo . prefix ) . toEqual ( 'lib' ) ;
116
116
} ) ;
117
117
118
- it ( 'should set the prefix correctly' , ( ) => {
118
+ it ( 'should set the prefix correctly' , async ( ) => {
119
119
const options = { ...defaultOptions , prefix : 'pre' } ;
120
- const tree = schematicRunner . runSchematic ( 'library' , options , workspaceTree ) ;
120
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , options , workspaceTree ) . toPromise ( ) ;
121
121
122
122
const workspace = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
123
123
expect ( workspace . projects . foo . prefix ) . toEqual ( 'pre' ) ;
124
124
} ) ;
125
125
126
- it ( 'should set the right prefix in the tslint file when provided is kebabed' , ( ) => {
126
+ it ( 'should set the right prefix in the tslint file when provided is kebabed' , async ( ) => {
127
127
const options : GenerateLibrarySchema = { ...defaultOptions , prefix : 'foo-bar' } ;
128
- const tree = schematicRunner . runSchematic ( 'library' , options , workspaceTree ) ;
128
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , options , workspaceTree ) . toPromise ( ) ;
129
129
const path = '/projects/foo/tslint.json' ;
130
130
const content = JSON . parse ( tree . readContent ( path ) ) ;
131
131
expect ( content . rules [ 'directive-selector' ] [ 2 ] ) . toMatch ( 'fooBar' ) ;
132
132
expect ( content . rules [ 'component-selector' ] [ 2 ] ) . toMatch ( 'foo-bar' ) ;
133
133
} ) ;
134
134
135
- it ( 'should handle a pascalCasedName' , ( ) => {
135
+ it ( 'should handle a pascalCasedName' , async ( ) => {
136
136
const options = { ...defaultOptions , name : 'pascalCasedName' } ;
137
- const tree = schematicRunner . runSchematic ( 'library' , options , workspaceTree ) ;
137
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , options , workspaceTree ) . toPromise ( ) ;
138
138
const config = getJsonFileContent ( tree , '/angular.json' ) ;
139
139
const project = config . projects . pascalCasedName ;
140
140
expect ( project ) . toBeDefined ( ) ;
@@ -143,14 +143,14 @@ describe('Library Schematic', () => {
143
143
expect ( svcContent ) . toMatch ( / p r o v i d e d I n : ' r o o t ' / ) ;
144
144
} ) ;
145
145
146
- it ( 'should export the component in the NgModule' , ( ) => {
147
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
146
+ it ( 'should export the component in the NgModule' , async ( ) => {
147
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
148
148
const fileContent = getFileContent ( tree , '/projects/foo/src/lib/foo.module.ts' ) ;
149
149
expect ( fileContent ) . toContain ( 'exports: [FooComponent]' ) ;
150
150
} ) ;
151
151
152
- it ( 'should set the right path and prefix in the tslint file' , ( ) => {
153
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
152
+ it ( 'should set the right path and prefix in the tslint file' , async ( ) => {
153
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
154
154
const path = '/projects/foo/tslint.json' ;
155
155
const content = JSON . parse ( tree . readContent ( path ) ) ;
156
156
expect ( content . extends ) . toMatch ( '../../tslint.json' ) ;
@@ -159,39 +159,39 @@ describe('Library Schematic', () => {
159
159
} ) ;
160
160
161
161
describe ( `update package.json` , ( ) => {
162
- it ( `should add ng-packagr to devDependencies` , ( ) => {
163
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
162
+ it ( `should add ng-packagr to devDependencies` , async ( ) => {
163
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
164
164
165
165
const packageJson = getJsonFileContent ( tree , 'package.json' ) ;
166
166
expect ( packageJson . devDependencies [ 'ng-packagr' ] ) . toEqual ( '^5.0.0' ) ;
167
167
expect ( packageJson . devDependencies [ '@angular-devkit/build-ng-packagr' ] )
168
168
. toEqual ( latestVersions . DevkitBuildNgPackagr ) ;
169
169
} ) ;
170
170
171
- it ( 'should use the latest known versions in package.json' , ( ) => {
172
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
171
+ it ( 'should use the latest known versions in package.json' , async ( ) => {
172
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
173
173
const pkg = JSON . parse ( tree . readContent ( '/package.json' ) ) ;
174
174
expect ( pkg . devDependencies [ '@angular/compiler-cli' ] ) . toEqual ( latestVersions . Angular ) ;
175
175
expect ( pkg . devDependencies [ 'typescript' ] ) . toEqual ( latestVersions . TypeScript ) ;
176
176
} ) ;
177
177
178
- it ( `should not override existing users dependencies` , ( ) => {
178
+ it ( `should not override existing users dependencies` , async ( ) => {
179
179
const oldPackageJson = workspaceTree . readContent ( 'package.json' ) ;
180
180
workspaceTree . overwrite ( 'package.json' , oldPackageJson . replace (
181
181
`"typescript": "${ latestVersions . TypeScript } "` ,
182
182
`"typescript": "~2.5.2"` ,
183
183
) ) ;
184
184
185
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
185
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
186
186
const packageJson = getJsonFileContent ( tree , 'package.json' ) ;
187
187
expect ( packageJson . devDependencies . typescript ) . toEqual ( '~2.5.2' ) ;
188
188
} ) ;
189
189
190
- it ( `should not modify the file when --skipPackageJson` , ( ) => {
191
- const tree = schematicRunner . runSchematic ( 'library' , {
190
+ it ( `should not modify the file when --skipPackageJson` , async ( ) => {
191
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , {
192
192
name : 'foo' ,
193
193
skipPackageJson : true ,
194
- } , workspaceTree ) ;
194
+ } , workspaceTree ) . toPromise ( ) ;
195
195
196
196
const packageJson = getJsonFileContent ( tree , 'package.json' ) ;
197
197
expect ( packageJson . devDependencies [ 'ng-packagr' ] ) . toBeUndefined ( ) ;
@@ -200,8 +200,8 @@ describe('Library Schematic', () => {
200
200
} ) ;
201
201
202
202
describe ( `update tsconfig.json` , ( ) => {
203
- it ( `should add paths mapping to empty tsconfig` , ( ) => {
204
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
203
+ it ( `should add paths mapping to empty tsconfig` , async ( ) => {
204
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
205
205
206
206
const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
207
207
expect ( tsConfigJson . compilerOptions . paths . foo ) . toBeTruthy ( ) ;
@@ -212,7 +212,7 @@ describe('Library Schematic', () => {
212
212
expect ( tsConfigJson . compilerOptions . paths [ 'foo/*' ] [ 0 ] ) . toEqual ( 'dist/foo/*' ) ;
213
213
} ) ;
214
214
215
- it ( `should append to existing paths mappings` , ( ) => {
215
+ it ( `should append to existing paths mappings` , async ( ) => {
216
216
workspaceTree . overwrite ( 'tsconfig.json' , JSON . stringify ( {
217
217
compilerOptions : {
218
218
paths : {
@@ -221,27 +221,27 @@ describe('Library Schematic', () => {
221
221
} ,
222
222
} ,
223
223
} ) ) ;
224
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
224
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
225
225
226
226
const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
227
227
expect ( tsConfigJson . compilerOptions . paths . foo ) . toBeTruthy ( ) ;
228
228
expect ( tsConfigJson . compilerOptions . paths . foo . length ) . toEqual ( 2 ) ;
229
229
expect ( tsConfigJson . compilerOptions . paths . foo [ 1 ] ) . toEqual ( 'dist/foo' ) ;
230
230
} ) ;
231
231
232
- it ( `should not modify the file when --skipTsConfig` , ( ) => {
233
- const tree = schematicRunner . runSchematic ( 'library' , {
232
+ it ( `should not modify the file when --skipTsConfig` , async ( ) => {
233
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , {
234
234
name : 'foo' ,
235
235
skipTsConfig : true ,
236
- } , workspaceTree ) ;
236
+ } , workspaceTree ) . toPromise ( ) ;
237
237
238
238
const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
239
239
expect ( tsConfigJson . compilerOptions . paths ) . toBeUndefined ( ) ;
240
240
} ) ;
241
241
} ) ;
242
242
243
- it ( 'should generate inside of a library' , ( ) => {
244
- let tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
243
+ it ( 'should generate inside of a library' , async ( ) => {
244
+ let tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
245
245
const componentOptions : ComponentOptions = {
246
246
name : 'comp' ,
247
247
project : 'foo' ,
@@ -250,10 +250,10 @@ describe('Library Schematic', () => {
250
250
expect ( tree . exists ( '/projects/foo/src/lib/comp/comp.component.ts' ) ) . toBe ( true ) ;
251
251
} ) ;
252
252
253
- it ( `should support creating scoped libraries` , ( ) => {
253
+ it ( `should support creating scoped libraries` , async ( ) => {
254
254
const scopedName = '@myscope/mylib' ;
255
255
const options = { ...defaultOptions , name : scopedName } ;
256
- const tree = schematicRunner . runSchematic ( 'library' , options , workspaceTree ) ;
256
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , options , workspaceTree ) . toPromise ( ) ;
257
257
258
258
const pkgJsonPath = '/projects/myscope/mylib/package.json' ;
259
259
expect ( tree . files ) . toContain ( pkgJsonPath ) ;
@@ -276,12 +276,12 @@ describe('Library Schematic', () => {
276
276
expect ( karmaConf ) . toContain ( `dir: require('path').join(__dirname, '../../../coverage/myscope/mylib')` ) ;
277
277
} ) ;
278
278
279
- it ( `should dasherize scoped libraries` , ( ) => {
279
+ it ( `should dasherize scoped libraries` , async ( ) => {
280
280
const scopedName = '@myScope/myLib' ;
281
281
const expectedScopeName = '@my-scope/my-lib' ;
282
282
const expectedFolderName = 'my-scope/my-lib' ;
283
283
const options = { ...defaultOptions , name : scopedName } ;
284
- const tree = schematicRunner . runSchematic ( 'library' , options , workspaceTree ) ;
284
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , options , workspaceTree ) . toPromise ( ) ;
285
285
286
286
const pkgJsonPath = '/projects/my-scope/my-lib/package.json' ;
287
287
expect ( tree . readContent ( pkgJsonPath ) ) . toContain ( expectedScopeName ) ;
@@ -296,8 +296,8 @@ describe('Library Schematic', () => {
296
296
expect ( cfg . projects [ '@myScope/myLib' ] ) . toBeDefined ( ) ;
297
297
} ) ;
298
298
299
- it ( `should set coverage folder to "coverage/foo"` , ( ) => {
300
- const tree = schematicRunner . runSchematic ( 'library' , defaultOptions , workspaceTree ) ;
299
+ it ( `should set coverage folder to "coverage/foo"` , async ( ) => {
300
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
301
301
const karmaConf = getFileContent ( tree , '/projects/foo/karma.conf.js' ) ;
302
302
expect ( karmaConf ) . toContain ( `dir: require('path').join(__dirname, '../../coverage/foo')` ) ;
303
303
} ) ;
0 commit comments