|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 |
|
9 |
| -import { runTargetSpec } from '@angular-devkit/architect/testing'; |
| 9 | +import { DefaultTimeout, TestLogger, runTargetSpec } from '@angular-devkit/architect/testing'; |
10 | 10 | import { join, normalize, virtualFs } from '@angular-devkit/core';
|
11 |
| -import { takeWhile, tap } from 'rxjs/operators'; |
| 11 | +import { of, race } from 'rxjs'; |
| 12 | +import { delay, filter, map, take, takeUntil, takeWhile, tap } from 'rxjs/operators'; |
12 | 13 | import { browserTargetSpec, host } from '../utils';
|
13 | 14 |
|
14 | 15 |
|
@@ -154,4 +155,53 @@ describe('Browser Builder file replacements', () => {
|
154 | 155 | );
|
155 | 156 | });
|
156 | 157 |
|
| 158 | + it('file replacements work with forked type checker on watch mode', async () => { |
| 159 | + host.writeMultipleFiles({ |
| 160 | + 'src/file-replaced.ts': 'export var obj = { one: 1, two: 2 };', |
| 161 | + 'src/file.ts': `export var obj = { one: 1 };`, |
| 162 | + 'src/main.ts': ` |
| 163 | + import { obj } from './file'; |
| 164 | + console.log(obj.two); |
| 165 | + `, |
| 166 | + }); |
| 167 | + |
| 168 | + const overrides = { |
| 169 | + fileReplacements: [{ |
| 170 | + replace: normalize('/src/file.ts'), |
| 171 | + with: normalize('/src/file-replaced.ts'), |
| 172 | + }], |
| 173 | + watch: true, |
| 174 | + }; |
| 175 | + |
| 176 | + const unexpectedError = `Property 'two' does not exist on type '{ one: number; }'`; |
| 177 | + const expectedError = `Property 'prop' does not exist on type '{}'`; |
| 178 | + const logger = new TestLogger('rebuild-type-errors'); |
| 179 | + |
| 180 | + // Race between a timeout and the expected log entry. |
| 181 | + const stop$ = race<null | string>( |
| 182 | + of(null).pipe(delay(DefaultTimeout * 2 / 3)), |
| 183 | + logger.pipe( |
| 184 | + filter(entry => entry.message.includes(expectedError)), |
| 185 | + map(entry => entry.message), |
| 186 | + take(1), |
| 187 | + ), |
| 188 | + ); |
| 189 | + |
| 190 | + let errorAdded = false; |
| 191 | + runTargetSpec(host, browserTargetSpec, overrides, DefaultTimeout, logger).pipe( |
| 192 | + tap((buildEvent) => expect(buildEvent.success).toBe(true, 'build should succeed')), |
| 193 | + tap(() => { |
| 194 | + // Introduce a known type error to detect in the logger filter. |
| 195 | + if (!errorAdded) { |
| 196 | + host.appendToFile('src/main.ts', 'console.log({}.prop);'); |
| 197 | + errorAdded = true; |
| 198 | + } |
| 199 | + }), |
| 200 | + takeUntil(stop$), |
| 201 | + ).subscribe(); |
| 202 | + |
| 203 | + const res = await stop$.toPromise(); |
| 204 | + expect(res).not.toBe(null, 'Test timed out.'); |
| 205 | + expect(res).not.toContain(unexpectedError); |
| 206 | + }); |
157 | 207 | });
|
0 commit comments