Skip to content

Commit

Permalink
feat(): migrate to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
chyzwar committed Feb 13, 2024
1 parent f2481dc commit 12ebe78
Show file tree
Hide file tree
Showing 33 changed files with 859 additions and 2,204 deletions.
4 changes: 1 addition & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn commitlint --edit $1
yarn commitlint --edit "$1"
4 changes: 1 addition & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
yarn test
2 changes: 0 additions & 2 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
14 changes: 0 additions & 14 deletions jest.config.ts

This file was deleted.

27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
"lint:fix": "eslint . --ext .ts,.js,.tsx --fix",
"build": "tsc --build",
"build:watch": "tsc --build --watch",
"test": "jest",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch",
"postinstall": "husky install"
"test": "vitest --run",
"test:coverage": "vitest --coverage",
"test:watch": "vitest",
"postinstall": "husky install",
"prepare": "husky"
},
"dependencies": {
"@chyzwar/eslint-config": "^0.2.0",
"@commitlint/cli": "^18.5.0",
"@commitlint/config-conventional": "^18.5.0",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "18.6.0",
"@types/node": "^20.11.17",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"eslint": "^8.56.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^15.2.0",
"husky": "^9.0.10",
"lint-staged": "^15.2.2",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^1.2.2"
},
"lint-staged": {
"*.{js,ts,tsx}": "yarn lint:fix"
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-config/node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const findUp = require("find-up");

const eslint = require("./rules/eslint");
const jest = require("./rules/jest");
const typescript = require("./rules/typescript");
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
},
"dependencies": {
"@chyzwar/tsconfig": "^0.2.17",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-react-hooks": "^4.6.0",
"find-up": "^5.0.0"
Expand Down
19 changes: 0 additions & 19 deletions packages/runner/.swcrc

This file was deleted.

2 changes: 1 addition & 1 deletion packages/runner/examples/packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"@chyzwar/eslint-config": "^0.2.0",
"@chyzwar/tsconfig": "^0.2.0",
"eslint": "^8.56.0",
"fastify": "^4.25.2"
"fastify": "^4.26.1"
}
}
8 changes: 4 additions & 4 deletions packages/runner/examples/packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"preview": "vite preview"
},
"dependencies": {
"preact": "^10.19.3"
"preact": "^10.19.4"
},
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/core": "^7.23.9",
"@chyzwar/eslint-config": "^0.2.2",
"@chyzwar/tsconfig": "^0.2.2",
"@preact/preset-vite": "^2.8.1",
"eslint": "^8.56.0",
"preact": "^10.19.3",
"preact": "^10.19.4",
"typescript": "^5.3.3",
"vite": "^5.0.12"
"vite": "^5.1.1"
}
}
1 change: 0 additions & 1 deletion packages/runner/examples/packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"esnext"
],
"types": [
"jest",
"react",
"react-dom"
]
Expand Down
21 changes: 0 additions & 21 deletions packages/runner/jest.config.ts

This file was deleted.

