From 28ae70f51c64a55172a61086d39fc010b34e4711 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Thu, 12 Mar 2026 10:43:02 +0100 Subject: [PATCH 1/2] Added new test scripts for running and updating fixtures --- package.json | 7 +++-- .../src/docs/contributing/CONTRIBUTING.mdx | 2 ++ .../docs/contributing/adding-a-new-scope.md | 6 ++--- .../src/docs/contributing/tests.md | 2 ++ packages/test-harness/package.json | 12 +++++---- .../src/scripts/runNeovimTestsCI.ts | 2 ++ .../src/scripts/runTalonJsTests.ts | 5 +++- .../src/scripts/runUnitTestsOnly.ts | 26 +++++++++++++++++-- .../src/scripts/runVscodeTestsCI.ts | 2 ++ 9 files changed, 51 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index e20ccf5f74..d5ee2eb931 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "scripts": { "build": "pnpm -r build", "clean": "pnpm -r clean", - "compile": "tsc --build && pnpm -r --if-present compile:esbuild", + "compile": "tsc --build && pnpm -r compile:esbuild", "fix:meta": "pnpm run meta-updater:base && pnpm -r exec prettier --write tsconfig.json package.json", "fix:syncpack": "syncpack fix", "fix:eslint": "pnpm lint:ts --fix", @@ -27,10 +27,13 @@ "preinstall": "npx only-allow pnpm", "test-compile": "tsc --build", "test": "pnpm -r test", + "test:subset": "pnpm -r test:subset", + "test:update": "pnpm -r test:update", + "test:update:subset": "pnpm -r test:update:subset", "generate-grammar": "pnpm -r generate-grammar", "transform-recorded-tests": "./packages/common/scripts/my-ts-node.js packages/cursorless-engine/src/scripts/transformRecordedTests/index.ts", "watch": "pnpm run -w --parallel '/^watch:.*/'", - "watch:esbuild": "pnpm run -r --parallel --if-present watch:esbuild", + "watch:esbuild": "pnpm run -r --parallel watch:esbuild", "watch:tsc": "tsc --build --watch" }, "devDependencies": { diff --git a/packages/cursorless-org-docs/src/docs/contributing/CONTRIBUTING.mdx b/packages/cursorless-org-docs/src/docs/contributing/CONTRIBUTING.mdx index 86e4676526..799b436dbe 100644 --- a/packages/cursorless-org-docs/src/docs/contributing/CONTRIBUTING.mdx +++ b/packages/cursorless-org-docs/src/docs/contributing/CONTRIBUTING.mdx @@ -134,6 +134,8 @@ To run the specified subset of tests, say `"debug test subset"` (or use the "Run If you need to edit the subset of tests to run in the future, you can say `"debug edit subset"`. +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`. + ## Code formatting We use [`pre-commit`](https://pre-commit.com/) to automate autoformatting. diff --git a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-scope.md b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-scope.md index 9f5c6755ef..eb38fb861a 100644 --- a/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-scope.md +++ b/packages/cursorless-org-docs/src/docs/contributing/adding-a-new-scope.md @@ -68,9 +68,9 @@ Then add parse tree patterns for the given scope to your language's `.scm` file 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. -1. Say `"debug edit subset"` and alter the file to include just the name of your language -2. Run the `Update fixtures subset` launch configuration to update your fixtures. -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) +1. Say `"debug edit subset"` and alter the file to include just the name of your language. +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`. +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). ## 7. File a PR! diff --git a/packages/cursorless-org-docs/src/docs/contributing/tests.md b/packages/cursorless-org-docs/src/docs/contributing/tests.md index 323e64af02..24989512ec 100644 --- a/packages/cursorless-org-docs/src/docs/contributing/tests.md +++ b/packages/cursorless-org-docs/src/docs/contributing/tests.md @@ -20,6 +20,8 @@ You can get an overview of the various test contexts that exist locally by looki ## Common commands - `pnpm test` runs the default `test` script for each workspace package. In practice, this is the fast unit-oriented test pass. +- `pnpm test:update` runs the test suite in fixture-update mode across the workspace. +- `pnpm test:update:subset` runs fixture updates only for the tests selected in `packages/test-harness/testSubsetGrep.properties`. - `pnpm -F @cursorless/test-harness test:vscode` runs the VSCode test harness. - `pnpm -F @cursorless/test-harness test:neovim` runs the Neovim test harness. - `pnpm -F @cursorless/test-harness test:talonJs` runs the Talon-JS test harness. diff --git a/packages/test-harness/package.json b/packages/test-harness/package.json index 840dec35b9..e751bb91ba 100644 --- a/packages/test-harness/package.json +++ b/packages/test-harness/package.json @@ -13,11 +13,13 @@ } }, "scripts": { - "test": "env CURSORLESS_MODE=test my-ts-node src/scripts/runUnitTestsOnly.ts", - "test:subset": "env CURSORLESS_MODE=test env CURSORLESS_RUN_TEST_SUBSET=true my-ts-node src/scripts/runUnitTestsOnly.ts", - "test:vscode": "env CURSORLESS_MODE=test my-ts-node src/scripts/runVscodeTestsCI.ts", - "test:neovim": "env CURSORLESS_MODE=test my-ts-node src/scripts/runNeovimTestsCI.ts", - "test:talonJs": "env CURSORLESS_MODE=test my-ts-node src/scripts/runTalonJsTests.ts", + "test": "my-ts-node src/scripts/runUnitTestsOnly.ts", + "test:subset": "my-ts-node src/scripts/runUnitTestsOnly.ts --subset", + "test:update": "my-ts-node src/scripts/runUnitTestsOnly.ts --update", + "test:update:subset": "my-ts-node src/scripts/runUnitTestsOnly.ts --update --subset", + "test:vscode": "my-ts-node src/scripts/runVscodeTestsCI.ts", + "test:neovim": "my-ts-node src/scripts/runNeovimTestsCI.ts", + "test:talonJs": "my-ts-node src/scripts/runTalonJsTests.ts", "build:base": "esbuild --sourcemap --conditions=cursorless:bundler --bundle --external:vscode --external:./reporters/parallel-buffered --external:./worker.js --external:talon --format=cjs --platform=node", "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", "build:runner:vscode": "pnpm run build:base ./src/runners/extensionTestsVscode.ts --outfile=dist/extensionTestsVscode.cjs", diff --git a/packages/test-harness/src/scripts/runNeovimTestsCI.ts b/packages/test-harness/src/scripts/runNeovimTestsCI.ts index 51f859f8c1..e503e88a3f 100644 --- a/packages/test-harness/src/scripts/runNeovimTestsCI.ts +++ b/packages/test-harness/src/scripts/runNeovimTestsCI.ts @@ -5,5 +5,7 @@ import { launchNeovimAndRunTests } from "../launchNeovimAndRunTests"; void (async () => { + process.env.CURSORLESS_MODE = "test"; + await launchNeovimAndRunTests(); })(); diff --git a/packages/test-harness/src/scripts/runTalonJsTests.ts b/packages/test-harness/src/scripts/runTalonJsTests.ts index 4674038d69..cfaa29a12c 100644 --- a/packages/test-harness/src/scripts/runTalonJsTests.ts +++ b/packages/test-harness/src/scripts/runTalonJsTests.ts @@ -1,9 +1,12 @@ /** * Runs all Talon everywhere/JS tests. */ -import { TestType, runAllTests } from "../runAllTests"; void (async () => { + process.env.CURSORLESS_MODE = "test"; + + const { TestType, runAllTests } = await import("../runAllTests"); + try { await runAllTests(TestType.talonJs); } catch (_ex) { diff --git a/packages/test-harness/src/scripts/runUnitTestsOnly.ts b/packages/test-harness/src/scripts/runUnitTestsOnly.ts index 0df79f4109..d33b75a7f1 100644 --- a/packages/test-harness/src/scripts/runUnitTestsOnly.ts +++ b/packages/test-harness/src/scripts/runUnitTestsOnly.ts @@ -1,6 +1,28 @@ /** * Runs all tests that don't have to be run within VSCode. */ -import { TestType, runAllTests } from "../runAllTests"; -void runAllTests(TestType.unit); +const supportedArgs = new Set(["--subset", "--update"]); + +const args = new Set(process.argv.slice(2)); +const unsupportedArgs = [...args].filter((arg) => !supportedArgs.has(arg)); + +if (unsupportedArgs.length > 0) { + throw new Error(`Unsupported arguments: ${unsupportedArgs.join(", ")}`); +} + +process.env.CURSORLESS_MODE = "test"; + +if (args.has("--subset")) { + process.env.CURSORLESS_RUN_TEST_SUBSET = "true"; +} + +if (args.has("--update")) { + process.env.CURSORLESS_TEST_UPDATE_FIXTURES = "true"; +} + +void (async () => { + const { TestType, runAllTests } = await import("../runAllTests"); + + await runAllTests(TestType.unit); +})(); diff --git a/packages/test-harness/src/scripts/runVscodeTestsCI.ts b/packages/test-harness/src/scripts/runVscodeTestsCI.ts index 53142d53c6..1796f6d3ce 100644 --- a/packages/test-harness/src/scripts/runVscodeTestsCI.ts +++ b/packages/test-harness/src/scripts/runVscodeTestsCI.ts @@ -7,6 +7,8 @@ import * as path from "node:path"; import { launchVscodeAndRunTests } from "../launchVscodeAndRunTests"; void (async () => { + process.env.CURSORLESS_MODE = "test"; + const extensionTestsPath = path.resolve( getCursorlessRepoRoot(), "packages/test-harness/dist/extensionTestsVscode.cjs", From e708235b413af2061336cb4a2ada613befb1cd07 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Thu, 12 Mar 2026 10:45:30 +0100 Subject: [PATCH 2/2] cleanup --- packages/test-harness/src/scripts/runNeovimTestsCI.ts | 4 ++-- packages/test-harness/src/scripts/runTalonJsTests.ts | 4 ++-- packages/test-harness/src/scripts/runVscodeTestsCI.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/test-harness/src/scripts/runNeovimTestsCI.ts b/packages/test-harness/src/scripts/runNeovimTestsCI.ts index e503e88a3f..331d3f16c0 100644 --- a/packages/test-harness/src/scripts/runNeovimTestsCI.ts +++ b/packages/test-harness/src/scripts/runNeovimTestsCI.ts @@ -4,8 +4,8 @@ import { launchNeovimAndRunTests } from "../launchNeovimAndRunTests"; -void (async () => { - process.env.CURSORLESS_MODE = "test"; +process.env.CURSORLESS_MODE = "test"; +void (async () => { await launchNeovimAndRunTests(); })(); diff --git a/packages/test-harness/src/scripts/runTalonJsTests.ts b/packages/test-harness/src/scripts/runTalonJsTests.ts index cfaa29a12c..2fd1f4f2c8 100644 --- a/packages/test-harness/src/scripts/runTalonJsTests.ts +++ b/packages/test-harness/src/scripts/runTalonJsTests.ts @@ -2,9 +2,9 @@ * Runs all Talon everywhere/JS tests. */ -void (async () => { - process.env.CURSORLESS_MODE = "test"; +process.env.CURSORLESS_MODE = "test"; +void (async () => { const { TestType, runAllTests } = await import("../runAllTests"); try { diff --git a/packages/test-harness/src/scripts/runVscodeTestsCI.ts b/packages/test-harness/src/scripts/runVscodeTestsCI.ts index 1796f6d3ce..9439cd6b51 100644 --- a/packages/test-harness/src/scripts/runVscodeTestsCI.ts +++ b/packages/test-harness/src/scripts/runVscodeTestsCI.ts @@ -6,9 +6,9 @@ import { getCursorlessRepoRoot } from "@cursorless/node-common"; import * as path from "node:path"; import { launchVscodeAndRunTests } from "../launchVscodeAndRunTests"; -void (async () => { - process.env.CURSORLESS_MODE = "test"; +process.env.CURSORLESS_MODE = "test"; +void (async () => { const extensionTestsPath = path.resolve( getCursorlessRepoRoot(), "packages/test-harness/dist/extensionTestsVscode.cjs",