Skip to content

Commit

Permalink
fix(@ngtools/webpack): wait for plugin when resolving ts requests
Browse files Browse the repository at this point in the history
Fix #5137
  • Loading branch information
filipesilva authored and hansl committed Aug 23, 2017
1 parent df7e631 commit aa34b28
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/@ngtools/webpack/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,11 @@ export class AotPlugin implements Tapable {

compiler.plugin('after-resolvers', (compiler: any) => {
// Virtual file system.
// Wait for the plugin to be done when requesting `.ts` files directly (entry points), or
// when the issuer is a `.ts` file.
compiler.resolvers.normal.plugin('before-resolve', (request: any, cb: () => void) => {
if (request.request.match(/\.ts$/)) {
if (request.request.endsWith('.ts')
|| (request.context.issuer && request.context.issuer.endsWith('.ts'))) {
this.done!.then(() => cb(), () => cb());
} else {
cb();
Expand Down
45 changes: 45 additions & 0 deletions tests/e2e/tests/build/aot/aot-rebuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
killAllProcesses,
waitForAnyProcessOutputToMatch,
execAndWaitForOutputToMatch,
} from '../../../utils/process';
import { appendToFile } from '../../../utils/fs';
import { getGlobalVariable } from '../../../utils/env';
import { request } from '../../../utils/http';
import { wait } from '../../../utils/utils';

const validBundleRegEx = /webpack: bundle is now VALID|webpack: Compiled successfully./;

export default function () {
if (process.platform.startsWith('win')) {
return Promise.resolve();
}
// Skip this in ejected tests.
if (getGlobalVariable('argv').eject) {
return Promise.resolve();
}

return execAndWaitForOutputToMatch('ng', ['serve', '--aot'], validBundleRegEx)
// Wait before editing a file.
// Editing too soon seems to trigger a rebuild and throw polling/watch out of whack.
.then(() => wait(2000))
// Check AOT templates are up to date with current code.
.then(() => request('http://localhost:4200/main.bundle.js'))
.then((body) => {
if (body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
throw new Error('Expected golden value 1 to not be present.');
}
})
.then(() => appendToFile('src/app/app.component.html', '<p> $$_E2E_GOLDEN_VALUE_1 </p>'))
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 20000))
.then(() => request('http://localhost:4200/main.bundle.js'))
.then((body) => {
if (!body.match(/\$\$_E2E_GOLDEN_VALUE_1/)) {
throw new Error('Expected golden value 1.');
}
})
.then(() => killAllProcesses(), (err: any) => {
killAllProcesses();
throw err;
});
}

0 comments on commit aa34b28

Please sign in to comment.