13 changes: 5 additions & 8 deletions packages/runner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"build:watch": "tsc --build --watch",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --fix --ext .ts",
"test": "jest",
"test:watch": "jest --watch"
"test": "vitest --run",
"test:watch": "vitest"
},
"keywords": [
"task runner"
Expand All @@ -36,13 +36,10 @@
"devDependencies": {
"@chyzwar/eslint-config": "^0.2.17",
"@chyzwar/tsconfig": "^0.2.17",
"@jest/globals": "^29.7.0",
"@swc/core": "^1.3.105",
"@swc/jest": "^0.2.31",
"@types/node": "^20.11.5",
"@types/node": "^20.11.17",
"eslint": "^8.56.0",
"jest": "^29.7.0",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "^1.2.2"
},
"peerDependencies": {
"@types/node": "> 16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/src/__fixtures__/runner.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
/* eslint-disable no-undef */
import {task} from "../../lib";


task("test", () => {
console.log("test");
});
13 changes: 11 additions & 2 deletions packages/runner/src/__tests__/__snapshots__/runner.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`runner should load configuration form runner.config.js 1`] = `[]`;
exports[`runner > should load configuration from runner.config.js 1`] = `
[
[
"Completed tasks: test in ",
],
[
"Failed with error: Error: Missing tasks definition for: test",
],
]
`;
14 changes: 7 additions & 7 deletions packages/runner/src/__tests__/dockerTask.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {expect, jest, describe, it} from "@jest/globals";
import {expect, describe, it, vi} from "vitest";
import register from "../register.js";

jest.unstable_mockModule("node:child_process", () => {
vi.mock("node:child_process", () => {
return {
spawn: jest.fn().mockImplementation(() => {
spawn: vi.fn().mockImplementation(() => {
const handlers: Record<string, (arg: unknown) => void> = {};

const timeout = 10;
Expand All @@ -13,20 +13,20 @@ jest.unstable_mockModule("node:child_process", () => {

return {
stdout: {
on: jest.fn(),
on: vi.fn(),
},
stderr: {
on: jest.fn(),
on: vi.fn(),
},
on: jest.fn((name: string, handler: (arg: unknown) => void) => {
on: vi.fn((name: string, handler: (arg: unknown) => void) => {
handlers[name] = handler;
}),
};
}),
};
});

jest.unstable_mockModule("../Logger.js", async() => {
vi.mock("../Logger.js", async() => {
return import("../__mocks__/Logger.js");
});

Expand Down
6 changes: 3 additions & 3 deletions packages/runner/src/__tests__/mapToTasks.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {expect, jest, describe, it} from "@jest/globals";
import {expect, describe, it, vi} from "vitest";
import register from "../register.js";
import mapToTasks from "../mapToTasks.js";

describe("mapToTasks", () => {
it("should map to registered tasks", () => {
const task1 = jest.fn();
const task2 = jest.fn();
const task1 = vi.fn();
const task2 = vi.fn();
register.set("test1", task1);
register.set("test2", task2);

Expand Down
2 changes: 1 addition & 1 deletion packages/runner/src/__tests__/parallel.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, describe, it} from "@jest/globals";
import {expect, describe, it} from "vitest";

import register from "../register.js";
import {parallel} from "../parallel.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/runner/src/__tests__/register.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {describe, expect, it} from "@jest/globals";
import {expect, describe, it} from "vitest";
import register from "../register.js";

describe("register", () => {
Expand Down
16 changes: 11 additions & 5 deletions packages/runner/src/__tests__/runner.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
import {expect, jest, describe, it} from "@jest/globals";
import {expect, describe, it, vi} from "vitest";
import {dirname, resolve} from "node:path";
import {fileURLToPath} from "node:url";

jest.unstable_mockModule("node:process", () => {
vi.mock("node:process", () => {
const currentDir = dirname(fileURLToPath(import.meta.url));

return {
cwd: (): string => resolve(currentDir, "../__fixtures__"),
argv: [
"node",
"runner",
"test",
],
};
});

jest.unstable_mockModule("../Logger.js", async() => {
vi.mock("../Logger.js", async() => {
const mock = await import("../__mocks__/Logger.js");
return mock;
});

const Logger = await import("../Logger.js");

describe("runner", () => {
it("should load configuration form runner.config.js", async() => {
it("should load configuration from runner.config.js", async() => {
await import("../runner.js");

await vi.dynamicImportSettled();
expect(Logger.default.calls).toMatchSnapshot();
});
});
2 changes: 1 addition & 1 deletion packages/runner/src/__tests__/series.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expect, describe, it} from "@jest/globals";
import {expect, describe, it} from "vitest";
import register from "../register.js";
import {series} from "../series.js";

Expand Down
4 changes: 2 additions & 2 deletions packages/runner/src/__tests__/spawnTask.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {expect, jest, describe, it} from "@jest/globals";
import {expect, describe, it, vi} from "vitest";

import register from "../register.js";
import SpawnError from "../SpawnError.js";

jest.unstable_mockModule("../Logger.js", async() => {
vi.mock("../Logger.js", async() => {
return import("../__mocks__/Logger.js");
});

Expand Down
8 changes: 4 additions & 4 deletions packages/runner/src/__tests__/task.test.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {expect, jest, describe, it} from "@jest/globals";
import {expect, describe, it, vi} from "vitest";
import register from "../register.js";

jest.unstable_mockModule("../Logger.js", async() => {
vi.mock("../Logger.js", async() => {
return import("../__mocks__/Logger.js");
});

const {task} = await import("../task.js");

describe("task", () => {
it("should register new task", () => {
const ls = jest.fn();
const ls = vi.fn();
task("ls", ls);

expect(register.get("ls")).toBeInstanceOf(Function);
});

it("should execute task function when run", async() => {
const ls = jest.fn();
const ls = vi.fn();
task("ls", ls);

const run = register.get("ls");
Expand Down
1 change: 1 addition & 0 deletions packages/runner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export {seriesTask} from "./series.js";
export {spawnTask} from "./spawnTask.js";
export {dockerTask} from "./dockerTask.js";
export {execTask} from "./execTask.js";
export {task} from "./task.js";
export {parallelTask} from "./parallel.js";
Loading

0 comments on commit 12ebe78

Please sign in to comment.