Skip to content

Commit 72c86ae

Browse files
committed
Run all vitests as electron
1 parent 1ddbdc4 commit 72c86ae

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ jobs:
4646

4747
- run: yarn test:ci
4848

49-
- run: yarn test:electron
50-
5149
package:
5250
name: Package
5351
runs-on: ubuntu-22.04

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010
},
1111
"[jsonc]": {
1212
"editor.defaultFormatter": "esbenp.prettier-vscode"
13-
}
13+
},
14+
"vitest.nodeEnv": {
15+
"ELECTRON_RUN_AS_NODE": "1"
16+
},
17+
"vitest.nodeExecutable": "node_modules/.bin/electron"
1418
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
"package": "webpack --mode production --devtool hidden-source-map",
2626
"package:prerelease": "npx vsce package --pre-release",
2727
"pretest": "tsc -p . --outDir out && tsc -p test --outDir out && yarn run build && yarn run lint",
28-
"test": "vitest",
28+
"test": "ELECTRON_RUN_AS_NODE=1 electron node_modules/vitest/vitest.mjs",
2929
"test:ci": "CI=true yarn test",
30-
"test:electron": "ELECTRON_RUN_AS_NODE=1 electron node_modules/vitest/vitest.mjs test/unit/error.test.ts",
3130
"test:integration": "vscode-test",
3231
"vscode:prepublish": "yarn package",
3332
"watch": "webpack --watch"

test/unit/error.test.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ describe("Certificate errors", () => {
1212
// Before each test we make a request to sanity check that we really get the
1313
// error we are expecting, then we run it through CertificateError.
1414

15-
// Some tests behave differently in Electron (BoringSSL) vs Node.js (OpenSSL).
16-
// Run `yarn test:electron` to test Electron-specific behavior.
17-
const isElectron =
18-
(process.versions.electron || process.env.ELECTRON_RUN_AS_NODE) &&
19-
!process.env.VSCODE_PID; // Running from the test explorer in VS Code
15+
// These tests run in Electron (BoringSSL) for accurate certificate validation testing.
16+
17+
it("should run in Electron environment", () => {
18+
const isElectron =
19+
process.versions.electron || process.env.ELECTRON_RUN_AS_NODE;
20+
expect(isElectron).toBeTruthy();
21+
});
2022

2123
beforeAll(() => {
2224
vi.mock("vscode", () => {
@@ -121,26 +123,16 @@ describe("Certificate errors", () => {
121123
servername: "localhost",
122124
}),
123125
});
124-
if (isElectron) {
125-
await expect(request).rejects.toHaveProperty(
126-
"code",
127-
X509_ERR_CODE.UNABLE_TO_VERIFY_LEAF_SIGNATURE,
128-
);
129-
try {
130-
await request;
131-
} catch (error) {
132-
const wrapped = await CertificateError.maybeWrap(
133-
error,
134-
address,
135-
logger,
136-
);
137-
expect(wrapped instanceof CertificateError).toBeTruthy();
138-
expect((wrapped as CertificateError).x509Err).toBe(
139-
X509_ERR.NON_SIGNING,
140-
);
141-
}
142-
} else {
143-
await expect(request).resolves.toHaveProperty("data", "foobar");
126+
await expect(request).rejects.toHaveProperty(
127+
"code",
128+
X509_ERR_CODE.UNABLE_TO_VERIFY_LEAF_SIGNATURE,
129+
);
130+
try {
131+
await request;
132+
} catch (error) {
133+
const wrapped = await CertificateError.maybeWrap(error, address, logger);
134+
expect(wrapped instanceof CertificateError).toBeTruthy();
135+
expect((wrapped as CertificateError).x509Err).toBe(X509_ERR.NON_SIGNING);
144136
}
145137
});
146138

0 commit comments

Comments
 (0)