|
8 | 8 |
|
9 | 9 | import { TargetSpecifier } from '@angular-devkit/architect';
|
10 | 10 | import { TestProjectHost, runTargetSpec } from '@angular-devkit/architect/testing';
|
11 |
| -import { join, normalize } from '@angular-devkit/core'; |
12 |
| -import { tap } from 'rxjs/operators'; |
13 |
| - |
| 11 | +import { join, normalize, virtualFs } from '@angular-devkit/core'; |
| 12 | +import { debounceTime, map, take, tap } from 'rxjs/operators'; |
14 | 13 |
|
15 | 14 | const devkitRoot = normalize((global as any)._DevKitRoot); // tslint:disable-line:no-any
|
16 | 15 | const workspaceRoot = join(devkitRoot, 'tests/angular_devkit/build_ng_packagr/ng-packaged/');
|
@@ -43,4 +42,59 @@ describe('NgPackagr Builder', () => {
|
43 | 42 | tap((buildEvent) => expect(buildEvent.success).toBe(true)),
|
44 | 43 | ).toPromise().then(done, done.fail);
|
45 | 44 | });
|
| 45 | + |
| 46 | + it('rebuilds on TS file changes', (done) => { |
| 47 | + const targetSpec: TargetSpecifier = { project: 'lib', target: 'build' }; |
| 48 | + |
| 49 | + const goldenValueFiles: { [path: string]: string } = { |
| 50 | + 'projects/lib/src/lib/lib.component.ts': ` |
| 51 | + import { Component } from '@angular/core'; |
| 52 | +
|
| 53 | + @Component({ |
| 54 | + selector: 'lib', |
| 55 | + template: 'lib update works!' |
| 56 | + }) |
| 57 | + export class LibComponent { } |
| 58 | + `, |
| 59 | + }; |
| 60 | + |
| 61 | + const overrides = { watch: true }; |
| 62 | + |
| 63 | + let buildNumber = 0; |
| 64 | + |
| 65 | + runTargetSpec(host, targetSpec, overrides) |
| 66 | + .pipe( |
| 67 | + // We must debounce on watch mode because file watchers are not very accurate. |
| 68 | + // Changes from just before a process runs can be picked up and cause rebuilds. |
| 69 | + // In this case, cleanup from the test right before this one causes a few rebuilds. |
| 70 | + debounceTime(1000), |
| 71 | + tap((buildEvent) => expect(buildEvent.success).toBe(true)), |
| 72 | + map(() => { |
| 73 | + const fileName = './dist/lib/fesm5/lib.js'; |
| 74 | + const content = virtualFs.fileBufferToString( |
| 75 | + host.scopedSync().read(normalize(fileName)), |
| 76 | + ); |
| 77 | + |
| 78 | + return content; |
| 79 | + }), |
| 80 | + tap(content => { |
| 81 | + buildNumber += 1; |
| 82 | + switch (buildNumber) { |
| 83 | + case 1: |
| 84 | + expect(content).toMatch(/lib works/); |
| 85 | + host.writeMultipleFiles(goldenValueFiles); |
| 86 | + break; |
| 87 | + |
| 88 | + case 2: |
| 89 | + expect(content).toMatch(/lib update works/); |
| 90 | + break; |
| 91 | + default: |
| 92 | + break; |
| 93 | + } |
| 94 | + }), |
| 95 | + take(2), |
| 96 | + ) |
| 97 | + .toPromise() |
| 98 | + .then(done, done.fail); |
| 99 | + }); |
46 | 100 | });
|
0 commit comments