Skip to content

Commit abb168e

Browse files
filipesilvaBrocco
authored andcommitted
ci: support debouncing for ng serve
1 parent b6dfa8d commit abb168e

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

tests/e2e/utils/process.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as child_process from 'child_process';
22
import {blue, yellow} from 'chalk';
3+
import {Subject, Observable} from 'rxjs';
34
import {getGlobalVariable} from './env';
45
import {rimraf} from './fs';
56
import {wait} from './utils';
@@ -91,6 +92,11 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
9192
resolve({ stdout, stderr });
9293
}
9394
});
95+
childProcess.stderr.on('data', (data: Buffer) => {
96+
if (data.toString().match(options.waitForMatch)) {
97+
resolve({ stdout, stderr });
98+
}
99+
});
94100
}
95101
});
96102
}
@@ -140,25 +146,27 @@ export function silentExec(cmd: string, ...args: string[]) {
140146
}
141147

142148
export function execAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) {
143-
let maybeWait = Promise.resolve();
144149
if (cmd === 'ng' && args[0] === 'serve') {
145-
// Webpack watcher can rebuild a few times due to files changes that happened just before the
146-
// build (e.g. `git clean`), so we wait here.
147-
maybeWait = wait(5000);
148-
}
149-
return maybeWait.then(() => _exec({ waitForMatch: match }, cmd, args));
150-
}
151-
152-
export function silentExecAndWaitForOutputToMatch(cmd: string, args: string[], match: RegExp) {
153-
let maybeWait = Promise.resolve();
154-
if (cmd === 'ng' && args[0] === 'serve') {
155-
// See execAndWaitForOutputToMatch for why the wait.
156-
maybeWait = wait(5000);
150+
// Accept matches up to 20 times after the initial match.
151+
// Useful because the Webpack watcher can rebuild a few times due to files changes that
152+
// happened just before the build (e.g. `git clean`).
153+
// This seems to be due to host file system differences, see
154+
// https://nodejs.org/docs/latest/api/fs.html#fs_caveats
155+
return Observable.fromPromise(_exec({ waitForMatch: match }, cmd, args))
156+
.concat(
157+
Observable.defer(() =>
158+
Observable.fromPromise(waitForAnyProcessOutputToMatch(match, 2500))
159+
.repeat(20)
160+
.catch(_x => Observable.empty())
161+
)
162+
)
163+
.takeLast(1)
164+
.toPromise();
165+
} else {
166+
return _exec({ waitForMatch: match }, cmd, args);
157167
}
158-
return maybeWait.then(() => _exec({ silent: true, waitForMatch: match }, cmd, args));
159168
}
160169

161-
162170
let npmInstalledEject = false;
163171
export function ng(...args: string[]) {
164172
const argv = getGlobalVariable('argv');

0 commit comments

Comments
 (0)