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

Make it easier to have unit tests in VSCode packages #1541

Merged
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
2 changes: 2 additions & 0 deletions docs/contributing/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Run the `workbench.action.debug.selectandstart` command and then select

See [test-case-recorder.md](./test-case-recorder.md).

It is also possible to write manual tests. When doing so, we have a convention that any test that must be run within a VSCode context (eg because it imports `"vscode"`), should be placed in a file with the suffix `.vscode.test.ts`. All other tests should end with just `.test.ts`. This allows us to run non-VSCode tests locally outside of VSCode using the `Run unit tests` launch config. These tests run much faster than the full VSCode test suite.

## Parse tree support

### Adding a new programming language
Expand Down
2 changes: 1 addition & 1 deletion packages/test-harness/src/runners/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import { runAllTestsInDir } from "../util/runAllTestsInDir";
* @returns A promise that resolves when tests have finished running
*/
export function run(): Promise<void> {
return runAllTestsInDir(path.join(getCursorlessRepoRoot(), "packages"));
return runAllTestsInDir(path.join(getCursorlessRepoRoot(), "packages"), true);
}
15 changes: 0 additions & 15 deletions packages/test-harness/src/runners/endToEndOnly.ts
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't used anywhere

This file was deleted.

15 changes: 8 additions & 7 deletions packages/test-harness/src/runners/unitTestsOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

import { getCursorlessRepoRoot } from "@cursorless/common";
import * as path from "path";
import { runAllTestsInDirs } from "../util/runAllTestsInDir";

const testDirectories = ["cursorless-engine", "common"];
import { runAllTestsInDir } from "../util/runAllTestsInDir";

/**
* Runs all tests that don't have to be run within VSCode.
* @returns A promise that resolves when tests have finished running
*/
export function run(): Promise<void> {
return runAllTestsInDirs(
testDirectories.map((testDirectory) =>
path.resolve(getCursorlessRepoRoot(), `packages/${testDirectory}`),
),
return runAllTestsInDir(
path.join(getCursorlessRepoRoot(), "packages"),
false,
);
}
5 changes: 1 addition & 4 deletions packages/test-harness/src/scripts/runTestsCI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { launchVscodeAndRunTests } from "../util/launchVscodeAndRunTests";

(async function main() {
// Note that we run all tests, including unit tests, in VSCode, even though
// unit tests could be run separately. If we wanted to run unit tests
// separately, we could instead use `../runners/endToEndOnly` instead of
// `../runners/all` and then just call `await runUnitTests()` beforehand to
// run the unit tests directly, instead of as part of VSCode runner.
// unit tests could be run separately.
const extensionTestsPath = path.resolve(
getCursorlessRepoRoot(),
"packages/test-harness/out/runners/all",
Expand Down
18 changes: 14 additions & 4 deletions packages/test-harness/src/util/runAllTestsInDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { promisify } from "util";

const glob = promisify(globRaw);

export function runAllTestsInDir(testRoot: string) {
return runAllTestsInDirs([testRoot]);
export function runAllTestsInDir(
testRoot: string,
includeVscodeTests: boolean,
) {
return runAllTestsInDirs([testRoot], includeVscodeTests);
}

export async function runAllTestsInDirs(testRoots: string[]): Promise<void> {
export async function runAllTestsInDirs(
testRoots: string[],
includeVscodeTests: boolean,
): Promise<void> {
// Create the mocha test
const mocha = new Mocha({
ui: "tdd",
Expand All @@ -19,7 +25,11 @@ export async function runAllTestsInDirs(testRoots: string[]): Promise<void> {
});

for (const testRoot of testRoots) {
const files = await glob("**/**.test.js", { cwd: testRoot });
let files = await glob("**/**.test.js", { cwd: testRoot });

if (!includeVscodeTests) {
files = files.filter((f) => !f.endsWith("vscode.test.js"));
}

// Add files to the test suite
files.forEach((f) => mocha.addFile(path.resolve(testRoot, f)));
Expand Down