Skip to content

Commit

Permalink
Merge 781a606 into 676f9b5
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Jul 24, 2021
2 parents 676f9b5 + 781a606 commit 8d50664
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/test/inquirer.private.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ function runBackportAsync(
...options,
]);

return new Promise<string>((resolve, reject) => {
const p = new Promise<string>((resolve, reject) => {
let data = '';

// fail if expectations hasn't been found within 4s
const TIMEOUT_IN_SECONDS = 4;
const timeout = setTimeout(() => {
reject(`Expectation "${waitForString}" not found in: ${data.toString()}`);
}, 4000);
reject(`Expectation '${waitForString}' not found within ${TIMEOUT_IN_SECONDS} seconds in:
'${data.toString()}'`);
}, TIMEOUT_IN_SECONDS * 1000);

proc.stdout.on('data', (dataChunk) => {
data += dataChunk;
Expand All @@ -186,9 +188,15 @@ function runBackportAsync(
if (!waitForString || output.includes(waitForString)) {
clearTimeout(timeout);
// remove ansi codes and whitespace
resolve(stripAnsi(output).replace(/\s+$/gm, ''));
proc.kill();
const strippedOutput = stripAnsi(output).replace(/\s+$/gm, '');

resolve(strippedOutput);
}
});
});

// kill child process
return p.finally(() => {
proc.kill();
});
}

0 comments on commit 8d50664

Please sign in to comment.