Skip to content

Commit

Permalink
Refactored "runAndGetOutputWithoutErrors" into "waitForCleanOutout"
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Sep 26, 2024
1 parent 0f92ba5 commit bb88c9e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
3 changes: 1 addition & 2 deletions packages/e2e-tests/test/e2e-snapshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
skipIfApiStrict,
startSharedTestServer,
} from '../../../testing/integration-testing-hooks';
import { TestShell } from './test-shell';
import { expect } from 'chai';

const setDifference = <T>(a: T[], b: T[]) => a.filter((e) => !b.includes(e));
Expand Down Expand Up @@ -57,7 +56,7 @@ describe('e2e snapshot support', function () {
] = (
await Promise.all(
argLists.map((args) =>
TestShell.runAndGetOutputWithoutErrors({ args })
this.startTestShell({ args }).waitForCleanOutput()
)
)
).map((output) =>
Expand Down
20 changes: 10 additions & 10 deletions packages/e2e-tests/test/test-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -108,15 +108,6 @@ export class TestShell {
return shell;
}

static async runAndGetOutputWithoutErrors(
options: TestShellOptions
): Promise<string> {
const shell = this.start(options);
await shell.waitForExit();
shell.assertNoErrors();
return shell.output;
}

debugInformation() {
return {
pid: this.process.pid,
Expand Down Expand Up @@ -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<string> {
await this.waitForExit();
this.assertNoErrors();
return this.output;
}

async waitForPromptOrExit(): Promise<TestShellStartupResult> {
return Promise.race([
this.waitForPrompt().then(() => ({ state: 'prompt' } as const)),
Expand Down

0 comments on commit bb88c9e

Please sign in to comment.