6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
// tslint:disable:no-big-function
9
+ import { JsonParseMode , parseJson } from '@angular-devkit/core' ;
9
10
import { SchematicTestRunner , UnitTestTree } from '@angular-devkit/schematics/testing' ;
10
11
import { getFileContent } from '../../angular/utility/test' ;
11
12
import { Schema as ComponentOptions } from '../component/schema' ;
@@ -200,19 +201,19 @@ describe('Library Schematic', () => {
200
201
} ) ;
201
202
} ) ;
202
203
203
- describe ( `update tsconfig.json` , ( ) => {
204
+ describe ( `update tsconfig.base. json` , ( ) => {
204
205
it ( `should add paths mapping to empty tsconfig` , async ( ) => {
205
206
const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
206
207
207
- const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
208
+ const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.base. json' ) ;
208
209
expect ( tsConfigJson . compilerOptions . paths . foo ) . toBeTruthy ( ) ;
209
210
expect ( tsConfigJson . compilerOptions . paths . foo . length ) . toEqual ( 2 ) ;
210
211
expect ( tsConfigJson . compilerOptions . paths . foo [ 0 ] ) . toEqual ( 'dist/foo/foo' ) ;
211
212
expect ( tsConfigJson . compilerOptions . paths . foo [ 1 ] ) . toEqual ( 'dist/foo' ) ;
212
213
} ) ;
213
214
214
215
it ( `should append to existing paths mappings` , async ( ) => {
215
- workspaceTree . overwrite ( 'tsconfig.json' , JSON . stringify ( {
216
+ workspaceTree . overwrite ( 'tsconfig.base. json' , JSON . stringify ( {
216
217
compilerOptions : {
217
218
paths : {
218
219
'unrelated' : [ './something/else.ts' ] ,
@@ -222,7 +223,7 @@ describe('Library Schematic', () => {
222
223
} ) ) ;
223
224
const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
224
225
225
- const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
226
+ const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.base. json' ) ;
226
227
expect ( tsConfigJson . compilerOptions . paths . foo ) . toBeTruthy ( ) ;
227
228
expect ( tsConfigJson . compilerOptions . paths . foo . length ) . toEqual ( 3 ) ;
228
229
expect ( tsConfigJson . compilerOptions . paths . foo [ 1 ] ) . toEqual ( 'dist/foo/foo' ) ;
@@ -235,7 +236,7 @@ describe('Library Schematic', () => {
235
236
skipTsConfig : true ,
236
237
} , workspaceTree ) . toPromise ( ) ;
237
238
238
- const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
239
+ const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.base. json' ) ;
239
240
expect ( tsConfigJson . compilerOptions . paths ) . toBeUndefined ( ) ;
240
241
} ) ;
241
242
} ) ;
@@ -264,12 +265,12 @@ describe('Library Schematic', () => {
264
265
expect ( pkgJson . name ) . toEqual ( scopedName ) ;
265
266
266
267
const tsConfigJson = JSON . parse ( tree . readContent ( '/projects/myscope/mylib/tsconfig.spec.json' ) ) ;
267
- expect ( tsConfigJson . extends ) . toEqual ( '../../../tsconfig.json' ) ;
268
+ expect ( tsConfigJson . extends ) . toEqual ( '../../../tsconfig.base. json' ) ;
268
269
269
270
const cfg = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
270
271
expect ( cfg . projects [ '@myscope/mylib' ] ) . toBeDefined ( ) ;
271
272
272
- const rootTsCfg = JSON . parse ( tree . readContent ( '/tsconfig.json' ) ) ;
273
+ const rootTsCfg = JSON . parse ( tree . readContent ( '/tsconfig.base. json' ) ) ;
273
274
expect ( rootTsCfg . compilerOptions . paths [ '@myscope/mylib' ] ) . toEqual ( [ 'dist/myscope/mylib/myscope-mylib' , 'dist/myscope/mylib' ] ) ;
274
275
275
276
const karmaConf = getFileContent ( tree , '/projects/myscope/mylib/karma.conf.js' ) ;
@@ -314,9 +315,9 @@ describe('Library Schematic', () => {
314
315
expect ( buildOpt . tsConfig ) . toEqual ( 'foo/tsconfig.lib.json' ) ;
315
316
316
317
const appTsConfig = JSON . parse ( tree . readContent ( '/foo/tsconfig.lib.json' ) ) ;
317
- expect ( appTsConfig . extends ) . toEqual ( '../tsconfig.json' ) ;
318
+ expect ( appTsConfig . extends ) . toEqual ( '../tsconfig.base. json' ) ;
318
319
const specTsConfig = JSON . parse ( tree . readContent ( '/foo/tsconfig.spec.json' ) ) ;
319
- expect ( specTsConfig . extends ) . toEqual ( '../tsconfig.json' ) ;
320
+ expect ( specTsConfig . extends ) . toEqual ( '../tsconfig.base. json' ) ;
320
321
} ) ;
321
322
322
323
it ( `should add 'production' configuration` , async ( ) => {
@@ -326,4 +327,16 @@ describe('Library Schematic', () => {
326
327
const workspace = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
327
328
expect ( workspace . projects . foo . architect . build . configurations . production ) . toBeDefined ( ) ;
328
329
} ) ;
330
+
331
+ it ( 'should add reference in solution style tsconfig' , async ( ) => {
332
+ const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree )
333
+ . toPromise ( ) ;
334
+
335
+ // tslint:disable-next-line:no-any
336
+ const { references } = parseJson ( tree . readContent ( '/tsconfig.json' ) . toString ( ) , JsonParseMode . Loose ) as any ;
337
+ expect ( references ) . toEqual ( [
338
+ { path : './projects/foo/tsconfig.lib.json' } ,
339
+ { path : './projects/foo/tsconfig.spec.json' } ,
340
+ ] ) ;
341
+ } ) ;
329
342
} ) ;
0 commit comments