From bb88c9eb0579e1d6b89039d0fb7423fe523963e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Thu, 26 Sep 2024 13:33:11 +0200 Subject: [PATCH] Refactored "runAndGetOutputWithoutErrors" into "waitForCleanOutout" --- packages/e2e-tests/test/e2e-snapshot.spec.ts | 3 +-- packages/e2e-tests/test/test-shell.ts | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/e2e-tests/test/e2e-snapshot.spec.ts b/packages/e2e-tests/test/e2e-snapshot.spec.ts index ef690582d..f887fae94 100644 --- a/packages/e2e-tests/test/e2e-snapshot.spec.ts +++ b/packages/e2e-tests/test/e2e-snapshot.spec.ts @@ -2,7 +2,6 @@ import { skipIfApiStrict, startSharedTestServer, } from '../../../testing/integration-testing-hooks'; -import { TestShell } from './test-shell'; import { expect } from 'chai'; const setDifference = (a: T[], b: T[]) => a.filter((e) => !b.includes(e)); @@ -57,7 +56,7 @@ describe('e2e snapshot support', function () { ] = ( await Promise.all( argLists.map((args) => - TestShell.runAndGetOutputWithoutErrors({ args }) + this.startTestShell({ args }).waitForCleanOutput() ) ) ).map((output) => diff --git a/packages/e2e-tests/test/test-shell.ts b/packages/e2e-tests/test/test-shell.ts index 43a031b38..66565a1a1 100644 --- a/packages/e2e-tests/test/test-shell.ts +++ b/packages/e2e-tests/test/test-shell.ts @@ -50,7 +50,7 @@ export class TestShell { /** * Starts a test shell. * - * Beware that the caller is responsible for calling {@link TestShell.kill} (and potentially {@link TestShell.waitForExit}). + * Beware that the caller is responsible for calling {@link kill} (and potentially {@link waitForExit}). * * Consider calling the `startTestShell` function on a {@link Mocha.Context} instead, as that manages the lifetime the shell * and ensures it gets killed eventually. @@ -108,15 +108,6 @@ export class TestShell { return shell; } - static async runAndGetOutputWithoutErrors( - options: TestShellOptions - ): Promise { - const shell = this.start(options); - await shell.waitForExit(); - shell.assertNoErrors(); - return shell.output; - } - debugInformation() { return { pid: this.process.pid, @@ -232,6 +223,15 @@ export class TestShell { return this._onClose; } + /** + * Waits for the shell to exit, asserts no errors and returns the output. + */ + async waitForCleanOutput(): Promise { + await this.waitForExit(); + this.assertNoErrors(); + return this.output; + } + async waitForPromptOrExit(): Promise { return Promise.race([ this.waitForPrompt().then(() => ({ state: 'prompt' } as const)),