Skip to content

Commit

Permalink
Switch from Jest to Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Apr 26, 2024
1 parent 1633283 commit 9bb3cce
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 87 deletions.
25 changes: 2 additions & 23 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,8 @@ module.exports = {
"*.test.ts",
"*.test.tsx",
],
extends: ["plugin:jest/recommended"],
plugins: ["jest"],
env: {
jest: true,
},
rules: {
// focused tests that make it to CI will cause a build failure
"jest/no-focused-tests": "warn",

// allow expect inside fast-check tests
"jest/no-standalone-expect": [
"error",
{ additionalTestBlockFunctions: ["it.prop", "test.prop"] },
],

// allow custom expect functions
"jest/expect-expect": [
"warn",
{
assertFunctionNames: ["expect*"],
},
],
},
extends: ["plugin:vitest/recommended"],
plugins: ["vitest"],
},
],
};
15 changes: 0 additions & 15 deletions jest.config.js

This file was deleted.

11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,23 @@
"prepublishOnly": "tsc -p tsconfig.build.json"
},
"devDependencies": {
"@fast-check/jest": "^1.7.3",
"@jest/globals": "^29.7.0",
"@swc/jest": "^0.2.29",
"@types/jest": "^29.5.5",
"@fast-check/vitest": "^0.1.0",
"@types/ws": "^8.5.5",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"@vitest/coverage-v8": "^1.5.2",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^28.0.0",
"eslint-plugin-n": "^17.0.0",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.7.0",
"eslint-plugin-vitest": "^0.4.1",
"prettier": "^3.0.3",
"prettier-plugin-organize-imports": "^3.2.3",
"typescript": "^5.2.2",
"vite": "^5.2.10",
"vitest": "^1.5.2",
"ws": "^8.14.2"
}
}
2 changes: 1 addition & 1 deletion test/arbitrary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fc } from "@fast-check/jest";
import { fc } from "@fast-check/vitest";
import type { Matrix3x3 } from "../src/matrix.js";
import type { Vector3, Vector4 } from "../src/vector.js";

Expand Down
40 changes: 0 additions & 40 deletions test/jest/n_E2lat_lon.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fc, it } from "@fast-check/jest";
import { fc, it } from "@fast-check/vitest";
import { afterAll, beforeAll, describe, expect } from "vitest";
import { lat_lon2n_E } from "../../src/index.js";
import { arbitrary3dRotationMatrix, arbitraryLatLon } from "../arbitrary.js";
import {
Expand All @@ -22,7 +23,7 @@ describe("lat_lon2n_E()", () => {
arbitraryLatLon(),
fc.option(arbitrary3dRotationMatrix(), { nil: undefined }),
],
{ numRuns: Infinity },
{ interruptAfterTimeLimit: 5000, numRuns: Infinity },
)(
"matches the Python implementation",
async ([latitude, longitude], R_Ee) => {
Expand All @@ -49,5 +50,6 @@ describe("lat_lon2n_E()", () => {
expect(actual[1]).toBeCloseTo(expected[1], 10);
expect(actual[2]).toBeCloseTo(expected[2], 10);
},
6000,
);
});
45 changes: 45 additions & 0 deletions test/vitest/n_E2lat_lon.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { fc, it } from "@fast-check/vitest";
import { afterAll, beforeAll, describe, expect } from "vitest";
import { n_E2lat_lon } from "../../src/index.js";
import {
arbitrary3dRotationMatrix,
arbitrary3dUnitVector,
} from "../arbitrary.js";
import {
NvectorTestClient,
createNvectorTestClient,
} from "../nvector-test-api.js";

describe("n_E2lat_lon()", () => {
let nvectorTestClient: NvectorTestClient;

beforeAll(async () => {
nvectorTestClient = await createNvectorTestClient();
});

afterAll(() => {
nvectorTestClient?.close();
});

it.prop(
[
arbitrary3dUnitVector(),
fc.option(arbitrary3dRotationMatrix(), { nil: undefined }),
],
{ interruptAfterTimeLimit: 5000, numRuns: Infinity },
)(
"matches the Python implementation",
async (n_E, R_Ee) => {
const expected = await nvectorTestClient.n_E2lat_lon(n_E, R_Ee);

expect(expected).toMatchObject([expect.any(Number), expect.any(Number)]);

const actual = n_E2lat_lon(n_E, R_Ee);

expect(actual).toMatchObject([expect.any(Number), expect.any(Number)]);
expect(actual[0]).toBeCloseTo(expected[0], 10);
expect(actual[1]).toBeCloseTo(expected[1], 10);
},
6000,
);
});
10 changes: 10 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "vite";

export default defineConfig({
test: {
include: ["test/vitest/**/*.spec.ts"],
coverage: {
include: ["src/**/*.ts"],
},
},
});

0 comments on commit 9bb3cce

Please sign in to comment.