Skip to content

Commit 0033c5c

Browse files
Added new test scripts for running and updating fixtures (#3213)
1 parent afab431 commit 0033c5c

9 files changed

Lines changed: 51 additions & 13 deletions

File tree

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"scripts": {
1313
"build": "pnpm -r build",
1414
"clean": "pnpm -r clean",
15-
"compile": "tsc --build && pnpm -r --if-present compile:esbuild",
15+
"compile": "tsc --build && pnpm -r compile:esbuild",
1616
"fix:meta": "pnpm run meta-updater:base && pnpm -r exec prettier --write tsconfig.json package.json",
1717
"fix:syncpack": "syncpack fix",
1818
"fix:eslint": "pnpm lint:ts --fix",
@@ -27,10 +27,13 @@
2727
"preinstall": "npx only-allow pnpm",
2828
"test-compile": "tsc --build",
2929
"test": "pnpm -r test",
30+
"test:subset": "pnpm -r test:subset",
31+
"test:update": "pnpm -r test:update",
32+
"test:update:subset": "pnpm -r test:update:subset",
3033
"generate-grammar": "pnpm -r generate-grammar",
3134
"transform-recorded-tests": "./packages/common/scripts/my-ts-node.js packages/cursorless-engine/src/scripts/transformRecordedTests/index.ts",
3235
"watch": "pnpm run -w --parallel '/^watch:.*/'",
33-
"watch:esbuild": "pnpm run -r --parallel --if-present watch:esbuild",
36+
"watch:esbuild": "pnpm run -r --parallel watch:esbuild",
3437
"watch:tsc": "tsc --build --watch"
3538
},
3639
"devDependencies": {

packages/cursorless-org-docs/src/docs/contributing/CONTRIBUTING.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ To run the specified subset of tests, say `"debug test subset"` (or use the "Run
134134

135135
If you need to edit the subset of tests to run in the future, you can say `"debug edit subset"`.
136136

137+
To update fixtures for the specified subset of tests from the command line, run `pnpm test:update:subset` from the repository root. To update fixtures for the full test suite instead, run `pnpm test:update`.
138+
137139
## Code formatting
138140

139141
We use [`pre-commit`](https://pre-commit.com/) to automate autoformatting.

packages/cursorless-org-docs/src/docs/contributing/adding-a-new-scope.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ Then add parse tree patterns for the given scope to your language's `.scm` file
6868

6969
The tests generated in step 4 only include the code example. Now that you've told Cursorless how to find the scope, we can automatically update the test cases to indicate where the scope should appear in your code examples.
7070

71-
1. Say `"debug edit subset"` and alter the file to include just the name of your language
72-
2. Run the `Update fixtures subset` launch configuration to update your fixtures.
73-
3. Check that the fixtures now look as expected, and no other tests for your language have been altered. The VSCode source control side bar is useful for this purpose. For help understanding the scope test format, see the [scope test format docs](./scope-test-format.md)
71+
1. Say `"debug edit subset"` and alter the file to include just the name of your language.
72+
2. Run `pnpm test:update:subset` from the repository root to update the fixtures for the selected subset of tests. If you want to update all fixtures instead, run `pnpm test:update`.
73+
3. Check that the fixtures now look as expected, and no other tests for your language have been altered. The VSCode source control side bar is useful for this purpose. For help understanding the scope test format, see the [scope test format docs](./scope-test-format.md).
7474

7575
## 7. File a PR!
7676

packages/cursorless-org-docs/src/docs/contributing/tests.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ You can get an overview of the various test contexts that exist locally by looki
2020
## Common commands
2121

2222
- `pnpm test` runs the default `test` script for each workspace package. In practice, this is the fast unit-oriented test pass.
23+
- `pnpm test:update` runs the test suite in fixture-update mode across the workspace.
24+
- `pnpm test:update:subset` runs fixture updates only for the tests selected in `packages/test-harness/testSubsetGrep.properties`.
2325
- `pnpm -F @cursorless/test-harness test:vscode` runs the VSCode test harness.
2426
- `pnpm -F @cursorless/test-harness test:neovim` runs the Neovim test harness.
2527
- `pnpm -F @cursorless/test-harness test:talonJs` runs the Talon-JS test harness.

packages/test-harness/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
}
1414
},
1515
"scripts": {
16-
"test": "env CURSORLESS_MODE=test my-ts-node src/scripts/runUnitTestsOnly.ts",
17-
"test:subset": "env CURSORLESS_MODE=test env CURSORLESS_RUN_TEST_SUBSET=true my-ts-node src/scripts/runUnitTestsOnly.ts",
18-
"test:vscode": "env CURSORLESS_MODE=test my-ts-node src/scripts/runVscodeTestsCI.ts",
19-
"test:neovim": "env CURSORLESS_MODE=test my-ts-node src/scripts/runNeovimTestsCI.ts",
20-
"test:talonJs": "env CURSORLESS_MODE=test my-ts-node src/scripts/runTalonJsTests.ts",
16+
"test": "my-ts-node src/scripts/runUnitTestsOnly.ts",
17+
"test:subset": "my-ts-node src/scripts/runUnitTestsOnly.ts --subset",
18+
"test:update": "my-ts-node src/scripts/runUnitTestsOnly.ts --update",
19+
"test:update:subset": "my-ts-node src/scripts/runUnitTestsOnly.ts --update --subset",
20+
"test:vscode": "my-ts-node src/scripts/runVscodeTestsCI.ts",
21+
"test:neovim": "my-ts-node src/scripts/runNeovimTestsCI.ts",
22+
"test:talonJs": "my-ts-node src/scripts/runTalonJsTests.ts",
2123
"build:base": "esbuild --sourcemap --conditions=cursorless:bundler --bundle --external:vscode --external:./reporters/parallel-buffered --external:./worker.js --external:talon --format=cjs --platform=node",
2224
"build": "pnpm run build:runner:vscode && pnpm run build:runner:neovim && pnpm run build:tests && pnpm run build:unit && pnpm run build:talon && pnpm run build:talonJs",
2325
"build:runner:vscode": "pnpm run build:base ./src/runners/extensionTestsVscode.ts --outfile=dist/extensionTestsVscode.cjs",

packages/test-harness/src/scripts/runNeovimTestsCI.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import { launchNeovimAndRunTests } from "../launchNeovimAndRunTests";
66

7+
process.env.CURSORLESS_MODE = "test";
8+
79
void (async () => {
810
await launchNeovimAndRunTests();
911
})();

packages/test-harness/src/scripts/runTalonJsTests.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
/**
22
* Runs all Talon everywhere/JS tests.
33
*/
4-
import { TestType, runAllTests } from "../runAllTests";
4+
5+
process.env.CURSORLESS_MODE = "test";
56

67
void (async () => {
8+
const { TestType, runAllTests } = await import("../runAllTests");
9+
710
try {
811
await runAllTests(TestType.talonJs);
912
} catch (_ex) {
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
/**
22
* Runs all tests that don't have to be run within VSCode.
33
*/
4-
import { TestType, runAllTests } from "../runAllTests";
54

6-
void runAllTests(TestType.unit);
5+
const supportedArgs = new Set(["--subset", "--update"]);
6+
7+
const args = new Set(process.argv.slice(2));
8+
const unsupportedArgs = [...args].filter((arg) => !supportedArgs.has(arg));
9+
10+
if (unsupportedArgs.length > 0) {
11+
throw new Error(`Unsupported arguments: ${unsupportedArgs.join(", ")}`);
12+
}
13+
14+
process.env.CURSORLESS_MODE = "test";
15+
16+
if (args.has("--subset")) {
17+
process.env.CURSORLESS_RUN_TEST_SUBSET = "true";
18+
}
19+
20+
if (args.has("--update")) {
21+
process.env.CURSORLESS_TEST_UPDATE_FIXTURES = "true";
22+
}
23+
24+
void (async () => {
25+
const { TestType, runAllTests } = await import("../runAllTests");
26+
27+
await runAllTests(TestType.unit);
28+
})();

packages/test-harness/src/scripts/runVscodeTestsCI.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { getCursorlessRepoRoot } from "@cursorless/node-common";
66
import * as path from "node:path";
77
import { launchVscodeAndRunTests } from "../launchVscodeAndRunTests";
88

9+
process.env.CURSORLESS_MODE = "test";
10+
911
void (async () => {
1012
const extensionTestsPath = path.resolve(
1113
getCursorlessRepoRoot(),

0 commit comments

Comments
 (0)