Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(grout/test-utils): replace jest with vitest #5762

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/grout/test-utils/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.js
*.d.ts
vitest.config.ts
build
coverage
8 changes: 0 additions & 8 deletions libs/grout/test-utils/jest.config.js

This file was deleted.

13 changes: 5 additions & 8 deletions libs/grout/test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,23 @@
"lint:fix": "pnpm type-check && eslint . --fix",
"pre-commit": "lint-staged",
"test": "is-ci test:ci test:watch",
"test:ci": "jest --coverage --reporters=default --reporters=jest-junit --maxWorkers=6",
"test:coverage": "jest --coverage",
"test:watch": "jest --watch",
"test:ci": "vitest run --coverage",
"test:coverage": "vitest --coverage",
"test:watch": "vitest",
"type-check": "tsc --build"
},
"dependencies": {
"@votingworks/test-utils": "workspace:*"
},
"devDependencies": {
"@types/jest": "^29.5.3",
"@vitest/coverage-istanbul": "^2.1.8",
"@votingworks/grout": "workspace:*",
"eslint-plugin-vx": "workspace:*",
"expect-type": "^0.15.0",
"is-ci-cli": "2.2.0",
"jest": "^29.6.2",
"jest-junit": "^16.0.0",
"jest-watch-typeahead": "^2.2.2",
"lint-staged": "11.0.0",
"sort-package-json": "^1.50.0",
"ts-jest": "29.1.1"
"vitest": "^2.1.8"
},
"peerDependencies": {
"@votingworks/grout": "workspace:*"
Expand Down
11 changes: 6 additions & 5 deletions libs/grout/test-utils/src/mock_client.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test, vi } from 'vitest';
import { MockFunction } from '@votingworks/test-utils';
import { expectTypeOf } from 'expect-type';
import { createApi, createClient } from '@votingworks/grout';
Expand Down Expand Up @@ -32,12 +33,12 @@ test('catches exceptions from mock function failures and logs them', async () =>
const mockClient = createMockClient<typeof api>({
catchUnexpectedErrors: true,
});
const consoleErrorMock = jest.fn();
const consoleErrorMock = vi.fn();
// eslint-disable-next-line no-console
console.error = consoleErrorMock;
await mockClient.add({ num1: 1, num2: 2 });
expect(consoleErrorMock).toHaveBeenCalledTimes(1);
expect(consoleErrorMock.mock.calls[0][0]).toMatchInlineSnapshot(
expect(consoleErrorMock.mock.calls[0]![0]).toMatchInlineSnapshot(
`"Unexpected call to mock function: add({ num1: 1, num2: 2 })"`
);
});
Expand All @@ -46,7 +47,7 @@ test('doesnt catch intentional exceptions from mock functions', () => {
const mockClient = createMockClient<typeof api>({
catchUnexpectedErrors: true,
});
const consoleErrorMock = jest.fn();
const consoleErrorMock = vi.fn();
// eslint-disable-next-line no-console
console.error = consoleErrorMock;
mockClient.add
Expand All @@ -66,10 +67,10 @@ test('asserts complete for all methods', async () => {
await expect(mockClient.add({ num1: 1, num2: 2 })).resolves.toEqual(42);

expect(() => mockClient.assertComplete()).toThrowErrorMatchingInlineSnapshot(`
"Mismatch between expected mock function calls and actual mock function calls:
[Error: Mismatch between expected mock function calls and actual mock function calls:

Call #0
Expected: sqrt({ num: 4 })
Actual: <none>"
Actual: <none>]
`);
});
6 changes: 3 additions & 3 deletions libs/grout/test-utils/src/mock_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ type AnyMockFunction = MockFunction<any>;

function createSafeMockMethod(methodName: string): AnyMockFunction {
// API methods are sometimes called without exception handling, which can
// cause cause jest to exit early and swallow the error. So we wrap the
// mock method in a proxy that catches any exceptions and logs them to the
// console instead.
// cause cause tests to exit early and swallow the error. So we wrap the mock
// method in a proxy that catches any exceptions and logs them to the console
// instead.
return new Proxy(mockFunction(methodName), {
apply: (target, thisArg, args) => {
try {
Expand Down
3 changes: 3 additions & 0 deletions libs/grout/test-utils/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from '../../../vitest.config.shared.mjs';

export default defineConfig();
21 changes: 6 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.