Skip to content

Commit

Permalink
fix: Increase delay between inputs on some acceptance tests
Browse files Browse the repository at this point in the history
Our prompt library inquirer only receives data from stdin after it has
been initialised. Therefore we can lose some buffered data if we send it
too fast, this is particularly noticeable if there are multiple inquirer
prompts in a row. There is no known way to check if the child process
that is under test is ready to receive input as node will swallow
anything given to stdin if it has nowhere to send it.

This hopefully will decrease the probability that these test fail by
increasing the delay between sending data to the child process.
  • Loading branch information
jgresty committed Mar 28, 2022
1 parent a86849c commit 41b7f9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions test/jest/acceptance/snyk-apps/create-app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('snyk-apps: create app', () => {
} = await runSnykCLIWithUserInputs(
'apps create --interactive --experimental',
[testData.appName, ENTER, testData.redirectURIs, ENTER, ENTER],
{ env },
{ env, delay: 200 },
);
// Assert
expect(stdout).toContain("Your Snyk App's permission scopes");
Expand Down Expand Up @@ -158,7 +158,7 @@ describe('snyk-apps: create app', () => {
testData.orgId,
ENTER,
],
{ env },
{ env, delay: 200 },
);
// Assert
expect(code).toBe(0);
Expand Down
6 changes: 4 additions & 2 deletions test/jest/util/runCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ type RunCommandResult = {
stderr: string;
};

type RunCommandOptions = SpawnOptionsWithoutStdio;
interface RunCommandOptions extends SpawnOptionsWithoutStdio {
delay?: number;
}

const runCommand = (
command: string,
Expand Down Expand Up @@ -47,7 +49,7 @@ function runCommandsWithUserInputs(
inputs: string[] = [],
options?: RunCommandOptions,
): Promise<any> {
const timeout = 100;
const timeout = options?.delay ?? 100;
const childProcess = spawn(command, args, options);

// Creates a loop to feed user inputs to the child process
Expand Down

0 comments on commit 41b7f9e

Please sign in to comment.