|
9 | 9 |
|
10 | 10 | import { Architect } from '@angular-devkit/architect';
|
11 | 11 | import { TestLogger } from '@angular-devkit/architect/testing';
|
12 |
| -import { normalize, virtualFs } from '@angular-devkit/core'; |
| 12 | +import { logging, normalize, virtualFs } from '@angular-devkit/core'; |
13 | 13 | import { debounceTime, take, takeWhile, tap } from 'rxjs/operators';
|
14 | 14 | import { createArchitect, host, lazyModuleFiles, lazyModuleStringImport } from '../utils';
|
15 | 15 |
|
@@ -68,14 +68,11 @@ describe('Browser Builder rebuilds', () => {
|
68 | 68 |
|
69 | 69 | const overrides = { watch: true };
|
70 | 70 |
|
71 |
| - let buildCount = 0; |
72 | 71 | let phase = 1;
|
73 | 72 | const run = await architect.scheduleTarget(target, overrides);
|
74 | 73 | await run.output.pipe(
|
75 | 74 | tap(result => {
|
76 | 75 | expect(result.success).toBe(true, 'build should succeed');
|
77 |
| - buildCount++; |
78 |
| - |
79 | 76 | const hasLazyChunk = host.scopedSync().exists(normalize('dist/lazy-lazy-module.js'));
|
80 | 77 | switch (phase) {
|
81 | 78 | case 1:
|
@@ -205,6 +202,47 @@ describe('Browser Builder rebuilds', () => {
|
205 | 202 | ).toPromise();
|
206 | 203 | });
|
207 | 204 |
|
| 205 | + it('rebuilds after errors in JIT', async () => { |
| 206 | + const origContent = virtualFs.fileBufferToString( |
| 207 | + host.scopedSync().read(normalize('src/app/app.component.ts'))); |
| 208 | + host.appendToFile('./src/app/app.component.ts', `console.logg('error')`); |
| 209 | + |
| 210 | + const overrides = { watch: true, aot: false }; |
| 211 | + let buildNumber = 0; |
| 212 | + const logger = new logging.Logger(''); |
| 213 | + let logs: string[] = []; |
| 214 | + logger.subscribe(e => logs.push(e.message)); |
| 215 | + |
| 216 | + const run = await architect.scheduleTarget(target, overrides, { logger }); |
| 217 | + await run.output.pipe( |
| 218 | + debounceTime(1000), |
| 219 | + tap((buildEvent) => { |
| 220 | + buildNumber ++; |
| 221 | + switch (buildNumber) { |
| 222 | + case 1: |
| 223 | + // The first build should error out with an error. |
| 224 | + expect(buildEvent.success).toBe(false); |
| 225 | + expect(logs.join()).toContain(`Property 'logg' does not exist on type 'Console'`); |
| 226 | + logs = []; |
| 227 | + // Fix the error. |
| 228 | + host.writeMultipleFiles({ 'src/app/app.component.ts': ` |
| 229 | + ${origContent} |
| 230 | + console.errorr('error'); |
| 231 | + `}); |
| 232 | + break; |
| 233 | + |
| 234 | + case 2: |
| 235 | + // The second build should have everything fixed. |
| 236 | + expect(buildEvent.success).toBe(true); |
| 237 | + expect(logs.join()).not.toContain('Module build failed'); |
| 238 | + break; |
| 239 | + } |
| 240 | + }), |
| 241 | + take(2), |
| 242 | + ).toPromise(); |
| 243 | + await run.stop(); |
| 244 | + }); |
| 245 | + |
208 | 246 | it('rebuilds after errors in AOT', async () => {
|
209 | 247 | // Save the original contents of `./src/app/app.component.ts`.
|
210 | 248 | const origContent = virtualFs.fileBufferToString(
|
|
0 commit comments