Skip to content

Commit 526c2d2

Browse files
committed
test(doctor): run the suite with vitest, directly from TypeScript
Brings the package onto the same runner as the CLI. Unlike the CLI, nothing here reflects over constructor source, so there is no reason to test the compiled output - vitest runs the TypeScript directly. That removes the dist-test build and the fixture copying that existed only to put example.zip next to the compiled tests; resolved from the sources, it is already there. tsconfig.test.json becomes a typecheck-only config, since test types were previously checked as a side effect of compiling them. The runner needed two changes: the extractZip test and its afterEach used mocha's done callback, and android-tools-info used before/after. 82 passing, unchanged.
1 parent e14dbbe commit 526c2d2

8 files changed

Lines changed: 30 additions & 34 deletions

File tree

packages/doctor/package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"clean": "npx rimraf node_modules package-lock.json && npm i && npm run clean.build",
1717
"clean.build": "node scripts/clean.js",
1818
"build": "tsc",
19-
"build.all": "tsc -p tsconfig.test.json && node scripts/copy-test-fixtures.js",
2019
"dev": "tsc --watch",
2120
"prepack": "npm run clean.build && npm test && tsc -p tsconfig.release.json",
22-
"test": "npm run build.all && mocha --recursive dist-test/test",
23-
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
21+
"test": "tsc -p tsconfig.test.json && vitest run",
22+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
23+
"test-watch": "vitest"
2424
},
2525
"repository": {
2626
"type": "git",
@@ -46,17 +46,16 @@
4646
"devDependencies": {
4747
"@types/chai": "5.2.2",
4848
"@types/lodash": "4.17.21",
49-
"@types/mocha": "10.0.10",
5049
"@types/semver": "7.7.1",
5150
"@types/shelljs": "0.8.17",
5251
"@types/temp": "0.9.4",
5352
"@types/winreg": "1.2.36",
5453
"@types/yauzl": "2.10.3",
5554
"chai": "5.3.3",
5655
"conventional-changelog-cli": "^5.0.0",
57-
"mocha": "11.7.5",
5856
"rimraf": "6.1.2",
59-
"typescript": "~5.9.2"
57+
"typescript": "~5.9.2",
58+
"vitest": "^4.1.10"
6059
},
6160
"dependencies": {
6261
"lodash": "4.17.21",
@@ -65,4 +64,4 @@
6564
"winreg": "1.2.5",
6665
"yauzl": "3.2.0"
6766
}
68-
}
67+
}

packages/doctor/scripts/clean.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if (result.status !== 0) {
1919
throw new Error(`git clean exited with status ${result.status}`);
2020
}
2121

22-
for (const dir of ["dist", "dist-test", "coverage"]) {
22+
for (const dir of ["dist", "coverage"]) {
2323
fs.rmSync(path.join(rootDir, dir), { recursive: true, force: true });
2424
}
2525

packages/doctor/scripts/copy-test-fixtures.js

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

packages/doctor/test/android-tools-info.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("androidToolsInfo", () => {
2323
EOL +
2424
" described in " +
2525
Constants.SYSTEM_REQUIREMENTS_LINKS;
26-
before(() => {
26+
beforeAll(() => {
2727
process.env["ANDROID_HOME"] = "test";
2828
});
2929
const getAndroidToolsInfo = (runtimeVersion?: string): AndroidToolsInfo => {
@@ -404,7 +404,7 @@ describe("androidToolsInfo", () => {
404404
});
405405
});
406406

407-
after(() => {
407+
afterAll(() => {
408408
process.env["ANDROID_HOME"] = originalAndroidHome;
409409
});
410410
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vitest/globals" />

packages/doctor/test/wrappers/file-system.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,20 @@ describe("FileSystem", () => {
2626
`${tmpDir}/test/wrappers/file-system.ts`,
2727
];
2828

29-
it("should extract in example zip archive in tmp folder", (done) => {
29+
it("should extract in example zip archive in tmp folder", async () => {
3030
const fs = new FileSystem();
3131

32-
fs.extractZip(testFilePath, tmpDir)
33-
.then(() => {
34-
const allExists = filesThatNeedToExist
35-
.map(fs.exists)
36-
.reduce((acc, r) => acc && r, true);
32+
await fs.extractZip(testFilePath, tmpDir);
3733

38-
assert.isTrue(allExists);
34+
const allExists = filesThatNeedToExist
35+
.map(fs.exists)
36+
.reduce((acc, r) => acc && r, true);
3937

40-
done();
41-
})
42-
.catch((e) => done(e));
38+
assert.isTrue(allExists);
4339
});
4440

45-
afterEach((done) => {
41+
afterEach(() => {
4642
rimrafSync(tmpDir);
47-
done();
4843
});
4944
});
5045
});

packages/doctor/tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
44
"rootDir": ".",
5-
"outDir": "dist-test",
5+
"noEmit": true,
66
"declaration": false
77
},
88
"include": ["src/", "test/", "typings/"]

packages/doctor/vitest.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
// Unlike the CLI, this package has no injector doing constructor-source
4+
// reflection, so the TypeScript sources run directly with no build step.
5+
export default defineConfig({
6+
test: {
7+
globals: true,
8+
environment: "node",
9+
include: ["test/**/*.ts"],
10+
exclude: ["**/node_modules/**", "**/*.d.ts"],
11+
},
12+
});

0 commit comments

Comments
 (0)