Skip to content

Commit 7efaba7

Browse files
authored
test: Execute all tests on VSIX Installation base (#169)
1 parent d27e65f commit 7efaba7

File tree

7 files changed

+195
-46
lines changed

7 files changed

+195
-46
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ jobs:
5050
run: npm test
5151
if: runner.os != 'Linux'
5252

53+
- name: Pack for VSIX Tests
54+
run: npm run package:test
55+
env:
56+
TEST_TEMP: ${{ runner.temp }}
57+
58+
- name: Run VSIX Tests (Linux)
59+
run: xvfb-run -a npm run test:vsix
60+
env:
61+
TEST_TEMP: ${{ runner.temp }}
62+
if: runner.os == 'Linux'
63+
- name: Run VSIX Tests (Win/MacOS)
64+
run: npm run test:vsix
65+
env:
66+
TEST_TEMP: ${{ runner.temp }}
67+
if: runner.os != 'Linux'
68+
5369
- name: Run Linter
5470
if: always()
5571
run: npm run lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,4 @@ dist
134134
out
135135
*.vsix
136136
vscode*.d.ts
137+
tmp

.vscode-test.mjs

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,54 @@ import * as fs from 'fs';
33
import * as path from 'path';
44
import { fileURLToPath } from 'url';
55

6+
67
const dirname = fileURLToPath(new URL('.', import.meta.url));
78
const integrationTestDir = path.join(dirname, 'out/test/integration');
89
const workspaceBaseDir = path.join(dirname, 'test-workspaces');
910

1011
const vsCodeVersion = process.env.VSCODE_TEST_VERSION ?? 'stable';
1112
const vsCodePlatform = process.env.VSCODE_TEST_PLATFORM ?? 'desktop';
1213

13-
let createCommonOptions = (label) => {
14-
if (process.env.GITHUB_ACTIONS) {
15-
return {
16-
platform: vsCodePlatform,
17-
version: vsCodeVersion,
18-
env: {
19-
MOCHA_COLORS: 'true',
20-
MOCHA_VSCODE_TEST: 'true'
21-
},
22-
mocha: {
23-
ui: 'bdd',
14+
let extensionDevelopmentPath = '';
2415

25-
reporter: path.join(dirname, '.vscode-ci-test-reporter.js'),
26-
reporterOption: {
27-
jsonReporterOption: {
28-
output: path.join(dirname, 'test-results', `${label}.json`),
29-
},
30-
},
31-
timeout: 60_000,
32-
},
33-
};
34-
} else {
35-
return {
36-
platform: vsCodePlatform,
37-
version: vsCodeVersion,
38-
env: {
39-
MOCHA_VSCODE_TEST: 'true'
40-
},
41-
mocha: {
42-
ui: 'bdd',
43-
timeout: 60_000,
16+
const testMode = process.env.TEST_MODE ?? 'normal';
17+
18+
if (testMode === 'vsix') {
19+
const tempDir = process.env.TEST_TEMP ?? path.join(dirname, 'tmp')
20+
extensionDevelopmentPath = path.resolve(path.join(tempDir, 'vsix', 'extension'));
21+
}
22+
23+
function createCommonOptions(label) {
24+
/**@type {import('@vscode/test-cli').TestConfiguration} */
25+
const options = {
26+
platform: vsCodePlatform,
27+
version: vsCodeVersion,
28+
env: {
29+
MOCHA_VSCODE_TEST: 'true',
30+
},
31+
mocha: {
32+
ui: 'bdd',
33+
timeout: 60_000,
34+
},
35+
};
36+
37+
if (process.env.GITHUB_ACTIONS) {
38+
options.mocha.reporter = path.join(dirname, '.vscode-ci-test-reporter.js');
39+
options.mocha.reporterOption = {
40+
jsonReporterOption: {
41+
output: path.join(dirname, 'test-results', `${testMode}-${label}.json`),
4442
},
4543
};
44+
options.env.MOCHA_COLORS = 'true';
45+
}
46+
47+
if (extensionDevelopmentPath) {
48+
options.extensionDevelopmentPath = extensionDevelopmentPath;
4649
}
47-
};
50+
51+
52+
return options;
53+
}
4854

4955
const config = [
5056
{

package-lock.json

Lines changed: 85 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
"publish:vsce:prerelease": "npx @vscode/vsce publish --pre-release",
117117
"publish:ovsx:release": "npx ovsx publish",
118118
"publish:ovsx:prerelease": "npx ovsx publish --pre-release",
119+
"package:test": "npm run compile && tsx ./scripts/prerelease.mts && npx @vscode/vsce package && tsx ./scripts/extractVsix.mts",
119120
"package:release": "npm run compile && tsx ./scripts/prerelease.mts && npx @vscode/vsce package",
120121
"package:prerelease": "npm run compile && tsx ./scripts/prerelease.mts --pre-release && npx @vscode/vsce package --pre-release",
121122
"vscode:prepublish": "npm run compile",
@@ -126,6 +127,7 @@
126127
"watch:esbuild": "npm run clean && node .esbuild.js --watch",
127128
"watch": "npm run clean && tsc --watch",
128129
"test": "tsc && vscode-test",
130+
"test:vsix": "tsc && cross-env TEST_MODE=vsix vscode-test",
129131
"prettier": "prettier --write src",
130132
"lint": "eslint .",
131133
"fix": "eslint . --fix"
@@ -136,6 +138,7 @@
136138
"@types/chai": "^4.3.17",
137139
"@types/eslint__js": "^8.42.3",
138140
"@types/estree": "^1.0.5",
141+
"@types/extract-zip": "^2.0.1",
139142
"@types/glob": "^8.1.0",
140143
"@types/mocha": "^10.0.8",
141144
"@types/node": "22.x",
@@ -155,6 +158,7 @@
155158
"acorn-loose": "^8.4.0",
156159
"ansi-colors": "^4.1.3",
157160
"chai": "^4.4.1",
161+
"cross-env": "^7.0.3",
158162
"data-uri-to-buffer": "^6.0.2",
159163
"enhanced-resolve": "^5.17.1",
160164
"error-stack-parser": "^2.1.4",
@@ -163,6 +167,7 @@
163167
"eslint-plugin-license-header": "^0.6.1",
164168
"eslint-plugin-prettier": "^5.2.1",
165169
"eslint-visitor-keys": "^4.1.0",
170+
"extract-zip": "^2.0.1",
166171
"glob": "^11.0.0",
167172
"minimatch": "^10.0.1",
168173
"mocha": "^10.7.3",
@@ -185,7 +190,7 @@
185190
"esbuild": "^0.24.0"
186191
},
187192
"mocha-vscode": {
188-
"version": "1.1.0-preview+FFFFFFF",
189-
"date": "2024-04-02T14:30:00Z"
193+
"version": "v1.2.3+d27e65f",
194+
"date": "2024-10-20T15:38:24.261Z"
190195
}
191196
}

scripts/extractVsix.mts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Copyright (C) Daniel Kuschny (Danielku15) and contributors.
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
import extract from 'extract-zip';
10+
import * as fs from 'fs';
11+
import * as path from 'path';
12+
import { fileURLToPath } from 'url';
13+
14+
const dirname = fileURLToPath(new URL('.', import.meta.url));
15+
16+
const vsix = fs
17+
.readdirSync(path.join(dirname, '..'), {
18+
withFileTypes: true,
19+
})
20+
.filter((f) => f.name.startsWith('mocha-vscode') && f.name.endsWith('.vsix'));
21+
22+
if (vsix.length > 1) {
23+
console.error('Multiple VSIX files found, cannot decide which is the one for testing');
24+
process.exit(1);
25+
}
26+
27+
const tempDir = process.env.TEST_TEMP ?? path.join(dirname, '..', 'tmp')
28+
const extensionDir = path.join(tempDir, 'vsix');
29+
await fs.promises.rm(extensionDir, { recursive: true, force: true });
30+
await fs.promises.mkdir(extensionDir, { recursive: true });
31+
32+
await extract(path.join(vsix[0].parentPath, vsix[0].name), {
33+
dir: extensionDir,
34+
});

0 commit comments

Comments
 (0)