Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
{
"label": "Build extension and tests",
"dependsOn": ["Build extension", "Build test harness"],
"dependsOn": ["Build extension", "Build test runner"],
"group": "build"
},
{
Expand All @@ -29,7 +29,7 @@

// Helper tasks
{
"label": "Build test harness",
"label": "Build test runner",
"type": "npm",
"script": "build",
"path": "packages/test-runner",
Expand Down
4 changes: 2 additions & 2 deletions cursorless.nvim/lua/cursorless/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ local function register_functions()
vim.fn["remote#host#RegisterPlugin"]("node", path .. "/node/test-runner/", {
{
type = "function",
name = "TestHarnessRun",
name = "TestRunnerRun",
sync = false,
opts = vim.empty_dict(),
},
Expand All @@ -55,7 +55,7 @@ local function load_extensions()
if os.getenv("CURSORLESS_MODE") == "test" then
-- make sure cursorless is loaded before starting the tests
vim.uv.sleep(1000)
vim.fn.TestHarnessRun()
vim.fn.TestRunnerRun()
else
vim.fn.CommandServerLoadExtension()
end
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"build": "pnpm -r build",
"clean": "pnpm -r clean",
"typecheck": "pnpm -r typecheck",
"fix:prettier": "prettier --write --list-different .",
"lint:meta": "pnpm run meta-updater --test",
"lint:syncpack": "syncpack lint",
"lint:ts": "eslint packages",
"lint:prettier": "prettier --check .",
"lint:style": "stylelint '**/*.{css,scss}' --ignore-path .gitignore",
"lint:fmt": "prettier --check .",
"lint": "pnpm run typecheck && pnpm run lint:meta && pnpm run lint:syncpack && pnpm run lint:ts && pnpm run lint:style",
"fix:meta": "pnpm run meta-updater && pnpm -r exec prettier --write tsconfig.json package.json",
"fix:syncpack": "syncpack fix",
"fix:eslint": "pnpm lint:ts --fix",
"fix:style": "stylelint '**/*.{css,scss}' --ignore-path .gitignore --fix",
"fix:fmt": "prettier --write --list-different .",
"init-vscode-sandbox": "pnpm -F @cursorless/app-vscode init-launch-sandbox",
"meta-updater": "env NODE_OPTIONS=--import=tsx meta-updater",
"preinstall": "npx only-allow pnpm",
Expand Down
16 changes: 8 additions & 8 deletions packages/app-neovim/scripts/populate-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fi
echo "CURSORLESS_REPO_ROOT: $CURSORLESS_REPO_ROOT"
cursorless_nvim_dir="$CURSORLESS_REPO_ROOT/cursorless.nvim"
cursorless_neovim_node_in_dir="$CURSORLESS_REPO_ROOT/packages/app-neovim"
test_harness_node_in_dir="$CURSORLESS_REPO_ROOT/packages/test-runner"
test_runner_node_in_dir="$CURSORLESS_REPO_ROOT/packages/test-runner"

if [[ "${CI:-x}" == "true" ]]; then
# If running in CI, only copy the necessary files for testing and release
Expand All @@ -25,10 +25,10 @@ if [[ "${CI:-x}" == "true" ]]; then
cp "$cursorless_neovim_node_in_dir/out/index.cjs" "$cursorless_neovim_node_out_dir/out"

# Populate test-runner
test_harness_node_out_dir="$cursorless_nvim_dist_dir/node/test-runner"
mkdir -p "$test_harness_node_out_dir/out"
cp "$test_harness_node_in_dir/package.json" "$test_harness_node_out_dir"
cp "$test_harness_node_in_dir/out/extensionTestsNeovim.cjs" "$test_harness_node_out_dir/out"
test_runner_node_out_dir="$cursorless_nvim_dist_dir/node/test-runner"
mkdir -p "$test_runner_node_out_dir/out"
cp "$test_runner_node_in_dir/package.json" "$test_runner_node_out_dir"
cp "$test_runner_node_in_dir/out/extensionTestsNeovim.cjs" "$test_runner_node_out_dir/out"
else
# Symlink so we inherit the .map files as well, but only if uname doesn't
# start with "MINGW" (Windows Git Bash)
Expand All @@ -43,8 +43,8 @@ else
rm -rf "$cursorless_neovim_node_out_dir"
ln -s "$cursorless_neovim_node_in_dir" "$cursorless_neovim_node_out_dir"

test_harness_node_out_dir="$cursorless_nvim_dir/node/test-runner"
rm -rf "$test_harness_node_out_dir"
ln -s "$test_harness_node_in_dir" "$test_harness_node_out_dir"
test_runner_node_out_dir="$cursorless_nvim_dir/node/test-runner"
rm -rf "$test_runner_node_out_dir"
ln -s "$test_runner_node_in_dir" "$test_runner_node_out_dir"
fi
fi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@cursorless/app-talon",
"name": "@cursorless/app-talonjs",
"version": "1.0.0",
"description": "cursorless in talon js",
"license": "MIT",
Expand All @@ -18,6 +18,6 @@
},
"dependencies": {
"@cursorless/lib-common": "workspace:*",
"@cursorless/lib-talon-core": "workspace:*"
"@cursorless/lib-talonjs-core": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RunMode } from "@cursorless/lib-common";
import { activate as activateCore } from "@cursorless/lib-talon-core";
import { activate as activateCore } from "@cursorless/lib-talonjs-core";
import * as talon from "talon";

export async function activate(runMode: RunMode): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module "talon" {
TalonActions,
TalonContextConstructor,
TalonSettings,
} from "@cursorless/lib-talon-core";
} from "@cursorless/lib-talonjs-core";

export const actions: TalonActions;
export const settings: TalonSettings;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/app-vscode/src/createVscodeIde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function createVscodeIde(context: ExtensionContext) {

await hats.init();

// FIXME: Inject this from test harness. Would need to arrange to delay
// FIXME: Inject this from test runner. Would need to arrange to delay
// extension initialization, probably by returning a function from extension
// init that has parameters consisting of test configuration, and have that
// function do the actual initialization.
Expand Down
8 changes: 4 additions & 4 deletions packages/app-vscode/src/keyboard/KeyboardCommandsModal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CompositeKeyMap } from "@cursorless/lib-common";
import type { VscodeApi } from "@cursorless/lib-vscode-common";
import { pick, sortedUniq, toPairs } from "lodash-es";
import { Grammar, Parser } from "nearley";
import nearley from "nearley";
import * as vscode from "vscode";
import { KeyboardCommandHandler } from "./KeyboardCommandHandler";
import { KeyboardCommandsModalLayer } from "./KeyboardCommandsModalLayer";
Expand Down Expand Up @@ -33,10 +33,10 @@ export default class KeyboardCommandsModal {
string[],
KeyboardCommandsModalLayer<KeyDescriptor>
>((keys) => keys);
private parser!: Parser;
private parser!: nearley.Parser;
private sections!: TokenTypeKeyMapMap;
private keyboardCommandHandler: KeyboardCommandHandler;
private compiledGrammar = Grammar.fromCompiled(grammar);
private compiledGrammar = nearley.Grammar.fromCompiled(grammar);
private keyboardConfig: KeyboardConfig;

constructor(
Expand Down Expand Up @@ -78,7 +78,7 @@ export default class KeyboardCommandsModal {
}

private resetParser() {
this.parser = new Parser(this.compiledGrammar);
this.parser = new nearley.Parser(this.compiledGrammar);
this.computeLayer();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "assert";
import { Grammar, Parser } from "nearley";
import nearley from "nearley";
import type { KeyDescriptor } from "../TokenTypeHelpers";
import grammar from "./generated/grammar";
import type { AcceptableTokenType } from "./getAcceptableTokenTypes";
Expand Down Expand Up @@ -132,9 +132,9 @@ const testCases: TestCase[] = [
];

suite("keyboard.getAcceptableTokenTypes", () => {
let parser: Parser;
let parser: nearley.Parser;
setup(() => {
parser = new Parser(Grammar.fromCompiled(grammar));
parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
});

testCases.forEach(({ tokens, expected }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { State } from "nearley";
import type nearley from "nearley";
import { isEqual, times } from "lodash-es";
import type { CommandRulePostProcessor } from "./CommandRulePostProcessor";
Expand Down Expand Up @@ -95,8 +94,8 @@ export const NEXT = Symbol("next");
function computeRootStatePartialArgs(
state: nearley.State,
lastSymbol: any = NEXT,
visitCounts = new DefaultMap<State, number>(() => 0),
roots: { state: State; partialArg: any }[] = [],
visitCounts = new DefaultMap<nearley.State, number>(() => 0),
roots: { state: nearley.State; partialArg: any }[] = [],
) {
const visitCount = visitCounts.get(state);
if (visitCount > MAX_VISITS) {
Expand Down
6 changes: 3 additions & 3 deletions packages/app-vscode/src/keyboard/grammar/grammar.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Parser, Grammar } from "nearley";
import nearley from "nearley";
import grammar from "./generated/grammar";
import assert from "assert";
import type { KeyDescriptor } from "../TokenTypeHelpers";
Expand Down Expand Up @@ -179,9 +179,9 @@ const testCases: TestCase[] = [
];

suite("keyboard grammar", () => {
let parser: Parser;
let parser: nearley.Parser;
setup(() => {
parser = new Parser(Grammar.fromCompiled(grammar));
parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar));
});

testCases.forEach(({ tokens, expected }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-vscode/src/keyboard/grammar/keyboardLexer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Lexer } from "nearley";
import type nearley from "nearley";
import type { TokenTypeKeyMapMap } from "../TokenTypeHelpers";

interface LexerState {
Expand All @@ -17,7 +17,7 @@ interface Token {
* method that the parser will then use to transform the token into the actual
* value that will be used when constructing rule outputs.
*/
class KeyboardLexer implements Lexer {
class KeyboardLexer implements nearley.Lexer {
buffer: any[] = [];
bufferIndex = 0;
index = 0;
Expand Down
4 changes: 2 additions & 2 deletions packages/app-vscode/src/vscodeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { commands, env, window, workspace } from "vscode";

/**
* A very thin wrapper around the VSCode API that allows us to mock it for
* testing. This is necessary because the test harness gets bundled separately
* testing. This is necessary because the test runner gets bundled separately
* from the extension code, so if we just import the VSCode API directly from
* the extension code, and from the test harness, we'll end up with two copies
* the extension code, and from the test runner, we'll end up with two copies
* of the VSCode API, so the mocks won't work.
*/
export const vscodeApi: VscodeApi = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ launch.json -> .vscode/tasks.json -> nvim -u init.lua

init.lua
-> CursorlessLoadExtension()
-> TestHarnessRun() -> run() -> runAllTests() -> Mocha -> packages/test-neovim-e2e/src/suite/recorded.neovim.test.ts
-> TestRunnerRun() -> run() -> runAllTests() -> Mocha -> packages/test-neovim-e2e/src/suite/recorded.neovim.test.ts
```

And here is the call path when running Neovim tests on CI:
Expand All @@ -26,7 +26,7 @@ launchNeovimAndRunTests.ts

packages/test-runner/src/config/init.lua
-> CursorlessLoadExtension()
-> TestHarnessRun() -> run() -> runAllTests() -> Mocha + packages/test-neovim-e2e/src/suite/recorded.neovim.test.ts
-> TestRunnerRun() -> run() -> runAllTests() -> Mocha + packages/test-neovim-e2e/src/suite/recorded.neovim.test.ts
```

### Running Neovim tests locally
Expand Down Expand Up @@ -56,7 +56,7 @@ This effectively runs a series of dependency tasks from `.vscode/tasks.json`:
"Neovim: ESBuild",
"Neovim: Populate dist",
"TSBuild",
"Build test harness",
"Build test runner",
"Neovim: Show logs"
],
"group": "build"
Expand Down Expand Up @@ -118,7 +118,7 @@ local function setup(user_config)
load_extensions()
```

First, it calls `register_functions()` to expose the node functions `CursorlessLoadExtension()` and `TestHarnessRun()` into the vim namespace. A side effect is that the `nvim` process loads the `node` process:
First, it calls `register_functions()` to expose the node functions `CursorlessLoadExtension()` and `TestRunnerRun()` into the vim namespace. A side effect is that the `nvim` process loads the `node` process:

```lua
local function register_functions()
Expand All @@ -138,14 +138,14 @@ local function register_functions()
vim.fn["remote#host#RegisterPlugin"]("node", path .. "/node/test-runner/", {
{
type = "function",
name = "TestHarnessRun",
name = "TestRunnerRun",
sync = false,
opts = vim.empty_dict(),
},
})
```

Then, it calls `load_extensions()`. This calls the vim functions in order to load the Cursorless neovim plugin (`CursorlessLoadExtension()`) and start the tests (`TestHarnessRun()`) which ends up calling the previously registered node functions.
Then, it calls `load_extensions()`. This calls the vim functions in order to load the Cursorless neovim plugin (`CursorlessLoadExtension()`) and start the tests (`TestRunnerRun()`) which ends up calling the previously registered node functions.

```lua
local function load_extensions()
Expand All @@ -154,20 +154,20 @@ local function load_extensions()
if os.getenv("CURSORLESS_MODE") == "test" then
-- make sure cursorless is loaded before starting the tests
vim.uv.sleep(1000)
vim.fn.TestHarnessRun()
vim.fn.TestRunnerRun()
```

However, because `nvim` was started with `"NVIM_NODE_HOST_DEBUG": "1"`, when `node` is spawned, `node` will hang and wait for a debugger to attach (`--inspect-brk`). Consequently, `nvim` won't finish loading yet (i.e. it won't finish loading `init.lua`).

This is handy because it allows VSCode to finish all the tasks required for building the Cursorless neovim package (`app-neovim`, exposed to Neovim under `node/cursorless-neovim`) and the test runner package (`test-runner`, exposed under `node/test-runner`), which will finally trigger VSCode to attach to the `node` process.

When VSCode attaches to the `node` process, `CursorlessLoadExtension()` is called to load the Cursorless neovim plugin and `TestHarnessRun()` is called to start the tests.
When VSCode attaches to the `node` process, `CursorlessLoadExtension()` is called to load the Cursorless neovim plugin and `TestRunnerRun()` is called to start the tests.

This ends up calling `TestHarnessRun()` from `packages/test-runner/src/index.ts` which calls `run()`:
This ends up calling `TestRunnerRun()` from `packages/test-runner/src/index.ts` which calls `run()`:

```ts
export default function entry(plugin: NvimPlugin) {
plugin.registerFunction("TestHarnessRun", () => run(plugin), {
plugin.registerFunction("TestRunnerRun", () => run(plugin), {
sync: false,
});
}
Expand Down Expand Up @@ -267,7 +267,7 @@ vim.opt.runtimepath:append(repo_root .. "/dist/cursorless.nvim")
require("cursorless").setup()
```

This ends up calling `setup()` from `dist/cursorless.nvim/lua/cursorless/init.lua`, which ends up triggering `TestHarnessRun()` and finally the recorded tests from `recorded.neovim.test.ts` using the Mocha API.
This ends up calling `setup()` from `dist/cursorless.nvim/lua/cursorless/init.lua`, which ends up triggering `TestRunnerRun()` and finally the recorded tests from `recorded.neovim.test.ts` using the Mocha API.

NOTE: Because `NVIM_NODE_HOST_DEBUG` is not set on CI, `nvim` loads entirely right away and tests are executed.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Examples include:
- `@cursorless/app-neovim`
- `@cursorless/app-web`
- `@cursorless/app-web-docs`
- `@cursorless/app-talon`
- `@cursorless/app-talonjs`

## Script meanings

Expand Down
6 changes: 3 additions & 3 deletions packages/app-web-docs/src/docs/contributing/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ You can get an overview of the various test contexts that exist locally by looki
- `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-runner/testSubsetGrep.properties`.
- `pnpm -F @cursorless/test-runner test:vscode` runs the VSCode test harness.
- `pnpm -F @cursorless/test-runner test:neovim` runs the Neovim test harness.
- `pnpm -F @cursorless/test-runner test:talonJs` runs the Talon-JS test harness.
- `pnpm -F @cursorless/test-runner test:vscode` runs the VSCode test runner.
- `pnpm -F @cursorless/test-runner test:neovim` runs the Neovim test runner.
- `pnpm -F @cursorless/test-runner test:talonJs` runs the Talon-JS test runner.
Loading
Loading