From 41b7f9e473d3d8a689e3bf2c546da135748a7c4c Mon Sep 17 00:00:00 2001 From: John Gresty Date: Mon, 28 Mar 2022 17:09:14 +0100 Subject: [PATCH] fix: Increase delay between inputs on some acceptance tests 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. --- test/jest/acceptance/snyk-apps/create-app.spec.ts | 4 ++-- test/jest/util/runCommand.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/jest/acceptance/snyk-apps/create-app.spec.ts b/test/jest/acceptance/snyk-apps/create-app.spec.ts index 87ea965ad0..e75d23aae2 100644 --- a/test/jest/acceptance/snyk-apps/create-app.spec.ts +++ b/test/jest/acceptance/snyk-apps/create-app.spec.ts @@ -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"); @@ -158,7 +158,7 @@ describe('snyk-apps: create app', () => { testData.orgId, ENTER, ], - { env }, + { env, delay: 200 }, ); // Assert expect(code).toBe(0); diff --git a/test/jest/util/runCommand.ts b/test/jest/util/runCommand.ts index 12bbc31230..2516bf2017 100644 --- a/test/jest/util/runCommand.ts +++ b/test/jest/util/runCommand.ts @@ -7,7 +7,9 @@ type RunCommandResult = { stderr: string; }; -type RunCommandOptions = SpawnOptionsWithoutStdio; +interface RunCommandOptions extends SpawnOptionsWithoutStdio { + delay?: number; +} const runCommand = ( command: string, @@ -47,7 +49,7 @@ function runCommandsWithUserInputs( inputs: string[] = [], options?: RunCommandOptions, ): Promise { - 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