mirror of
https://github.com/threeal/cmake-action.git
synced 2025-04-11 15:01:41 +00:00
test: use Vitest for testing (#564)
Some checks are pending
Build / Build Package (push) Waiting to run
Check / Check Package (push) Waiting to run
Test / Test Package (push) Waiting to run
Test / Test Action (macos-14) (push) Waiting to run
Test / Test Action (ubuntu-24.04) (push) Waiting to run
Test / Test Action (windows-2022) (push) Waiting to run
Test / Test Action With Specified Directories (push) Waiting to run
Test / Test Action Without Run Build (push) Waiting to run
Test / Test Action With Additional Options (push) Waiting to run
Test / Test Action With Custom Generator (push) Waiting to run
Some checks are pending
Build / Build Package (push) Waiting to run
Check / Check Package (push) Waiting to run
Test / Test Package (push) Waiting to run
Test / Test Action (macos-14) (push) Waiting to run
Test / Test Action (ubuntu-24.04) (push) Waiting to run
Test / Test Action (windows-2022) (push) Waiting to run
Test / Test Action With Specified Directories (push) Waiting to run
Test / Test Action Without Run Build (push) Waiting to run
Test / Test Action With Additional Options (push) Waiting to run
Test / Test Action With Custom Generator (push) Waiting to run
* test: use Vitest for testing Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * build: remove `esModuleInterop` option in TypeScript configuration Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> --------- Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
This commit is contained in:
parent
878c1020c1
commit
db9fa0b745
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"collectCoverage": true,
|
|
||||||
"coverageReporters": ["text"],
|
|
||||||
"coverageThreshold": {
|
|
||||||
"global": {
|
|
||||||
"branches": 100,
|
|
||||||
"functions": 100,
|
|
||||||
"lines": 100,
|
|
||||||
"statements": 100
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"moduleNameMapper": {
|
|
||||||
"^(\\.{1,2}/.*)\\.js$": "$1"
|
|
||||||
},
|
|
||||||
"preset": "ts-jest/presets/default-esm",
|
|
||||||
"transform": {
|
|
||||||
"^.+\\.ts$": ["ts-jest", { "useESM": true }]
|
|
||||||
},
|
|
||||||
"verbose": true
|
|
||||||
}
|
|
10
package.json
10
package.json
@ -6,26 +6,24 @@
|
|||||||
"build": "rollup -c",
|
"build": "rollup -c",
|
||||||
"format": "prettier --write --cache . !dist !README.md",
|
"format": "prettier --write --cache . !dist !README.md",
|
||||||
"lint": "eslint",
|
"lint": "eslint",
|
||||||
"test": "jest"
|
"test": "vitest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"gha-utils": "^0.4.1"
|
"gha-utils": "^0.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.17.0",
|
"@eslint/js": "^9.17.0",
|
||||||
"@jest/globals": "^29.7.0",
|
|
||||||
"@rollup/plugin-node-resolve": "^16.0.0",
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
||||||
"@rollup/plugin-typescript": "^12.1.2",
|
"@rollup/plugin-typescript": "^12.1.2",
|
||||||
"@types/jest": "^29.5.14",
|
|
||||||
"@types/node": "^22.10.2",
|
"@types/node": "^22.10.2",
|
||||||
|
"@vitest/coverage-v8": "^2.1.8",
|
||||||
"eslint": "^9.17.0",
|
"eslint": "^9.17.0",
|
||||||
"jest": "^29.7.0",
|
|
||||||
"prettier": "^3.4.2",
|
"prettier": "^3.4.2",
|
||||||
"rollup": "^4.29.1",
|
"rollup": "^4.29.1",
|
||||||
"ts-jest": "^29.2.5",
|
|
||||||
"tslib": "^2.8.1",
|
"tslib": "^2.8.1",
|
||||||
"typescript": "^5.7.2",
|
"typescript": "^5.7.2",
|
||||||
"typescript-eslint": "^8.19.0"
|
"typescript-eslint": "^8.19.0",
|
||||||
|
"vitest": "^2.1.8"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@4.5.3"
|
"packageManager": "yarn@4.5.3"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { jest } from "@jest/globals";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import { buildProject, configureProject } from "./cmake.js";
|
||||||
import type { Context } from "./context.js";
|
import type { Context } from "./context.js";
|
||||||
|
import { exec } from "./exec.js";
|
||||||
|
|
||||||
interface TestCase {
|
interface TestCase {
|
||||||
name: string;
|
name: string;
|
||||||
@ -21,9 +23,7 @@ const defaultContext: Context = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
jest.unstable_mockModule("./exec.js", () => ({
|
vi.mock("./exec.js", () => ({ exec: vi.fn() }));
|
||||||
exec: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("configure a CMake project", () => {
|
describe("configure a CMake project", () => {
|
||||||
const testCases: TestCase[] = [
|
const testCases: TestCase[] = [
|
||||||
@ -100,10 +100,7 @@ describe("configure a CMake project", () => {
|
|||||||
|
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
it(`should execute the correct command ${testCase.name}`, async () => {
|
it(`should execute the correct command ${testCase.name}`, async () => {
|
||||||
const { configureProject } = await import("./cmake.js");
|
vi.mocked(exec).mockReset();
|
||||||
const { exec } = await import("./exec.js");
|
|
||||||
|
|
||||||
jest.mocked(exec).mockReset();
|
|
||||||
|
|
||||||
await configureProject({ ...defaultContext, ...testCase.context });
|
await configureProject({ ...defaultContext, ...testCase.context });
|
||||||
|
|
||||||
@ -144,10 +141,7 @@ describe("build a CMake project", () => {
|
|||||||
|
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
it(`should execute the correct command ${testCase.name}`, async () => {
|
it(`should execute the correct command ${testCase.name}`, async () => {
|
||||||
const { buildProject } = await import("./cmake.js");
|
vi.mocked(exec).mockReset();
|
||||||
const { exec } = await import("./exec.js");
|
|
||||||
|
|
||||||
jest.mocked(exec).mockReset();
|
|
||||||
|
|
||||||
await buildProject({ ...defaultContext, ...testCase.context });
|
await buildProject({ ...defaultContext, ...testCase.context });
|
||||||
|
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
import { jest } from "@jest/globals";
|
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import type { Context } from "./context.js";
|
import type { Context } from "./context.js";
|
||||||
|
|
||||||
jest.unstable_mockModule("gha-utils", () => ({
|
vi.mock("gha-utils", () => ({ getInput: vi.fn() }));
|
||||||
getInput: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("get action context", () => {
|
describe("get action context", () => {
|
||||||
interface TestCase {
|
interface TestCase {
|
||||||
@ -186,9 +184,7 @@ describe("get action context", () => {
|
|||||||
const { getContext } = await import("./context.js");
|
const { getContext } = await import("./context.js");
|
||||||
|
|
||||||
const inputs = testCase.inputs || {};
|
const inputs = testCase.inputs || {};
|
||||||
jest.mocked(getInput).mockImplementation((name) => {
|
vi.mocked(getInput).mockImplementation((name) => inputs[name] ?? "");
|
||||||
return inputs[name] || "";
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(getContext()).toStrictEqual({
|
expect(getContext()).toStrictEqual({
|
||||||
sourceDir: "",
|
sourceDir: "",
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
import { jest } from "@jest/globals";
|
import { logCommand } from "gha-utils";
|
||||||
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { exec } from "./exec.js";
|
||||||
|
|
||||||
describe("execute commands", () => {
|
describe("execute commands", () => {
|
||||||
const logCommand = jest.fn<(command: string, ...args: string[]) => void>();
|
vi.mock("gha-utils", () => ({
|
||||||
jest.unstable_mockModule("gha-utils", () => ({ logCommand }));
|
logCommand: vi.fn<(command: string, ...args: string[]) => void>(),
|
||||||
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
logCommand.mockClear();
|
vi.mocked(logCommand).mockClear();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should successfully execute a command", async () => {
|
it("should successfully execute a command", async () => {
|
||||||
const { exec } = await import("./exec.js");
|
|
||||||
|
|
||||||
await exec("node", ["--version"]);
|
await exec("node", ["--version"]);
|
||||||
|
|
||||||
expect(logCommand).toHaveBeenCalledTimes(1);
|
expect(logCommand).toHaveBeenCalledTimes(1);
|
||||||
@ -18,8 +19,6 @@ describe("execute commands", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should fail to execute a command", async () => {
|
it("should fail to execute a command", async () => {
|
||||||
const { exec } = await import("./exec.js");
|
|
||||||
|
|
||||||
await expect(exec("node", ["--invalid"])).rejects.toThrow(
|
await expect(exec("node", ["--invalid"])).rejects.toThrow(
|
||||||
"Command exited with status code 9",
|
"Command exited with status code 9",
|
||||||
);
|
);
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"module": "node16",
|
"module": "node16",
|
||||||
"moduleResolution": "node16",
|
"moduleResolution": "node16",
|
||||||
"esModuleInterop": true,
|
|
||||||
"target": "es2022",
|
"target": "es2022",
|
||||||
"skipLibCheck": true
|
"skipLibCheck": true
|
||||||
}
|
}
|
||||||
|
13
vitest.config.ts
Normal file
13
vitest.config.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { defineConfig } from "vitest/config";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
watch: false,
|
||||||
|
coverage: {
|
||||||
|
all: false,
|
||||||
|
enabled: true,
|
||||||
|
reporter: ["text"],
|
||||||
|
thresholds: { 100: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user