Skip to content

Commit 6919a8a

Browse files
committed
test: replace mocha with vitest
Vitest runs tsc's output rather than the TypeScript sources. The injector discovers dependencies by regex-parsing constructor source text (annotate() in lib/common/helpers.ts), which only matches tsc's emit; esbuild's class transform emits constructor(...args), so running the sources directly makes every injectable fail to resolve. Test changes required by the runner: - before/after hooks renamed to beforeAll/afterAll - 9 promise-chain tests using mocha's done callback converted to async/await - 25 event-driven done callbacks adapted through withDone(), which wraps a callback-style body in the promise the runner expects - the hand-written mocha global typings replaced with vitest/globals Three failures were pre-existing rather than migration fallout, and are fixed here because vitest surfaces them where mocha stayed quiet: - test/options.ts disabled its whole suite with an early return, and getNSValue in project-data-service generates its cases from an array whose entries are all commented out; both are now explicit .skip, which is why the skipped count rises from 9 to 38 - project-name-service only passed because test/project-commands.ts assigns helpers.isInteractive = () => true in a beforeEach and never restores it, and mocha's shared module registry leaked that to every file running after it. Per-file isolation removes the leak, so ensureValidName takes its non-interactive path and never prompts; the test now pins interactivity explicitly through setIsInteractive() - the callstack assertion in errors.ts matched "at next", a mocha runner frame, and now just requires a stack frame Same 1513 passing, 22s rather than 31s. Drops istanbul, which nothing referenced, and dev/tsc-to-mocha-watch.js, which required chalk - not a declared dependency since it was removed in e562267.
1 parent e8e83e4 commit 6919a8a

22 files changed

Lines changed: 2228 additions & 2213 deletions

dev/tsc-to-mocha-watch.js

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

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)