Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log fail test to file went running tests locally #2809

Merged
merged 4 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ next-env.d.ts

# test subset config
packages/test-harness/testSubsetGrep.properties
packages/test-harness/failedTests.properties


# cursorless-neovim
cursorless.nvim/node/cursorless-neovim
Expand Down
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"request": "launch",
"env": {
"CURSORLESS_MODE": "test",
"CURSORLESS_LOG_FAILED": "true",
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
},
"args": [
Expand All @@ -52,6 +53,7 @@
"env": {
"CURSORLESS_MODE": "test",
"CURSORLESS_RUN_TEST_SUBSET": "true",
"CURSORLESS_LOG_FAILED": "true",
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
},
"args": [
Expand Down Expand Up @@ -136,6 +138,7 @@
"program": "${workspaceFolder}/packages/test-harness/dist/runTalonTests.cjs",
"env": {
"CURSORLESS_MODE": "test",
"CURSORLESS_LOG_FAILED": "true",
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
},
"outFiles": ["${workspaceFolder}/**/out/**/*.js"],
Expand Down Expand Up @@ -171,6 +174,7 @@
"program": "${workspaceFolder}/packages/test-harness/dist/runTalonJsTests.cjs",
"env": {
"CURSORLESS_MODE": "test",
"CURSORLESS_LOG_FAILED": "true",
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
},
"outFiles": ["${workspaceFolder}/**/out/**/*.js"],
Expand Down
32 changes: 24 additions & 8 deletions packages/test-harness/src/runAllTests.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Mocha from "mocha";
import * as path from "node:path";
import { getCursorlessRepoRoot } from "@cursorless/node-common";
import { runTestSubset, testSubsetGrepString } from "./testSubset";
import { glob } from "glob";
import Mocha from "mocha";
import * as path from "node:path";
import {
logFailedTests,
runTestSubset,
shouldLogFailedTests,
testSubsetGrepString,
} from "./testSubset";

/**
* Type of test to run, eg unit, vscode, talon
Expand All @@ -24,7 +29,7 @@ export enum TestType {
neovim,
}

export function runAllTests(...types: TestType[]) {
export function runAllTests(...types: TestType[]): Promise<void> {
return runTestsInDir(
path.join(getCursorlessRepoRoot(), "packages"),
(files) =>
Expand Down Expand Up @@ -68,14 +73,25 @@ async function runTestsInDir(

try {
// Run the mocha test
await new Promise<void>((c, e) => {
mocha.run((failures) => {
await new Promise<void>((resolve, reject) => {
const failedTests: string[] = [];

const runner = mocha.run((failures) => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
if (shouldLogFailedTests()) {
logFailedTests(failedTests);
}
reject(`${failures} tests failed.`);
} else {
c();
resolve();
}
});

if (shouldLogFailedTests()) {
runner.on("fail", (test) => {
failedTests.push(test.fullTitle());
});
}
phillco marked this conversation as resolved.
Show resolved Hide resolved
});
} catch (err) {
console.error(err);
Expand Down
22 changes: 22 additions & 0 deletions packages/test-harness/src/testSubset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ export function testSubsetFilePath() {
);
}

function testFailedFilePath() {
return path.join(
getCursorlessRepoRoot(),
"packages",
"test-harness",
"failedTests.properties",
);
}

export function logFailedTests(testNames: string[]) {
const lines = [`${testNames.length} failed tests`, "", ...testNames];
fs.writeFileSync(testFailedFilePath(), lines.join("\n"));
}

/**
* Determine whether we should run just the subset of the tests specified by
* {@link TEST_SUBSET_GREP_STRING}.
Expand All @@ -37,3 +51,11 @@ export function testSubsetFilePath() {
export function runTestSubset() {
return process.env.CURSORLESS_RUN_TEST_SUBSET === "true";
}

/**
* Determine whether we should log the failed tests.
* @returns `true` if we should log the failed tests
phillco marked this conversation as resolved.
Show resolved Hide resolved
*/
export function shouldLogFailedTests() {
return process.env.CURSORLESS_LOG_FAILED === "true";
}
Loading