Skip to content

Commit 89225f2

Browse files
Charles Lydingfilipesilva
Charles Lyding
authored andcommitted
test: attempt to reduce flakiness of rebuild e2e test
1 parent 38a2bc7 commit 89225f2

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

tests/e2e/tests/build/rebuild.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import {
55
silentExecAndWaitForOutputToMatch,
66
ng,
77
} from '../../utils/process';
8-
import {writeFile, writeMultipleFiles, appendToFile, expectFileToMatch} from '../../utils/fs';
8+
import {writeFile, writeMultipleFiles} from '../../utils/fs';
99
import {wait} from '../../utils/utils';
1010
import {request} from '../../utils/http';
1111
import {getGlobalVariable} from '../../utils/env';
1212

13+
const validBundleRegEx = /webpack: bundle is now VALID|webpack: Compiled successfully./;
14+
const invalidBundleRegEx = /webpack: bundle is now INVALID|webpack: Compiling.../;
1315

1416
export default function() {
1517
if (process.platform.startsWith('win')) {
@@ -23,22 +25,19 @@ export default function() {
2325
let oldNumberOfChunks = 0;
2426
const chunkRegExp = /chunk\s+\{/g;
2527

26-
return silentExecAndWaitForOutputToMatch('ng', ['serve'],
27-
/webpack: bundle is now VALID|webpack: Compiled successfully./)
28+
return silentExecAndWaitForOutputToMatch('ng', ['serve'], validBundleRegEx)
2829
// Should trigger a rebuild.
2930
.then(() => exec('touch', 'src/main.ts'))
30-
.then(() => waitForAnyProcessOutputToMatch(
31-
/webpack: bundle is now INVALID|webpack: Compiling.../, 10000))
32-
.then(() => waitForAnyProcessOutputToMatch(
33-
/webpack: bundle is now VALID|webpack: Compiled successfully./, 10000))
31+
.then(() => waitForAnyProcessOutputToMatch(invalidBundleRegEx, 10000))
32+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 10000))
3433
// Count the bundles.
3534
.then(({ stdout }) => {
3635
oldNumberOfChunks = stdout.split(chunkRegExp).length;
3736
})
3837
// Add a lazy module.
3938
.then(() => ng('generate', 'module', 'lazy', '--routing'))
4039
// Just wait for the rebuild, otherwise we might be validating the last build.
41-
.then(() => wait(2000))
40+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 10000))
4241
.then(() => writeFile('src/app/app.module.ts', `
4342
import { BrowserModule } from '@angular/platform-browser';
4443
import { NgModule } from '@angular/core';
@@ -65,18 +64,15 @@ export default function() {
6564
})
6665
export class AppModule { }
6766
`))
68-
.then(() => wait(2000))
6967
// Should trigger a rebuild with a new bundle.
70-
.then(() => waitForAnyProcessOutputToMatch(
71-
/webpack: bundle is now VALID|webpack: Compiled successfully./, 10000))
68+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 10000))
7269
// Count the bundles.
7370
.then(({ stdout }) => {
7471
let newNumberOfChunks = stdout.split(chunkRegExp).length;
7572
if (oldNumberOfChunks >= newNumberOfChunks) {
7673
throw new Error('Expected webpack to create a new chunk, but did not.');
7774
}
7875
})
79-
.then(() => wait(2000))
8076
// Change multiple files and check that all of them are invalidated and recompiled.
8177
.then(() => writeMultipleFiles({
8278
'src/app/app.module.ts': `
@@ -89,8 +85,7 @@ export default function() {
8985
console.log('$$_E2E_GOLDEN_VALUE_3');
9086
`
9187
}))
92-
.then(() => waitForAnyProcessOutputToMatch(
93-
/webpack: bundle is now VALID|webpack: Compiled successfully./, 10000))
88+
.then(() => waitForAnyProcessOutputToMatch(validBundleRegEx, 10000))
9489
.then(() => wait(2000))
9590
.then(() => request('http://localhost:4200/main.bundle.js'))
9691
.then((body) => {

0 commit comments

Comments
 (0)