Skip to content

Commit ff31585

Browse files
Log fail test to file went running tests locally (#2809)
The issue suggested showing a pop-up, but this wasn't optimal. It was either blocking the tests from terminating or it closed immediately by itself. I also don't want to clobber the clipboard all the time. Let's log to a file because it seems like the best of the options. Fixes #2805 --------- Co-authored-by: Phil Cohen <[email protected]>
1 parent 2d9f784 commit ff31585

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ next-env.d.ts
4545

4646
# test subset config
4747
packages/test-harness/testSubsetGrep.properties
48+
packages/test-harness/failedTests.properties
49+
4850

4951
# cursorless-neovim
5052
cursorless.nvim/node/cursorless-neovim

.vscode/launch.json

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"request": "launch",
3232
"env": {
3333
"CURSORLESS_MODE": "test",
34+
"CURSORLESS_LOG_FAILED": "true",
3435
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
3536
},
3637
"args": [
@@ -52,6 +53,7 @@
5253
"env": {
5354
"CURSORLESS_MODE": "test",
5455
"CURSORLESS_RUN_TEST_SUBSET": "true",
56+
"CURSORLESS_LOG_FAILED": "true",
5557
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
5658
},
5759
"args": [
@@ -136,6 +138,7 @@
136138
"program": "${workspaceFolder}/packages/test-harness/dist/runTalonTests.cjs",
137139
"env": {
138140
"CURSORLESS_MODE": "test",
141+
"CURSORLESS_LOG_FAILED": "true",
139142
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
140143
},
141144
"outFiles": ["${workspaceFolder}/**/out/**/*.js"],
@@ -171,6 +174,7 @@
171174
"program": "${workspaceFolder}/packages/test-harness/dist/runTalonJsTests.cjs",
172175
"env": {
173176
"CURSORLESS_MODE": "test",
177+
"CURSORLESS_LOG_FAILED": "true",
174178
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
175179
},
176180
"outFiles": ["${workspaceFolder}/**/out/**/*.js"],

packages/test-harness/src/runAllTests.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import Mocha from "mocha";
2-
import * as path from "node:path";
31
import { getCursorlessRepoRoot } from "@cursorless/node-common";
4-
import { runTestSubset, testSubsetGrepString } from "./testSubset";
52
import { glob } from "glob";
3+
import Mocha from "mocha";
4+
import * as path from "node:path";
5+
import {
6+
logFailedTests,
7+
runTestSubset,
8+
shouldLogFailedTests,
9+
testSubsetGrepString,
10+
} from "./testSubset";
611

712
/**
813
* Type of test to run, eg unit, vscode, talon
@@ -24,7 +29,7 @@ export enum TestType {
2429
neovim,
2530
}
2631

27-
export function runAllTests(...types: TestType[]) {
32+
export function runAllTests(...types: TestType[]): Promise<void> {
2833
return runTestsInDir(
2934
path.join(getCursorlessRepoRoot(), "packages"),
3035
(files) =>
@@ -68,14 +73,23 @@ async function runTestsInDir(
6873

6974
try {
7075
// Run the mocha test
71-
await new Promise<void>((c, e) => {
72-
mocha.run((failures) => {
76+
await new Promise<void>((resolve, reject) => {
77+
const failedTests: string[] = [];
78+
79+
const runner = mocha.run((failures) => {
7380
if (failures > 0) {
74-
e(new Error(`${failures} tests failed.`));
81+
if (shouldLogFailedTests()) {
82+
logFailedTests(failedTests);
83+
}
84+
reject(`${failures} tests failed.`);
7585
} else {
76-
c();
86+
resolve();
7787
}
7888
});
89+
90+
if (shouldLogFailedTests()) {
91+
runner.on("fail", (test) => failedTests.push(test.fullTitle()));
92+
}
7993
});
8094
} catch (err) {
8195
console.error(err);

packages/test-harness/src/testSubset.ts

+22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ export function testSubsetFilePath() {
2929
);
3030
}
3131

32+
function testFailedFilePath() {
33+
return path.join(
34+
getCursorlessRepoRoot(),
35+
"packages",
36+
"test-harness",
37+
"failedTests.properties",
38+
);
39+
}
40+
41+
export function logFailedTests(testNames: string[]) {
42+
const lines = [`${testNames.length} failed tests`, "", ...testNames];
43+
fs.writeFileSync(testFailedFilePath(), lines.join("\n"));
44+
}
45+
3246
/**
3347
* Determine whether we should run just the subset of the tests specified by
3448
* {@link TEST_SUBSET_GREP_STRING}.
@@ -37,3 +51,11 @@ export function testSubsetFilePath() {
3751
export function runTestSubset() {
3852
return process.env.CURSORLESS_RUN_TEST_SUBSET === "true";
3953
}
54+
55+
/**
56+
* Determine whether we should log the failed tests to a file. This makes it easier to put them in `testSubsetGrep.properties` for faster iterating.
57+
* @returns `true` if we should log failed tests to `packages/test-harness/failedTests.properties`
58+
*/
59+
export function shouldLogFailedTests() {
60+
return process.env.CURSORLESS_LOG_FAILED === "true";
61+
}

0 commit comments

Comments
 (0)