Skip to content

Commit 686ef1e

Browse files
authored
Migrate test runner from bun:test to vitest (#1784)
1 parent 1cdd7a8 commit 686ef1e

File tree

13 files changed

+242
-35
lines changed

13 files changed

+242
-35
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
with:
5454
bun-version: 1.3.10
5555
- run: bun install --frozen-lockfile
56-
- run: bunx depcheck --ignores depcheck,@types/bun,@types/bun-types,bun:test
56+
- run: bunx depcheck --ignores depcheck,@types/bun,@types/bun-types,vitest,@vitest/coverage-v8
5757

5858
test:
5959
runs-on: ubuntu-24.04

CLAUDE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ CLI tool to run GitLab CI pipelines locally. Written in TypeScript, built with B
44

55
## Build & Runtime
66

7-
- **Runtime**: Bun (not Node.js). All scripts use `bun`/`bun test`/`bun run`.
7+
- **Runtime**: Bun (not Node.js). All scripts use `bun`/`bun run`. Tests use vitest.
88
- **npm publish**: Still uses `npm publish --provenance` because Bun doesn't support provenance.
99
- **`bin` field**: Points to `dist/index.js` (Node.js-compatible bundle built by `bun run build:node`), not `src/index.ts`. This keeps `npm install -g` working without Bun.
1010
- **Standalone binaries**: Built with `bun build --compile` for linux-amd64, linux-arm64, macos-x64, macos-arm64, win.
1111
- **Version**: Hardcoded as `0.0.0` in `package.json`. CI replaces it via `sed` before build/publish. At runtime, `src/index.ts` reads it from `package.json` import.
1212

1313
## Testing
1414

15-
- **Never run the full test suite** (`bun test`), it takes too long. Always run targeted tests: `bun test --timeout 60000 tests/test-cases/<name>/`
16-
- **Timeout**: `bunfig.toml` timeout setting does not work. The `--timeout 60000` flag in package.json scripts is required.
15+
- **Never run the full test suite** (`bun run test`), it takes too long. Always run targeted tests: `bunx vitest run tests/test-cases/<name>/`
16+
- **Timeout**: Configured in `vitest.config.ts` (`testTimeout: 60_000`).
1717
- **Docker tests**: Tests under `dind-*` require Docker and are slow.
18-
- **depcheck ignores**: `depcheck,@types/bun,@types/bun-types,bun:test`
18+
- **depcheck ignores**: `depcheck,@types/bun,@types/bun-types,vitest,@vitest/coverage-v8`
1919

2020
## Schema
2121

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,10 @@ You need [bun](https://bun.sh/) installed.
416416
bun install
417417
418418
# Run all tests
419-
bun test
419+
bun run test
420420
421421
# Run individual test-case
422-
bun test tests/test-cases/cache-paths-not-array
422+
bunx vitest run tests/test-cases/cache-paths-not-array
423423
```
424424

425425
![example](./docs/images/example.png)

bun.lock

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

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"build-all": "bun run build:linux-amd64 && bun run build:linux-arm64 && bun run build:win && bun run build:macos-x64 && bun run build:macos-arm64",
1717
"check-all": "bun run lint && bun run coverage",
1818
"lint": "eslint .",
19-
"test": "FORCE_COLOR=1 bun test --timeout 60000",
20-
"test-except-dind": "bun test --timeout 60000 --filter '(?!.*dind)'",
21-
"coverage": "FORCE_COLOR=1 bun test --timeout 60000 --coverage --coverage-reporter=text --coverage-reporter=lcov --verbose",
19+
"test": "vitest run",
20+
"test-except-dind": "vitest run --exclude '**/dind-*/**'",
21+
"coverage": "vitest run --coverage",
2222
"start": "bun src/index.ts --cwd examples/docker-compose-nodejs",
2323
"typecheck": "tsc --noEmit",
2424
"fetch-schema": "curl https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json -sf > src/schema.json"
@@ -62,11 +62,13 @@
6262
"@types/semver": "7.x.x",
6363
"@types/split2": "4.x.x",
6464
"@types/yargs": "17.x.x",
65+
"@vitest/coverage-v8": "^4.0.18",
6566
"axios-mock-adapter": "2.x",
6667
"depcheck": "1.x.x",
6768
"eslint": "10.x",
6869
"typescript": "5.x.x",
69-
"typescript-eslint": "8.x.x"
70+
"typescript-eslint": "8.x.x",
71+
"vitest": "^4.0.18"
7072
},
7173
"repository": {
7274
"type": "git",

tests/cases.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {spyOn, beforeAll, afterAll, test, expect} from "bun:test";
1+
import {vi} from "vitest";
22
import {WriteStreamsMock} from "../src/write-streams.js";
33
import chalk from "chalk-template";
44
import {handler} from "../src/handler.js";
@@ -16,7 +16,7 @@ afterAll(() => {
1616
});
1717

1818
test("--completion", async () => {
19-
const spy = spyOn(console, "log").mockImplementation(() => {});
19+
const spy = vi.spyOn(console, "log").mockImplementation(() => {});
2020
const writeStreams = new WriteStreamsMock();
2121
await handler({
2222
completion: true,

tests/mocks/utils.mock.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {spyOn, expect} from "bun:test";
1+
import {vi, expect} from "vitest";
22
import {Utils} from "../../src/utils.js";
33

44
const originalBash = Utils.bash.bind(Utils);
@@ -21,7 +21,7 @@ let spawnRejectMocks: {cmdArgs: any[]; rejection: any}[] = [];
2121

2222
export function initBashSpy (spyMocks: {cmd: any; returnValue: any}[]) {
2323
bashMocks = spyMocks;
24-
const spy = spyOn(Utils, "bash");
24+
const spy = vi.spyOn(Utils, "bash");
2525
spy.mockImplementation(async (cmd: string, cwd?: string) => {
2626
for (const spyMock of bashMocks) {
2727
if (matches(cmd, spyMock.cmd)) return spyMock.returnValue;
@@ -33,7 +33,7 @@ export function initBashSpy (spyMocks: {cmd: any; returnValue: any}[]) {
3333

3434
export function initSyncSpawnSpy (spyMocks: {cmdArgs: string[]; returnValue: any}[]) {
3535
syncSpawnMocks = spyMocks;
36-
const spy = spyOn(Utils, "syncSpawn");
36+
const spy = vi.spyOn(Utils, "syncSpawn");
3737
spy.mockImplementation((cmdArgs: string[], cwd?: string) => {
3838
for (const spyMock of syncSpawnMocks) {
3939
if (matches(cmdArgs, spyMock.cmdArgs)) return spyMock.returnValue;
@@ -56,14 +56,14 @@ async function spawnMockImpl (cmdArgs: string[], cwd?: string) {
5656
export function initSpawnSpy (spyMocks: {cmdArgs: any[]; returnValue: any}[]) {
5757
spawnResolveMocks = spyMocks;
5858
spawnRejectMocks = [];
59-
const spy = spyOn(Utils, "spawn");
59+
const spy = vi.spyOn(Utils, "spawn");
6060
spy.mockImplementation(spawnMockImpl);
6161
return spy;
6262
}
6363

6464
export function initSpawnSpyReject (spyMocks: {cmdArgs: string[]; rejection: any}[]) {
6565
spawnRejectMocks = spyMocks;
66-
const spy = spyOn(Utils, "spawn");
66+
const spy = vi.spyOn(Utils, "spawn");
6767
spy.mockImplementation(spawnMockImpl);
6868
return spy;
6969
}

tests/process-write-streams.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {spyOn, afterEach, afterAll, test, expect} from "bun:test";
1+
import {vi} from "vitest";
22
import {WriteStreamsProcess} from "../src/write-streams.js";
33

4-
const spyStdout = spyOn(process.stdout, "write").mockImplementation(() => true);
5-
const spyStderr = spyOn(process.stderr, "write").mockImplementation(() => true);
4+
const spyStdout = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
5+
const spyStderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
66

77
afterEach(() => {
88
spyStdout.mockClear();

tests/rules-regex.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {spyOn, mock, beforeEach, describe, test, expect} from "bun:test";
1+
import {vi} from "vitest";
22
import "../src/global.js";
33
import {Argv} from "../src/argv";
44
import {Utils} from "../src/utils";
@@ -13,7 +13,7 @@ beforeEach(async () => {
1313
writeStreams = new WriteStreamsMock();
1414
gitData = await GitData.init("tests", writeStreams);
1515
argv = await Argv.build({}, writeStreams);
16-
mock.restore();
16+
vi.restoreAllMocks();
1717
});
1818

1919
/* eslint-disable @stylistic/quotes */
@@ -128,8 +128,8 @@ describe("gitlab rules regex", () => {
128128
.forEach((t) => {
129129
test(`- if: '${t.rule}'\n\t => ${t.evalResult}`, async () => {
130130
const rules = [ {if: t.rule} ];
131-
const evalSpy = spyOn(global, "eval");
132-
const evaluateRuleIfSpy = spyOn(Utils, "evaluateRuleIf");
131+
const evalSpy = vi.spyOn(global, "eval");
132+
const evaluateRuleIfSpy = vi.spyOn(Utils, "evaluateRuleIf");
133133

134134
Utils.getRulesResult({argv, cwd: "", rules, variables: {}}, gitData);
135135
expect(evaluateRuleIfSpy).toHaveReturnedWith(t.evalResult);

tests/test-cases/predefined-variables/integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {spyOn, type Mock, beforeAll, beforeEach, afterEach, afterAll, describe, test, expect} from "bun:test";
1+
import {vi, type Mock} from "vitest";
22
import {WriteStreamsMock} from "../../../src/write-streams.js";
33
import {handler} from "../../../src/handler.js";
44
import chalk from "chalk-template";
@@ -91,7 +91,7 @@ beforeAll(() => {
9191
returnValue: {stdout: "git@gitlab.com:GCL/predefined-variables.git"},
9292
};
9393
initSpawnSpy([...WhenStatics.all, spyGitRemote]);
94-
jobIdSpy = spyOn(
94+
jobIdSpy = vi.spyOn(
9595
Job.prototype as any,
9696
"generateJobId",
9797
);

0 commit comments

Comments
 (0)