Skip to content

fix(@ngtools/webpack): rebuilding project with errors reports cannot … #14658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { Architect } from '@angular-devkit/architect';
import { TestLogger } from '@angular-devkit/architect/testing';
import { normalize, virtualFs } from '@angular-devkit/core';
import { logging, normalize, virtualFs } from '@angular-devkit/core';
import { debounceTime, take, takeWhile, tap } from 'rxjs/operators';
import { createArchitect, host, lazyModuleFiles, lazyModuleStringImport } from '../utils';

Expand Down Expand Up @@ -68,14 +68,11 @@ describe('Browser Builder rebuilds', () => {

const overrides = { watch: true };

let buildCount = 0;
let phase = 1;
const run = await architect.scheduleTarget(target, overrides);
await run.output.pipe(
tap(result => {
expect(result.success).toBe(true, 'build should succeed');
buildCount++;

const hasLazyChunk = host.scopedSync().exists(normalize('dist/lazy-lazy-module.js'));
switch (phase) {
case 1:
Expand Down Expand Up @@ -205,6 +202,47 @@ describe('Browser Builder rebuilds', () => {
).toPromise();
});

it('rebuilds after errors in JIT', async () => {
const origContent = virtualFs.fileBufferToString(
host.scopedSync().read(normalize('src/app/app.component.ts')));
host.appendToFile('./src/app/app.component.ts', `console.logg('error')`);

const overrides = { watch: true, aot: false };
let buildNumber = 0;
const logger = new logging.Logger('');
let logs: string[] = [];
logger.subscribe(e => logs.push(e.message));

const run = await architect.scheduleTarget(target, overrides, { logger });
await run.output.pipe(
debounceTime(1000),
tap((buildEvent) => {
buildNumber ++;
switch (buildNumber) {
case 1:
// The first build should error out with an error.
expect(buildEvent.success).toBe(false);
expect(logs.join()).toContain(`Property 'logg' does not exist on type 'Console'`);
logs = [];
// Fix the error.
host.writeMultipleFiles({ 'src/app/app.component.ts': `
${origContent}
console.errorr('error');
`});
break;

case 2:
// The second build should have everything fixed.
expect(buildEvent.success).toBe(true);
expect(logs.join()).not.toContain('Module build failed');
break;
}
}),
take(2),
).toPromise();
await run.stop();
});

it('rebuilds after errors in AOT', async () => {
// Save the original contents of `./src/app/app.component.ts`.
const origContent = virtualFs.fileBufferToString(
Expand Down
2 changes: 1 addition & 1 deletion packages/ngtools/webpack/src/angular_compiler_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ export class AngularCompilerPlugin {
'AngularCompilerPlugin._emit.ts', diagMode));

if (!hasErrors(allDiagnostics)) {
if (this._firstRun || changedTsFiles.size > 20) {
if (this._firstRun || changedTsFiles.size > 20 || this._emitSkipped) {
emitResult = tsProgram.emit(
undefined,
undefined,
Expand Down