Skip to content

Commit f24cc5d

Browse files
authored
test: replace mocha with vitest (#6094)
1 parent 695de03 commit f24cc5d

37 files changed

Lines changed: 4902 additions & 2264 deletions

.github/workflows/tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,40 @@ jobs:
5454

5555
- name: Test
5656
run: npm test
57+
58+
doctor:
59+
name: Doctor (Node ${{ matrix.node-version }})
60+
runs-on: ubuntu-latest
61+
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
# No darwin leg: unlike the CLI suites, these stub the platform through
66+
# a fake HostInfo rather than probing it, so a second OS runs identical
67+
# assertions.
68+
node-version: [ '20.x', '22.x', '24.x' ]
69+
70+
steps:
71+
72+
- name: Harden the runner (Audit all outbound calls)
73+
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
74+
with:
75+
egress-policy: audit
76+
77+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
78+
with:
79+
persist-credentials: false
80+
81+
- uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
82+
with:
83+
node-version: ${{ matrix.node-version }}
84+
cache: 'npm'
85+
cache-dependency-path: packages/doctor/package-lock.json
86+
87+
- name: Install
88+
working-directory: packages/doctor
89+
run: npm ci
90+
91+
- name: Test
92+
working-directory: packages/doctor
93+
run: npm test

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,7 @@ lib/common/test-reports.xml
8888
!lib/common/scripts/**
8989
config/test-deps-versions-generated.json
9090
!scripts/*.js
91+
!dev/*.js
92+
9193
# build output
9294
/dist

dev/tsc-to-mocha-watch.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

dev/tsc-to-vitest-watch.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Run "tsc" in watch mode alongside vitest. Vitest runs the compiled output,
2+
// so on its own it never notices a .ts edit - tsc has to re-emit first, and
3+
// vitest picks the change up from there.
4+
5+
const { spawn } = require("child_process");
6+
7+
// shell: true so the node_modules/.bin shims resolve on Windows as well
8+
const spawnOptions = { stdio: "inherit", shell: true };
9+
10+
const children = [
11+
// --preserveWatchOutput keeps tsc from clearing the screen and wiping the
12+
// test results out from under you on every recompile
13+
spawn("tsc", ["--watch", "--preserveWatchOutput"], spawnOptions),
14+
// --watch explicitly: vitest only infers watch mode when stdout is a TTY,
15+
// and would otherwise run once and exit, taking tsc down with it
16+
spawn("vitest", ["--watch"], spawnOptions),
17+
];
18+
19+
let shuttingDown = false;
20+
21+
function shutdown() {
22+
if (shuttingDown) {
23+
return;
24+
}
25+
shuttingDown = true;
26+
for (const child of children) {
27+
child.kill("SIGINT");
28+
}
29+
}
30+
31+
process.on("SIGINT", shutdown);
32+
process.on("SIGTERM", shutdown);
33+
34+
for (const child of children) {
35+
// if either side dies, don't leave the other running in the background
36+
child.on("exit", shutdown);
37+
}

lib/common/test/definitions/mocha.d.ts

Lines changed: 0 additions & 86 deletions
This file was deleted.

lib/common/test/unit-tests/analytics-service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe("analytics-service", () => {
128128
service = null;
129129
});
130130

131-
after(() => {
131+
afterAll(() => {
132132
setIsInteractive(null);
133133
});
134134

@@ -147,8 +147,8 @@ describe("analytics-service", () => {
147147
});
148148

149149
it("returns false when analytics status is disabled", async () => {
150-
baseTestScenario.exceptionsTracking = baseTestScenario.featureTracking =
151-
false;
150+
baseTestScenario.exceptionsTracking =
151+
baseTestScenario.featureTracking = false;
152152
const testInjector = createTestInjector(baseTestScenario);
153153
service = testInjector.resolve<IAnalyticsService>("analyticsService");
154154
const staticConfig: Config.IStaticConfig =
@@ -377,8 +377,8 @@ describe("analytics-service", () => {
377377
});
378378

379379
it("does nothing when exception and feature tracking are already set", async () => {
380-
baseTestScenario.featureTracking = baseTestScenario.exceptionsTracking =
381-
true;
380+
baseTestScenario.featureTracking =
381+
baseTestScenario.exceptionsTracking = true;
382382
const testInjector = createTestInjector(baseTestScenario);
383383
service = testInjector.resolve<IAnalyticsService>("analyticsService");
384384
await service.checkConsent();

0 commit comments

Comments
 (0)