66 * found in the LICENSE file at https://angular.io/license
77 */
88// tslint:disable:no-big-function
9+ import { JsonParseMode , parseJson } from '@angular-devkit/core' ;
910import { SchematicTestRunner , UnitTestTree } from '@angular-devkit/schematics/testing' ;
1011import { getFileContent } from '../../angular/utility/test' ;
1112import { Schema as ComponentOptions } from '../component/schema' ;
@@ -200,19 +201,19 @@ describe('Library Schematic', () => {
200201 } ) ;
201202 } ) ;
202203
203- describe ( `update tsconfig.json` , ( ) => {
204+ describe ( `update tsconfig.base. json` , ( ) => {
204205 it ( `should add paths mapping to empty tsconfig` , async ( ) => {
205206 const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
206207
207- const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
208+ const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.base. json' ) ;
208209 expect ( tsConfigJson . compilerOptions . paths . foo ) . toBeTruthy ( ) ;
209210 expect ( tsConfigJson . compilerOptions . paths . foo . length ) . toEqual ( 2 ) ;
210211 expect ( tsConfigJson . compilerOptions . paths . foo [ 0 ] ) . toEqual ( 'dist/foo/foo' ) ;
211212 expect ( tsConfigJson . compilerOptions . paths . foo [ 1 ] ) . toEqual ( 'dist/foo' ) ;
212213 } ) ;
213214
214215 it ( `should append to existing paths mappings` , async ( ) => {
215- workspaceTree . overwrite ( 'tsconfig.json' , JSON . stringify ( {
216+ workspaceTree . overwrite ( 'tsconfig.base. json' , JSON . stringify ( {
216217 compilerOptions : {
217218 paths : {
218219 'unrelated' : [ './something/else.ts' ] ,
@@ -222,7 +223,7 @@ describe('Library Schematic', () => {
222223 } ) ) ;
223224 const tree = await schematicRunner . runSchematicAsync ( 'library' , defaultOptions , workspaceTree ) . toPromise ( ) ;
224225
225- const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
226+ const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.base. json' ) ;
226227 expect ( tsConfigJson . compilerOptions . paths . foo ) . toBeTruthy ( ) ;
227228 expect ( tsConfigJson . compilerOptions . paths . foo . length ) . toEqual ( 3 ) ;
228229 expect ( tsConfigJson . compilerOptions . paths . foo [ 1 ] ) . toEqual ( 'dist/foo/foo' ) ;
@@ -235,7 +236,7 @@ describe('Library Schematic', () => {
235236 skipTsConfig : true ,
236237 } , workspaceTree ) . toPromise ( ) ;
237238
238- const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.json' ) ;
239+ const tsConfigJson = getJsonFileContent ( tree , 'tsconfig.base. json' ) ;
239240 expect ( tsConfigJson . compilerOptions . paths ) . toBeUndefined ( ) ;
240241 } ) ;
241242 } ) ;
@@ -264,12 +265,12 @@ describe('Library Schematic', () => {
264265 expect ( pkgJson . name ) . toEqual ( scopedName ) ;
265266
266267 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' ) ;
268269
269270 const cfg = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
270271 expect ( cfg . projects [ '@myscope/mylib' ] ) . toBeDefined ( ) ;
271272
272- const rootTsCfg = JSON . parse ( tree . readContent ( '/tsconfig.json' ) ) ;
273+ const rootTsCfg = JSON . parse ( tree . readContent ( '/tsconfig.base. json' ) ) ;
273274 expect ( rootTsCfg . compilerOptions . paths [ '@myscope/mylib' ] ) . toEqual ( [ 'dist/myscope/mylib/myscope-mylib' , 'dist/myscope/mylib' ] ) ;
274275
275276 const karmaConf = getFileContent ( tree , '/projects/myscope/mylib/karma.conf.js' ) ;
@@ -314,9 +315,9 @@ describe('Library Schematic', () => {
314315 expect ( buildOpt . tsConfig ) . toEqual ( 'foo/tsconfig.lib.json' ) ;
315316
316317 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' ) ;
318319 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' ) ;
320321 } ) ;
321322
322323 it ( `should add 'production' configuration` , async ( ) => {
@@ -326,4 +327,16 @@ describe('Library Schematic', () => {
326327 const workspace = JSON . parse ( tree . readContent ( '/angular.json' ) ) ;
327328 expect ( workspace . projects . foo . architect . build . configurations . production ) . toBeDefined ( ) ;
328329 } ) ;
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+ } ) ;
329342} ) ;
0 commit comments