Skip to content

Commit 0424deb

Browse files
authored
Add infrastructure for VS Code extension tests (#757)
1 parent faef822 commit 0424deb

File tree

14 files changed

+4242
-2505
lines changed

14 files changed

+4242
-2505
lines changed
File renamed without changes.

.github/workflows/test.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
name: Test VS Code Extension
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
13+
jobs:
14+
test-extension:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: latest
22+
23+
- name: Update build environment and install XVFB
24+
run: |
25+
sudo apt-get -y update
26+
sudo apt-get -y install --fix-missing xvfb
27+
28+
- name: Compile and run tests
29+
run: |
30+
yarn install --immutable --immutable-cache --check-cache
31+
xvfb-run yarn test-vscode

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ public/dist
1515
.luarc.json
1616
.ipynb_checkpoints
1717
/.luarc.json
18+
.vscode-test
19+
*.vsix

apps/vscode/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
out/
22
*.vsix
3+
test-out/

apps/vscode/.vscode-test.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from '@vscode/test-cli';
2+
3+
export default defineConfig([
4+
{
5+
files: 'test-out/*.test.js',
6+
workspaceFolder: 'src/test/examples',
7+
},
8+
]);

apps/vscode/CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ yarn # install dependencies
77
yarn dev-vscode # run development/debug version of extension
88
```
99

10+
Run the extension tests with:
11+
12+
```sh
13+
yarn test-vscode # compile the test files and run them with the vscode-test CLI
14+
```
15+
1016
Install the dev version of the extension in VS Code or Positron with:
1117

1218
```sh
1319
yarn install-vscode
1420
yarn install-positron
1521
```
1622

17-
1823
# Debugging the extension
1924

2025
The extension must have been built in dev mode (see the build section). The `dev` build flag is essential for debugging:

apps/vscode/build.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,25 @@
1414
*/
1515

1616
import { runBuild } from "build";
17+
import * as glob from "glob";
1718

1819
const args = process.argv;
1920
const dev = args[2] === "dev";
21+
const test = args[2] === "test";
22+
const testFiles = glob.sync("src/test/*.ts");
2023

21-
runBuild({
24+
const testBuildOptions = {
25+
entryPoints: testFiles,
26+
outdir: 'test-out',
27+
external: ['vscode'],
28+
};
29+
30+
const defaultBuildOptions = {
2231
entryPoints: ['./src/main.ts'],
2332
outfile: './out/main.js',
2433
external: ['vscode'],
2534
minify: !dev,
2635
dev
27-
});
36+
};
37+
38+
runBuild(test ? testBuildOptions : defaultBuildOptions);

apps/vscode/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,8 @@
14261426
"build": "tsx build.ts",
14271427
"dev": "yarn run build dev",
14281428
"lint": "eslint src --ext ts",
1429-
"build-lang": "node syntaxes/build-lang"
1429+
"build-lang": "node syntaxes/build-lang",
1430+
"test": "yarn run build test && vscode-test"
14301431
},
14311432
"dependencies": {
14321433
"axios": "^1.2.1",
@@ -1435,6 +1436,7 @@
14351436
"editor-core": "*",
14361437
"editor-server": "*",
14371438
"editor-types": "*",
1439+
"glob": "^11.0.3",
14381440
"highlight.js": "^11.7.0",
14391441
"js-yaml": "^4.1.0",
14401442
"lodash.debounce": "^4.0.8",
@@ -1472,7 +1474,8 @@
14721474
"@types/which": "^2.0.2",
14731475
"@typescript-eslint/eslint-plugin": "^5.45.0",
14741476
"@typescript-eslint/parser": "^5.45.0",
1475-
"@vscode/test-electron": "^2.2.0",
1477+
"@vscode/test-cli": "^0.0.11",
1478+
"@vscode/test-electron": "^2.5.2",
14761479
"@vscode/vsce": "^2.15.0",
14771480
"build": "*",
14781481
"esbuild": "^0.16.7",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "Hello, Quarto"
3+
format: html
4+
---
5+
6+
## Header
7+
8+
```{python}
9+
1 + 1
10+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from "vscode";
2+
import * as assert from "assert";
3+
import { exampleWorkspacePath } from "./test-utils";
4+
import { isQuartoDoc } from "../core/doc";
5+
6+
suite("Quarto basics", () => {
7+
test("Can open a Quarto document", async () => {
8+
const doc = await vscode.workspace.openTextDocument(exampleWorkspacePath("hello.qmd"));
9+
const editor = await vscode.window.showTextDocument(doc);
10+
assert.strictEqual(editor?.document.languageId, "quarto");
11+
assert.strictEqual(isQuartoDoc(editor?.document), true);
12+
});
13+
});

0 commit comments

Comments
 (0)