Skip to content

Commit 5e548f7

Browse files
authored
fix: exit successfully if last failed only is on and there are no failed tests (#1150)
* fix: exit successfully if last failed only is on and there are no failed tests * fix: do not show keep-browser param in error message if no tests were found
1 parent 2c17240 commit 5e548f7

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

src/test-reader/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ export class TestReader extends EventEmitter {
4949
parser.parse(files, { browserId, config: this.#config.forBrowser(browserId), grep }),
5050
);
5151

52-
validateTests(testsByBro, options);
52+
validateTests(testsByBro, options, this.#config);
5353

5454
return testsByBro;
5555
}
5656
}
5757

58-
function validateTests(testsByBro: Record<string, Test[]>, options: TestReaderOpts): void {
58+
function validateTests(testsByBro: Record<string, Test[]>, options: TestReaderOpts, config: Config): void {
5959
const tests = _.flatten(Object.values(testsByBro));
6060

6161
const singleTestModes = [
@@ -76,11 +76,11 @@ function validateTests(testsByBro: Record<string, Test[]>, options: TestReaderOp
7676
}
7777
}
7878

79-
if (!_.isEmpty(tests) && tests.some(test => !test.silentSkip)) {
79+
if ((!_.isEmpty(tests) && tests.some(test => !test.silentSkip)) || (_.isEmpty(tests) && config.lastFailed.only)) {
8080
return;
8181
}
8282

83-
const stringifiedOpts = convertOptions(_.omit(options, "replMode"));
83+
const stringifiedOpts = convertOptions(_.omit(options, "replMode", "keepBrowserMode"));
8484
if (_.isEmpty(stringifiedOpts)) {
8585
throw new Error(`There are no tests found. Try to specify [${Object.keys(options).join(", ")}] options`);
8686
} else {

src/test-reader/test-parser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ export class TestParser extends EventEmitter {
144144
treeBuilder.addTestFilter((test: Test) => grep.test(test.fullTitle()));
145145
}
146146

147-
if (config.lastFailed && config.lastFailed.only && this.#failedTests.size) {
147+
if (config.lastFailed?.only) {
148+
if (!this.#failedTests.size) {
149+
return [];
150+
}
151+
148152
treeBuilder.addTestFilter(test => {
149153
return this.#failedTests.has(
150154
getFailedTestId({

test/src/test-reader/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,21 @@ describe("test-reader", () => {
287287
assert.equal(e.message, "There are no tests found by the specified options:\n" + "- grep: foo\n");
288288
}
289289
});
290+
291+
it("should resolve successfully when last failed mode is enabled", async () => {
292+
const config = makeConfigStub({
293+
browsers: ["bro"],
294+
lastFailed: {
295+
only: true,
296+
input: "last-failed.json",
297+
output: "last-failed-out.json",
298+
},
299+
});
300+
301+
const testsByBrowser = await readTests_({ config });
302+
303+
assert.deepEqual(testsByBrowser, { bro: [] });
304+
});
290305
});
291306

292307
describe("repl mode", () => {

0 commit comments

Comments
 (0)