|
8 | 8 | getProjectStyleFile, |
9 | 9 | getProjectTargetOptions, |
10 | 10 | } from '@angular/cdk/schematics'; |
11 | | -import {createTestApp, getFileContent} from '@angular/cdk/schematics/testing'; |
| 11 | +import {createTestApp, createTestLibrary, getFileContent} from '@angular/cdk/schematics/testing'; |
12 | 12 | import {getWorkspace} from '@schematics/angular/utility/config'; |
13 | 13 | import {COLLECTION_PATH} from '../index.spec'; |
14 | 14 | import {addPackageToPackageJson} from './package-config'; |
@@ -419,3 +419,33 @@ describe('ng-add schematic', () => { |
419 | 419 | }); |
420 | 420 | }); |
421 | 421 | }); |
| 422 | + |
| 423 | +describe('ng-add schematic - library project', () => { |
| 424 | + let runner: SchematicTestRunner; |
| 425 | + let libraryTree: Tree; |
| 426 | + let errorOutput: string[]; |
| 427 | + let warnOutput: string[]; |
| 428 | + |
| 429 | + beforeEach(async () => { |
| 430 | + runner = new SchematicTestRunner('schematics', require.resolve('../collection.json')); |
| 431 | + libraryTree = await createTestLibrary(runner); |
| 432 | + |
| 433 | + errorOutput = []; |
| 434 | + warnOutput = []; |
| 435 | + runner.logger.subscribe(e => { |
| 436 | + if (e.level === 'error') { |
| 437 | + errorOutput.push(e.message); |
| 438 | + } else if (e.level === 'warn') { |
| 439 | + warnOutput.push(e.message); |
| 440 | + } |
| 441 | + }); |
| 442 | + }); |
| 443 | + |
| 444 | + it('should warn if a library project is targeted', async () => { |
| 445 | + await runner.runSchematicAsync('ng-add-setup-project', {}, libraryTree).toPromise(); |
| 446 | + |
| 447 | + expect(errorOutput.length).toBe(0); |
| 448 | + expect(warnOutput.length).toBe(1); |
| 449 | + expect(warnOutput[0]).toMatch(/There is no additional setup required/); |
| 450 | + }); |
| 451 | +}); |
0 commit comments