Skip to content

Add infrastructure for VS Code extension tests #757

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

Merged
merged 10 commits into from
Jul 12, 2025
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
File renamed without changes.
31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

name: Test VS Code Extension

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test-extension:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: latest

- name: Update build environment and install XVFB
run: |
sudo apt-get -y update
sudo apt-get -y install --fix-missing xvfb

- name: Compile and run tests
run: |
yarn install --immutable --immutable-cache --check-cache
xvfb-run yarn test-vscode
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ public/dist
.luarc.json
.ipynb_checkpoints
/.luarc.json
.vscode-test
*.vsix
1 change: 1 addition & 0 deletions apps/vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
out/
*.vsix
test-out/
8 changes: 8 additions & 0 deletions apps/vscode/.vscode-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from '@vscode/test-cli';

export default defineConfig([
{
files: 'test-out/*.test.js',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is where we tell the vscode-test cli where to find the files.

workspaceFolder: 'src/test/examples',
},
]);
7 changes: 6 additions & 1 deletion apps/vscode/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ yarn # install dependencies
yarn dev-vscode # run development/debug version of extension
```

Run the extension tests with:

```sh
yarn test-vscode # compile the test files and run them with the vscode-test CLI
```

Install the dev version of the extension in VS Code or Positron with:

```sh
yarn install-vscode
yarn install-positron
```


# Debugging the extension

The extension must have been built in dev mode (see the build section). The `dev` build flag is essential for debugging:
Expand Down
15 changes: 13 additions & 2 deletions apps/vscode/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@
*/

import { runBuild } from "build";
import * as glob from "glob";

const args = process.argv;
const dev = args[2] === "dev";
const test = args[2] === "test";
const testFiles = glob.sync("src/test/*.ts");

runBuild({
const testBuildOptions = {
entryPoints: testFiles,
outdir: 'test-out',
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This creates the test .js files in the directory where we can tell the vscode-test cli where to find them.

external: ['vscode'],
};

const defaultBuildOptions = {
entryPoints: ['./src/main.ts'],
outfile: './out/main.js',
external: ['vscode'],
minify: !dev,
dev
});
};

runBuild(test ? testBuildOptions : defaultBuildOptions);
7 changes: 5 additions & 2 deletions apps/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,8 @@
"build": "tsx build.ts",
"dev": "yarn run build dev",
"lint": "eslint src --ext ts",
"build-lang": "node syntaxes/build-lang"
"build-lang": "node syntaxes/build-lang",
"test": "yarn run build test && vscode-test"
},
"dependencies": {
"axios": "^1.2.1",
Expand All @@ -1422,6 +1423,7 @@
"editor-core": "*",
"editor-server": "*",
"editor-types": "*",
"glob": "^11.0.3",
"highlight.js": "^11.7.0",
"js-yaml": "^4.1.0",
"lodash.debounce": "^4.0.8",
Expand Down Expand Up @@ -1459,7 +1461,8 @@
"@types/which": "^2.0.2",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@vscode/test-electron": "^2.2.0",
"@vscode/test-cli": "^0.0.11",
"@vscode/test-electron": "^2.5.2",
"@vscode/vsce": "^2.15.0",
"build": "*",
"esbuild": "^0.16.7",
Expand Down
10 changes: 10 additions & 0 deletions apps/vscode/src/test/examples/hello.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "Hello, Quarto"
format: html
---

## Header

```{python}
1 + 1
```
13 changes: 13 additions & 0 deletions apps/vscode/src/test/quartoDoc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as vscode from "vscode";
import * as assert from "assert";
import { exampleWorkspacePath } from "./test-utils";
import { isQuartoDoc } from "../core/doc";

suite("Quarto basics", () => {
test("Can open a Quarto document", async () => {
const doc = await vscode.workspace.openTextDocument(exampleWorkspacePath("hello.qmd"));
const editor = await vscode.window.showTextDocument(doc);
assert.strictEqual(editor?.document.languageId, "quarto");
assert.strictEqual(isQuartoDoc(editor?.document), true);
});
});
18 changes: 18 additions & 0 deletions apps/vscode/src/test/test-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as path from "path";


/**
* Path to the root directory of the extension:
* https://github.com/microsoft/vscode-python-tools-extension-template/blob/main/src/common/constants.ts
*/
export const EXTENSION_ROOT_DIR =
path.basename(__dirname) === "common"
? path.dirname(path.dirname(__dirname))
: path.dirname(__dirname);

export const TEST_PATH = path.join(EXTENSION_ROOT_DIR, "src", "test");
export const WORKSPACE_PATH = path.join(TEST_PATH, "examples");

export function exampleWorkspacePath(file: string): string {
return path.join(WORKSPACE_PATH, file);
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
"build": "turbo run build",
"dev-writer": "turbo run dev --filter writer*",
"dev-vscode": "turbo run dev --filter quarto...",
"test-vscode": "cd apps/vscode && yarn test",
"install-vscode": "cd apps/vscode && yarn install-vscode",
"install-positron": "cd apps/vscode && yarn install-positron",
"lint": "turbo run lint",
"format": "prettier --write \"**/*.{ts,tsx}\"",
"watch": "concurrently 'tsc --watch --noEmit --project apps/writer/tsconfig.json' 'tsc --watch --noEmit --project packages/writer-server/tsconfig.json'"
},
"devDependencies": {
"@vscode/test-cli": "^0.0.11",
"concurrently": "^7.5.0",
"eslint": "^7.32.0",
"eslint-config-custom": "*",
Expand Down
5 changes: 4 additions & 1 deletion packages/build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { AssetPair, copy } from 'esbuild-plugin-copy';

export interface BuildOptions {
entryPoints: string[];
outfile: string;
outfile?: string;
outdir?: string;
assets?: Array<AssetPair>;
bundle?: boolean; // true
minify?: boolean; // false
Expand All @@ -32,6 +33,7 @@ export async function runBuild(options: BuildOptions) {
const {
entryPoints,
outfile,
outdir,
assets,
bundle = true,
minify = false,
Expand All @@ -44,6 +46,7 @@ export async function runBuild(options: BuildOptions) {
await build({
entryPoints,
outfile,
outdir,
bundle,
minify,
format,
Expand Down
Loading