Skip to content

Commit

Permalink
Replace jest with vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Nov 4, 2024
1 parent 8e66daa commit 06e0807
Show file tree
Hide file tree
Showing 8 changed files with 2,832 additions and 2,987 deletions.
4 changes: 0 additions & 4 deletions jest.config.js

This file was deleted.

5,604 changes: 2,728 additions & 2,876 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"sideEffects": false,
"scripts": {
"build": "rollup -c",
"test": "jest",
"test": "vitest run",
"tsc": "tsc -p . --noEmit",
"storybook": "storybook dev -p 6006",
"storybook:build": "storybook build",
Expand All @@ -33,9 +33,6 @@
"unist-util-visit": "^4.1.2"
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@rollup/plugin-typescript": "^11.1.6",
"@storybook/addon-storysource": "^8.4.0",
"@storybook/react": "^8.4.0",
Expand All @@ -46,11 +43,9 @@
"@types/mdast": "^3.0.10",
"@types/unist": "^2.0.6",
"adm-zip": "^0.5.9",
"babel-jest": "^29.0.2",
"concurrently": "^8.2.2",
"docx-preview": "^0.3.0",
"file-saver": "^2.0.5",
"jest": "^29.0.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-is": "^18.3.1",
Expand All @@ -67,7 +62,8 @@
"typedoc-plugin-markdown": "^3.16.0",
"typescript": "^5.0.4",
"unified": "^10.1.2",
"vite": "^5.2.11",
"vite": "^5.4.10",
"vitest": "^2.1.4",
"wait-on": "^7.2.0"
},
"repository": {
Expand Down
146 changes: 73 additions & 73 deletions src/__snapshots__/index.spec.ts.snap

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions src/__snapshots__/latex.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`parse \\f\\relax{x} = \\int_{-\\infty}^\\infty\\f\\hat\\xi\\,e^{2 \\pi i \\xi x}\\,d\\xi 1`] = `
exports[`parse > \\f\\relax{x} = \\int_{-\\infty}^\\infty\\f\\hat\\xi\\,e^{2 \\pi i \\xi x}\\,d\\xi 1`] = `
[
[
MathRun {
Expand Down Expand Up @@ -295,7 +295,7 @@ exports[`parse \\f\\relax{x} = \\int_{-\\infty}^\\infty\\f\\hat\\xi\\,e^{2 \\pi
]
`;

exports[`parse \\frac{a+b}{c+d} 1`] = `
exports[`parse > \\frac{a+b}{c+d} 1`] = `
[
[
MathFraction {
Expand Down Expand Up @@ -383,7 +383,7 @@ exports[`parse \\frac{a+b}{c+d} 1`] = `
]
`;

exports[`parse \\sqrt[30]{a+\\sqrt{b+c}} 1`] = `
exports[`parse > \\sqrt[30]{a+\\sqrt{b+c}} 1`] = `
[
[
MathRadical {
Expand Down Expand Up @@ -464,7 +464,7 @@ exports[`parse \\sqrt[30]{a+\\sqrt{b+c}} 1`] = `
]
`;

exports[`parse \\sum_{k=1}^{n} k=rac{n(n+1)}{2} 1`] = `
exports[`parse > \\sum_{k=1}^{n} k=rac{n(n+1)}{2} 1`] = `
[
[
MathSuperScript {
Expand Down Expand Up @@ -766,7 +766,7 @@ exports[`parse \\sum_{k=1}^{n} k= rac{n(n+1)}{2} 1`] = `
]
`;

exports[`parse L = \\frac{1}{2} \\rho v^2 S C_L 1`] = `
exports[`parse > L = \\frac{1}{2} \\rho v^2 S C_L 1`] = `
[
[
MathRun {
Expand Down Expand Up @@ -936,7 +936,7 @@ exports[`parse L = \\frac{1}{2} \\rho v^2 S C_L 1`] = `
]
`;

exports[`parse command greek1 1`] = `
exports[`parse > command > greek1 1`] = `
[
[
MathRun {
Expand Down Expand Up @@ -1207,7 +1207,7 @@ exports[`parse command greek1 1`] = `
]
`;

exports[`parse command greek2 1`] = `
exports[`parse > command > greek2 1`] = `
[
[
MathRun {
Expand Down Expand Up @@ -1269,7 +1269,7 @@ exports[`parse command greek2 1`] = `
]
`;

exports[`parse command greek3 1`] = `
exports[`parse > command > greek3 1`] = `
[
[
MathRun {
Expand Down Expand Up @@ -1397,7 +1397,7 @@ exports[`parse command greek3 1`] = `
]
`;

exports[`parse i hbar \\frac{partial psi}{partial t} = H psi(x,t) 1`] = `
exports[`parse > i hbar \\frac{partial psi}{partial t} = H psi(x,t) 1`] = `
[
[
MathRun {
Expand Down
15 changes: 4 additions & 11 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
jest,
beforeEach,
afterEach,
it,
describe,
expect,
} from "@jest/globals";
import { vitest, beforeEach, afterEach, it, describe, expect } from "vitest";
import fs from "fs";
import path from "path";
import { unified } from "unified";
Expand All @@ -21,10 +14,10 @@ const FIXTURE_PATH = "../fixtures";

// mock unique id
beforeEach(() => {
jest.spyOn(global.Math, "random").mockReturnValue(0.123456789);
vitest.spyOn(global.Math, "random").mockReturnValue(0.123456789);
});
afterEach(() => {
jest.spyOn(global.Math, "random").mockRestore();
vitest.spyOn(global.Math, "random").mockRestore();
});

describe("e2e", () => {
Expand All @@ -48,7 +41,7 @@ describe("e2e", () => {
filenames.forEach((filename) => {
it(filename, async () => {
const doc = await toDocxProcessor.process(
fs.readFileSync(path.join(fixturesDir, filename))
fs.readFileSync(path.join(fixturesDir, filename)),
);
const z = new Zip((await doc.result) as any);
for (const e of z.getEntries()) {
Expand Down
12 changes: 6 additions & 6 deletions src/latex.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { it, describe, expect } from "@jest/globals";
import { it, describe, expect } from "vitest";
import { parseLatex } from "./latex";

const parse = (str: string) => parseLatex(str);
Expand All @@ -21,20 +21,20 @@ describe("parse", () => {
it("greek1", () => {
expect(
parse(
"\\alpha\\beta\\gamma\\delta\\epsilon\\zeta\\eta\\theta\\iota\\kappa\\lambda\\mu\\nu\\xi o\\pi\\rho\\sigma\\tau\\upsilon\\phi\\chi\\psi\\omega"
)
"\\alpha\\beta\\gamma\\delta\\epsilon\\zeta\\eta\\theta\\iota\\kappa\\lambda\\mu\\nu\\xi o\\pi\\rho\\sigma\\tau\\upsilon\\phi\\chi\\psi\\omega",
),
).toMatchSnapshot();
});
it("greek2", () => {
expect(
parse("\\varepsilon\\vartheta\\varrho\\varsigma\\varphi")
parse("\\varepsilon\\vartheta\\varrho\\varsigma\\varphi"),
).toMatchSnapshot();
});
it("greek3", () => {
expect(
parse(
"\\Gamma\\Delta\\Theta\\Lambda\\Xi\\Pi\\Sigma\\Upsilon\\Phi\\Psi\\Omega"
)
"\\Gamma\\Delta\\Theta\\Lambda\\Xi\\Pi\\Sigma\\Upsilon\\Phi\\Psi\\Omega",
),
).toMatchSnapshot();
});
});
Expand Down
8 changes: 8 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {
root: "src",
clearMocks: true,
},
});

0 comments on commit 06e0807

Please sign in to comment.