Skip to content

Commit

Permalink
chore: Use vitest (#539)
Browse files Browse the repository at this point in the history
Replace jest with [Vitest](https://vitest.dev/).
  • Loading branch information
ueokande authored May 4, 2024
1 parent fa41f1d commit 8c84ae6
Show file tree
Hide file tree
Showing 7 changed files with 714 additions and 2,100 deletions.
6 changes: 0 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,3 @@ updates:
actions:
patterns:
- "@actions/*"
jest:
patterns:
- "jest"
- "jest-*"
- "ts-jest"
- "@types/jest"
1 change: 1 addition & 0 deletions __test__/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { afterEach, beforeEach, describe, expect, test } from "vitest";
import { cacheDir, find } from "../src/cache";

const mkdir = (dir: string) => fs.promises.mkdir(dir, { recursive: true });
Expand Down
1 change: 1 addition & 0 deletions __test__/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from "vitest";
import { isReleaseChannelName, parse } from "../src/version";

describe("isReleaseChannelName", () => {
Expand Down
37 changes: 21 additions & 16 deletions __test__/version_installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@ import fs from "node:fs";
import path from "node:path";
import * as httpm from "@actions/http-client";
import * as tc from "@actions/tool-cache";
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
import * as cache from "../src/cache";
import {
KnownGoodVersionInstaller,
KnownGoodVersionResolver,
} from "../src/version_installer";

describe("VersionResolver", () => {
const getJsonSpy = jest.spyOn(httpm.HttpClient.prototype, "getJson");
const getJsonSpy = vi.spyOn(httpm.HttpClient.prototype, "getJson");

beforeEach(() => {
const mockDataPath = path.join(
__dirname,
"data/known-good-versions-with-downloads.json",
);
beforeEach(() => {
const mockDataPath = path.join(
__dirname,
"data/known-good-versions-with-downloads.json",
);

getJsonSpy.mockImplementation(async () => {
return {
statusCode: 200,
headers: {},
result: JSON.parse(await fs.promises.readFile(mockDataPath, "utf-8")),
};
});
getJsonSpy.mockImplementation(async () => {
return {
statusCode: 200,
headers: {},
result: JSON.parse(await fs.promises.readFile(mockDataPath, "utf-8")),
};
});
});

afterEach(() => {
vi.resetAllMocks();
});

describe("VersionResolver", () => {
test.each`
spec | resolved
${"120.0.6099.5"} | ${"120.0.6099.5"}
Expand Down Expand Up @@ -54,8 +59,8 @@ describe("VersionResolver", () => {
});

describe("KnownGoodVersionInstaller", () => {
const tcFindSpy = jest.spyOn(cache, "find");
const tcDownloadToolSpy = jest.spyOn(tc, "downloadTool");
const tcFindSpy = vi.spyOn(cache, "find");
const tcDownloadToolSpy = vi.spyOn(tc, "downloadTool");

test("should return installed path if installed", async () => {
tcFindSpy.mockImplementation((name: string, version: string) => {
Expand Down
11 changes: 0 additions & 11 deletions jest.config.js

This file was deleted.

10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
},
"devDependencies": {
"@biomejs/biome": "^1.7.2",
"@types/jest": "^29.5.10",
"@types/node": "^20.6.2",
"@vercel/ncc": "^0.38.1",
"jest": "^29.7.0",
"jest-circus": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^1.6.0"
},
"scripts": {
"build": "ncc build src/index.ts",
"package": "cp action.yml README.md dist/",
"test": "jest",
"test:watch": "jest --watch",
"test": "vitest",
"lint": "biome ci .",
"lint:fix": "biome check --apply ."
},
Expand Down
Loading

0 comments on commit 8c84ae6

Please sign in to comment.