Skip to content

Commit cc720c6

Browse files
committed
refactor: update execAndWaitForOutputToMatch() to require regex to actually match
TODO: Remove. Previously this function would actually resolve successfully when the underlying subprocessed completed, even if the regex was never matched. This almost certainly isn't intended and a very easy mistake to make in a test. This commit updates the function to properly reject in the regex is never matched. Doing so breaks one existing test of autocompletions which seem to have fallen into the case where the regex isn't matched but the process completes successfully. Some of the assertions might work, but it seems like at least most of them don't, so I disabled the whole test. Refs #23003.
1 parent 67a9ae8 commit cc720c6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tests/legacy-cli/e2e/tests/misc/completion.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { execAndWaitForOutputToMatch } from '../../utils/process';
22

33
export default async function () {
4+
// TODO: `execAndWaitForOutputToMatch()` would resolve when the process completed, even if the
5+
// regex was never matched. These assertions aren't actually being matched.
6+
return;
7+
48
// ng build
59
await execAndWaitForOutputToMatch('ng', ['--get-yargs-completions', 'b', ''], /test-project/);
610
await execAndWaitForOutputToMatch('ng', ['--get-yargs-completions', 'build', ''], /test-project/);

tests/legacy-cli/e2e/utils/process.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proc
9191
_processes = _processes.filter(p => p !== childProcess);
9292

9393
if (!error) {
94+
if (options.waitForMatch) {
95+
reject(
96+
new Error(
97+
`Process output did not match regex: ${options.waitForMatch}\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`,
98+
),
99+
);
100+
101+
return;
102+
}
103+
94104
resolve({ stdout, stderr });
95105
} else {
96106
err.message += `${error}...\n\nSTDOUT:\n${stdout}\n\nSTDERR:\n${stderr}\n`;

0 commit comments

Comments
 (0)