@@ -4,11 +4,12 @@ import {Tree} from '@angular-devkit/schematics';
4
4
import { SchematicTestRunner } from '@angular-devkit/schematics/testing' ;
5
5
import {
6
6
addModuleImportToRootModule ,
7
- getProjectFromWorkspace , getProjectIndexFiles ,
7
+ getProjectFromWorkspace ,
8
+ getProjectIndexFiles ,
8
9
getProjectStyleFile ,
9
10
getProjectTargetOptions ,
10
11
} from '@angular/cdk/schematics' ;
11
- import { createTestApp , getFileContent } from '@angular/cdk/schematics/testing' ;
12
+ import { createTestApp , createTestLibrary , getFileContent } from '@angular/cdk/schematics/testing' ;
12
13
import { getWorkspace } from '@schematics/angular/utility/config' ;
13
14
import { COLLECTION_PATH } from '../index.spec' ;
14
15
import { addPackageToPackageJson } from './package-config' ;
@@ -75,10 +76,10 @@ describe('ng-add schematic', () => {
75
76
Object . keys ( dependencies ) . sort ( ) ,
76
77
'Expected the modified "dependencies" to be sorted alphabetically.' ) ;
77
78
78
- expect ( runner . tasks . some ( task => task . name === 'node-package' ) ) . toBe ( true ,
79
- 'Expected the package manager to be scheduled in order to update lock files.' ) ;
80
- expect ( runner . tasks . some ( task => task . name === 'run-schematic' ) ) . toBe ( true ,
81
- 'Expected the setup-project schematic to be scheduled.' ) ;
79
+ expect ( runner . tasks . some ( task => task . name === 'node-package' ) )
80
+ . toBe ( true , 'Expected the package manager to be scheduled in order to update lock files.' ) ;
81
+ expect ( runner . tasks . some ( task => task . name === 'run-schematic' ) )
82
+ . toBe ( true , 'Expected the setup-project schematic to be scheduled.' ) ;
82
83
} ) ;
83
84
84
85
it ( 'should respect version range from CLI ng-add command' , async ( ) => {
@@ -152,10 +153,10 @@ describe('ng-add schematic', () => {
152
153
// the created links properly align with the existing HTML. Default CLI projects use an
153
154
// indentation of two columns.
154
155
expect ( htmlContent )
155
- . toContain ( ' <link href="https://fonts.googleapis.com/icon?family=Material+Icons"' ) ;
156
+ . toContain ( ' <link href="https://fonts.googleapis.com/icon?family=Material+Icons"' ) ;
156
157
expect ( htmlContent )
157
- . toContain (
158
- ' <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap"' ) ;
158
+ . toContain (
159
+ ' <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500&display=swap"' ) ;
159
160
} ) ;
160
161
} ) ;
161
162
@@ -246,7 +247,7 @@ describe('ng-add schematic', () => {
246
247
overwriteTargetBuilder ( appTree , 'build' , 'thirdparty-builder' ) ;
247
248
248
249
await expectAsync ( runner . runSchematicAsync ( 'ng-add-setup-project' , { } , appTree ) . toPromise ( ) )
249
- . toBeRejectedWithError ( / n o t u s i n g t h e d e f a u l t b u i l d e r s .* b u i l d / ) ;
250
+ . toBeRejectedWithError ( / n o t u s i n g t h e d e f a u l t b u i l d e r s .* b u i l d / ) ;
250
251
} ) ;
251
252
252
253
it ( 'should warn if the "test" target has been changed' , async ( ) => {
@@ -256,8 +257,8 @@ describe('ng-add schematic', () => {
256
257
257
258
expect ( errorOutput . length ) . toBe ( 0 ) ;
258
259
expect ( warnOutput . length ) . toBe ( 1 ) ;
259
- expect ( warnOutput [ 0 ] ) . toMatch (
260
- / n o t u s i n g t h e d e f a u l t b u i l d e r s .* c a n n o t a d d t h e c o n f i g u r e d t h e m e / ) ;
260
+ expect ( warnOutput [ 0 ] )
261
+ . toMatch ( / n o t u s i n g t h e d e f a u l t b u i l d e r s .* c a n n o t a d d t h e c o n f i g u r e d t h e m e / ) ;
261
262
} ) ;
262
263
} ) ;
263
264
@@ -335,9 +336,8 @@ describe('ng-add schematic', () => {
335
336
} ) ;
336
337
337
338
it ( 'should add the global typography class if the body has no classes' , async ( ) => {
338
- const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , {
339
- typography : true
340
- } , appTree ) . toPromise ( ) ;
339
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { typography : true } , appTree )
340
+ . toPromise ( ) ;
341
341
const workspace = getWorkspace ( tree ) ;
342
342
const project = getProjectFromWorkspace ( workspace ) ;
343
343
@@ -358,9 +358,8 @@ describe('ng-add schematic', () => {
358
358
</html>
359
359
` ) ;
360
360
361
- const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , {
362
- typography : true
363
- } , appTree ) . toPromise ( ) ;
361
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { typography : true } , appTree )
362
+ . toPromise ( ) ;
364
363
365
364
const workspace = getWorkspace ( tree ) ;
366
365
const project = getProjectFromWorkspace ( workspace ) ;
@@ -381,9 +380,8 @@ describe('ng-add schematic', () => {
381
380
</html>
382
381
` ) ;
383
382
384
- const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , {
385
- typography : true
386
- } , appTree ) . toPromise ( ) ;
383
+ const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , { typography : true } , appTree )
384
+ . toPromise ( ) ;
387
385
388
386
const workspace = getWorkspace ( tree ) ;
389
387
const project = getProjectFromWorkspace ( workspace ) ;
@@ -404,9 +402,9 @@ describe('ng-add schematic', () => {
404
402
</html>
405
403
` ) ;
406
404
407
- const tree = await runner . runSchematicAsync ( 'ng-add-setup-project' , {
408
- typography : false
409
- } , appTree ) . toPromise ( ) ;
405
+ const tree =
406
+ await runner . runSchematicAsync ( 'ng-add-setup-project' , { typography : false } , appTree )
407
+ . toPromise ( ) ;
410
408
411
409
const workspace = getWorkspace ( tree ) ;
412
410
const project = getProjectFromWorkspace ( workspace ) ;
@@ -419,3 +417,33 @@ describe('ng-add schematic', () => {
419
417
} ) ;
420
418
} ) ;
421
419
} ) ;
420
+
421
+ describe ( 'ng-add schematic - library project' , ( ) => {
422
+ let runner : SchematicTestRunner ;
423
+ let libraryTree : Tree ;
424
+ let errorOutput : string [ ] ;
425
+ let warnOutput : string [ ] ;
426
+
427
+ beforeEach ( async ( ) => {
428
+ runner = new SchematicTestRunner ( 'schematics' , require . resolve ( '../collection.json' ) ) ;
429
+ libraryTree = await createTestLibrary ( runner ) ;
430
+
431
+ errorOutput = [ ] ;
432
+ warnOutput = [ ] ;
433
+ runner . logger . subscribe ( e => {
434
+ if ( e . level === 'error' ) {
435
+ errorOutput . push ( e . message ) ;
436
+ } else if ( e . level === 'warn' ) {
437
+ warnOutput . push ( e . message ) ;
438
+ }
439
+ } ) ;
440
+ } ) ;
441
+
442
+ it ( 'should warn if a library project is targeted' , async ( ) => {
443
+ await runner . runSchematicAsync ( 'ng-add-setup-project' , { } , libraryTree ) . toPromise ( ) ;
444
+
445
+ expect ( errorOutput . length ) . toBe ( 0 ) ;
446
+ expect ( warnOutput . length ) . toBe ( 1 ) ;
447
+ expect ( warnOutput [ 0 ] ) . toMatch ( / Y o u r p r o j e c t i s a l i b r a r y / ) ;
448
+ } ) ;
449
+ } ) ;
0 commit comments