Skip to content

Commit 1ccd155

Browse files
tests: configure headless ci testing for vscode
1 parent 9b33a2f commit 1ccd155

13 files changed

+721
-171
lines changed

.github/workflows/vscode-tests.yaml

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: Publish Preview Extension
2+
3+
on:
4+
push:
5+
branches:
6+
- pe/ci-testing
7+
8+
jobs:
9+
build:
10+
strategy:
11+
matrix:
12+
include:
13+
- os: windows-latest
14+
platform: win32
15+
arch: x64
16+
npm_config_arch: x64
17+
- os: windows-latest
18+
platform: win32
19+
arch: arm64
20+
npm_config_arch: arm
21+
- os: ubuntu-latest
22+
platform: linux
23+
arch: x64
24+
npm_config_arch: x64
25+
- os: ubuntu-latest
26+
platform: linux
27+
arch: arm64
28+
npm_config_arch: arm64
29+
- os: ubuntu-latest
30+
platform: linux
31+
arch: armhf
32+
npm_config_arch: arm
33+
- os: ubuntu-latest
34+
platform: alpine
35+
arch: x64
36+
npm_config_arch: x64
37+
- os: macos-12 # should migrate this to the newer x64 version of macos-14
38+
platform: darwin
39+
arch: x64
40+
npm_config_arch: x64
41+
- os: macos-12 # same here, especially
42+
platform: darwin
43+
arch: arm64
44+
npm_config_arch: arm64
45+
runs-on: ${{ matrix.os }}
46+
steps:
47+
# 1. Check-out repository
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0 # This ensures all tags are fetched
52+
53+
- name: Checkout tag
54+
run: git checkout ${GITHUB_REF#refs/tags/}
55+
56+
# 2. Install npm dependencies
57+
- name: Use Node.js from .nvmrc
58+
uses: actions/setup-node@v4
59+
with:
60+
node-version-file: ".nvmrc"
61+
62+
- name: Cache extension node_modules
63+
uses: actions/cache@v3
64+
with:
65+
path: extensions/vscode/node_modules
66+
key: ${{ runner.os }}-node-${{ hashFiles('extensions/vscode/package-lock.json') }}
67+
68+
- name: Cache core node_modules
69+
uses: actions/cache@v3
70+
with:
71+
path: core/node_modules
72+
key: ${{ runner.os }}-node-${{ hashFiles('core/package-lock.json') }}
73+
74+
- name: Cache gui node_modules
75+
uses: actions/cache@v3
76+
with:
77+
path: gui/node_modules
78+
key: ${{ runner.os }}-node-${{ hashFiles('gui/package-lock.json') }}
79+
80+
- name: Install extension Dependencies
81+
run: |
82+
cd extensions/vscode
83+
npm ci
84+
env:
85+
# https://github.com/microsoft/vscode-ripgrep/issues/9#issuecomment-643965333
86+
GITHUB_TOKEN: ${{ secrets.CI_GITHUB_TOKEN }}
87+
88+
- name: Install gui Dependencies
89+
run: |
90+
cd gui
91+
npm ci
92+
93+
- name: Install Core Dependencies
94+
run: |
95+
cd core
96+
npm ci
97+
98+
# 2.5. Pre package
99+
- name: Set var for environment info
100+
shell: pwsh
101+
run: echo "target=${{ matrix.platform }}-${{ matrix.arch }}" >> $env:GITHUB_ENV
102+
103+
- name: Prepackage the extension
104+
run: |
105+
cd extensions/vscode
106+
npm run prepackage -- --target ${{ env.target }}
107+
108+
# 3. Re-install esbuild (for cases that we force installed for another arch in prepackage.js)
109+
- name: Re-install esbuild
110+
run: |
111+
cd extensions/vscode
112+
npm install -f esbuild
113+
114+
# 4. Run tests for the extension
115+
- name: Run headless test
116+
uses: coactions/setup-xvfb@v1
117+
with:
118+
run: npm test
119+
working-directory: ./extensions/vscode
120+
# - name: Install Xvfb for Linux and run tests
121+
# run: |
122+
# sudo apt-get install -y xvfb # Install Xvfb
123+
# Xvfb :99 & # Start Xvfb
124+
# export DISPLAY=:99 # Export the display number to the environment
125+
# cd extensions/vscode
126+
# npm run test
127+
# if: matrix.os == 'ubuntu-latest'
128+
129+
# - name: Run extension tests
130+
# run: |
131+
# cd extensions/vscode
132+
# npm run test
133+
# if: matrix.os != 'ubuntu-latest'

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,4 @@ Icon?
165165

166166
.continue
167167

168-
# Sandbox env default file
169-
extensions/vscode/manual-testing-sandbox/example.ts
170-
171168
.prompts/

.vscode/launch.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode"
1818
],
1919
"pauseForSourceMap": false,
20-
"outFiles": [
21-
"${workspaceFolder}/extensions/vscode/out/extension.js",
22-
"/Users/natesesti/.continue/config.ts"
23-
],
20+
"outFiles": ["${workspaceFolder}/extensions/vscode/out/extension.js"],
2421
"preLaunchTask": "vscode-extension:build",
2522
"env": {
2623
// "CONTROL_PLANE_ENV": "local"

extensions/vscode/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ gui/*
1414
!gui/onigasm.wasm
1515

1616
.devcontainer
17-
.github
17+
.github
18+
src/test/fixtures/test-workspace/

extensions/vscode/.vscodeignore

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ node_modules/**
1616
**/.pytest_cache
1717
**/__pycache__
1818

19-
manual-testing-sandbox
2019
esbuild.js
2120
esbuild.test.mjs
2221
importMetaUrl.js

extensions/vscode/esbuild.test.mjs

+30-34
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
12
import * as esbuild from "esbuild";
23
import glob from "glob";
34

@@ -9,59 +10,54 @@ import glob from "glob";
910

1011
console.log("Bundling tests...");
1112

12-
// Bundles script to run tests on VSCode host + mocha runner that will be invoked from within VSCode host
13-
await esbuild.build({
14-
entryPoints: [
15-
// Runs mocha runner on VSCode host using runTests from @vscode/test-electron
16-
"src/test/runner/runTestOnVSCodeHost.ts",
17-
18-
// Runs the bundled tests using Mocha class
19-
"src/test/runner/mochaRunner.ts",
20-
],
13+
const baseConfig = {
2114
bundle: true,
2215
outdir: "out",
23-
2416
external: [
2517
"vscode",
26-
2718
// Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
2819
// Example warning by esbuild when mocha is not externalized:
2920
// [WARNING] "./reporters/parallel-buffered" should be marked as external for use with "require.resolve" [require-resolve-not-external]
3021
"mocha",
22+
"esbuild",
23+
"./xhr-sync-worker.js",
3124
],
3225
format: "cjs",
3326
platform: "node",
3427
sourcemap: true,
3528
loader: {
36-
// eslint-disable-next-line @typescript-eslint/naming-convention
3729
".node": "file",
3830
},
39-
});
31+
};
4032

41-
/**
42-
* Note: Bundling is done to work around import issues, for example with fkill that does not provide cjs module.
43-
* Rather than figuring out a combination of tsconfig.json that would work, I decided to bundle tests instead.
44-
*/
45-
await esbuild.build({
33+
const runnerConfig = {
34+
...baseConfig,
35+
// Bundles script to run tests on VSCode host + mocha runner that will be invoked from within VSCode host
36+
entryPoints: [
37+
// Runs mocha runner on VSCode host using runTests from @vscode/test-electron
38+
"src/test/runner/runTestOnVSCodeHost.ts",
39+
// Runs the bundled tests using Mocha class
40+
"src/test/runner/mochaRunner.ts",
41+
],
42+
};
43+
44+
const testsConfig = {
45+
...baseConfig,
4646
// Tests can be added anywhere in src folder
4747
entryPoints: glob.sync("src/**/*.test.ts"),
48-
bundle: true,
49-
outdir: "out",
50-
external: [
51-
"vscode",
52-
53-
// Its important to externalize mocha, otherwise mocha seems to be not initialized properly when running tests
54-
"mocha",
55-
],
56-
format: "cjs",
57-
platform: "node",
58-
sourcemap: true,
59-
loader: {
60-
// eslint-disable-next-line @typescript-eslint/naming-convention
61-
".node": "file",
62-
},
6348
// To allow import.meta.path for transformers.js
6449
// https://github.com/evanw/esbuild/issues/1492#issuecomment-893144483
6550
inject: ["./scripts/importMetaUrl.js"],
6651
define: { "import.meta.url": "importMetaUrl" },
67-
});
52+
};
53+
54+
// Build runner
55+
await esbuild.build(runnerConfig);
56+
57+
/**
58+
* Note: Bundling is done to work around import issues, for example with fkill that does not provide cjs module.
59+
* Rather than figuring out a combination of tsconfig.json that would work, I decided to bundle tests instead.
60+
*
61+
* Build tests
62+
*/
63+
await esbuild.build(testsConfig);

0 commit comments

Comments
 (0)