Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/test-reader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ import type { Config } from "../config";
import type { Test } from "./test-object";
import type { ReadTestsOpts } from "../testplane";

class SingleTestModeError extends Error {
constructor(modeName: string, testsCount: number, browsersToRun: string[]) {
const message =
`In ${modeName} only 1 test in 1 browser should be run, but found ${testsCount} tests` +
`${testsCount === 0 ? ". " : ` that run in ${browsersToRun.join(", ")} browsers. `}` +
`Try to specify cli-options: "--grep" and "--browser" or use "testplane.only.in" in the test file.`;

super(message);
this.name = "SingleTestModeError";
// Удаляем стектрейс про EPIPE, который не нужен пользователю
delete this.stack;
Comment on lines +21 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By deleting "stack" property you are producing invalid Error object:

Specs: https://nodejs.org/api/errors.html#errorstack

If you want to override stack, make it comply node.js stacktraces:

The first line is formatted as : , and is followed by a series of stack frames (each line beginning with "at ").

So, we could overwrite it with SingleTestModeError: ${message}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but in that case the message will be duplicated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't lead to an error, its fine, i guess

}
}

export type TestReaderOpts = { paths: string[] } & Partial<ReadTestsOpts>;

export class TestReader extends EventEmitter {
Expand Down Expand Up @@ -68,11 +82,7 @@ function validateTests(testsByBro: Record<string, Test[]>, options: TestReaderOp
const browsersToRun = _.uniq(testsToRun.map(test => test.browserId));

if (testsToRun.length !== 1) {
throw new Error(
`In ${mode.name} only 1 test in 1 browser should be run, but found ${testsToRun.length} tests` +
`${testsToRun.length === 0 ? ". " : ` that run in ${browsersToRun.join(", ")} browsers. `}` +
`Try to specify cli-options: "--grep" and "--browser" or use "testplane.only.in" in the test file.`,
);
throw new SingleTestModeError(mode.name, testsToRun.length, browsersToRun);
}
}

Expand Down
Loading