Skip to content

Commit

Permalink
replace: jest to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
kobakazu0429 committed Nov 6, 2023
1 parent 2110e50 commit ecef3f7
Show file tree
Hide file tree
Showing 3 changed files with 537 additions and 1,976 deletions.
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint": "tsc --noEmit && npm run lint:eslint && npm run lint:prettier",
"lint:eslint": "eslint \"./{src,test}/**/*.{js,ts,tsx,svelte}\" --fix",
"lint:prettier": "prettier \"./{src,test}/**/*.{js,ts,tsx,svelte}\" --write",
"test": "jest",
"test": "vitest",
"check": "svelte-check"
},
"devDependencies": {
Expand All @@ -24,14 +24,12 @@
"@rollup/plugin-node-resolve": "15.0.1",
"@sveltejs/vite-plugin-svelte": "1.1.1",
"@tsconfig/svelte": "5.0.2",
"@types/jest": "29.2.4",
"@types/node": "18.11.12",
"@types/wicg-file-system-access": "2020.9.5",
"@wessberg/rollup-plugin-ts": "2.0.4",
"autoprefixer": "10.4.13",
"carbon-preprocess-svelte": "0.9.1",
"eslint": "8.26.0",
"jest": "29.2.2",
"postcss": "8.4.19",
"rollup": "3.2.5",
"rollup-plugin-svelte": "7.1.0",
Expand All @@ -40,10 +38,10 @@
"svelte-check": "2.9.2",
"svelte-preprocess": "4.10.7",
"terser": "^5.15.1",
"ts-jest": "29.0.3",
"tslib": "2.4.1",
"typescript": "5.2.2",
"vite": "3.2.5"
"vite": "3.2.5",
"vitest": "^0.34.6"
},
"dependencies": {
"@kobakazu0429/test": "1.0.10",
Expand Down
95 changes: 84 additions & 11 deletions src/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, test, expect } from "vitest";
import { run, constructResultsHTML } from "@kobakazu0429/test";
// import { testBuilder } from "./index";
import { testBuilder } from "./index";
import type { Test } from "./index";

const tests: Test[] = [
Expand Down Expand Up @@ -27,18 +28,90 @@ const tests: Test[] = [
},
];

// function add(a: number, b: number) {
// return a + b;
// }
function add(a: number, b: number) {
return a + b;
}

// function div(a: number, b: number) {
// return a / b;
// }
function div(a: number, b: number) {
return a / b;
}

describe("jest", () => {
test.skip("testBuilder", async () => {
// testBuilder(tests, { add, div })();
const result = await run();
expect(constructResultsHTML(result)).toMatchInlineSnapshot();
describe("testBuilder", () => {
const timeRegExp = /\s*Time: \d+.\d+ \[s\]\s*/g;
test.skip("PASS", async () => {
testBuilder(tests, { add, div }, new ArrayBuffer(0))();
const result = await run();
const html = constructResultsHTML(result).trim().replace(timeRegExp, "");
expect(html).toMatchInlineSnapshot(`
"<div class=\\"test-report__result\\">
<span class=\\"test-report__status-icon\\">✓</span>
<span class=\\"test-report__status test-report__status--pass\\">
PASS
</span>
add(1, 2) should be 3
</div>
<div class=\\"test-report__result\\">
<span class=\\"test-report__status-icon\\">✓</span>
<span class=\\"test-report__status test-report__status--pass\\">
PASS
</span>
div(8, 2) should be 4
</div>
<span class=\\"test-report__summary-status test-report__summary-status--pass\\">
Tests: 0 failed, 2 passed, 2 total<br></span>"
`);
});

test("FAIL", async () => {
testBuilder(
tests,
{
add: function add(a: number, b: number) {
return a - b;
},
div,
},
new ArrayBuffer(0)
)();
const result = await run();
const html = constructResultsHTML(result).replace(timeRegExp, "");
expect(html).toMatchInlineSnapshot(`
"
<div class=\\"test-report__result\\">
<span class=\\"test-report__status-icon\\">×</span>
<span class=\\"test-report__status test-report__status--fail\\">
FAIL
</span>
add(1, 2) should be 3
<div class=\\"test-report__errors\\">expected: 3, received: -1</div>
</div>
<div class=\\"test-report__result\\">
<span class=\\"test-report__status-icon\\">✓</span>
<span class=\\"test-report__status test-report__status--pass\\">
PASS
</span>
div(8, 2) should be 4
</div>
<span class=\\"test-report__summary-status test-report__summary-status--fail\\">
Tests: 1 failed, 1 passed, 2 total<br></span>
"
`);
});
});
});
Loading

0 comments on commit ecef3f7

Please sign in to comment.