|
8 | 8 |
|
9 | 9 | import { runTargetSpec } from '@angular-devkit/architect/testing';
|
10 | 10 | import { join, normalize, virtualFs } from '@angular-devkit/core';
|
11 |
| -import { tap } from 'rxjs/operators'; |
| 11 | +import { debounceTime, take, tap } from 'rxjs/operators'; |
12 | 12 | import { browserTargetSpec, host } from '../utils';
|
13 | 13 |
|
14 | 14 |
|
@@ -100,4 +100,45 @@ describe('Browser Builder file replacements', () => {
|
100 | 100 | runTargetSpec(host, browserTargetSpec, overrides)
|
101 | 101 | .subscribe(undefined, () => done(), done.fail);
|
102 | 102 | });
|
| 103 | + |
| 104 | + it('file replacements work with watch mode', (done) => { |
| 105 | + const overrides = { |
| 106 | + fileReplacements: [ |
| 107 | + { |
| 108 | + replace: normalize('/src/meaning.ts'), |
| 109 | + with: normalize('/src/meaning-too.ts'), |
| 110 | + }, |
| 111 | + ], |
| 112 | + watch: true, |
| 113 | + }; |
| 114 | + |
| 115 | + let buildNumber = 0; |
| 116 | + |
| 117 | + runTargetSpec(host, browserTargetSpec, overrides, 45000).pipe( |
| 118 | + debounceTime(1000), |
| 119 | + tap((buildEvent) => expect(buildEvent.success).toBe(true)), |
| 120 | + tap(() => { |
| 121 | + const fileName = join(outputPath, 'main.js'); |
| 122 | + const content = virtualFs.fileBufferToString(host.scopedSync().read(fileName)); |
| 123 | + buildNumber += 1; |
| 124 | + |
| 125 | + switch (buildNumber) { |
| 126 | + case 1: |
| 127 | + expect(content).toMatch(/meaning\s*=\s*42/); |
| 128 | + expect(content).not.toMatch(/meaning\s*=\s*10/); |
| 129 | + host.writeMultipleFiles({ |
| 130 | + 'src/meaning-too.ts': 'export var meaning = 84;', |
| 131 | + }); |
| 132 | + break; |
| 133 | + |
| 134 | + case 2: |
| 135 | + expect(content).toMatch(/meaning\s*=\s*84/); |
| 136 | + expect(content).not.toMatch(/meaning\s*=\s*42/); |
| 137 | + break; |
| 138 | + } |
| 139 | + }), |
| 140 | + take(2), |
| 141 | + ).toPromise().then(() => done(), done.fail); |
| 142 | + }); |
| 143 | + |
103 | 144 | });
|
0 commit comments