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(scan): replace jest with vitest #5830

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion apps/scan/backend/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
build
jest.config.js
vitest.config.ts
coverage

public/vendor
33 changes: 0 additions & 33 deletions apps/scan/backend/jest.config.js

This file was deleted.

16 changes: 5 additions & 11 deletions apps/scan/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
"pre-commit": "lint-staged",
"start": "node ./build/index.js",
"test": "is-ci test:ci test:watch",
"test:ci": "TZ=America/Anchorage jest --coverage --reporters=default --reporters=jest-junit --maxWorkers=6",
"test:coverage": "TZ=America/Anchorage jest --coverage",
"test:debug": "TZ=America/Anchorage node --inspect-brk $(which jest) --runInBand --no-cache",
"test:watch": "TZ=America/Anchorage jest --watch",
"test:ci": "TZ=America/Anchorage vitest run --coverage",
"test:coverage": "TZ=America/Anchorage vitest --coverage",
"test:watch": "TZ=America/Anchorage vitest",
"type-check": "tsc --build"
},
"dependencies": {
Expand Down Expand Up @@ -64,12 +63,9 @@
"zod": "3.23.5"
},
"devDependencies": {
"@jest/globals": "^29.6.2",
"@jest/types": "^29.6.1",
"@types/debug": "4.1.8",
"@types/express": "4.17.14",
"@types/fs-extra": "11.0.1",
"@types/jest": "^29.5.3",
"@types/jest-image-snapshot": "^6.4.0",
"@types/luxon": "^3.0.0",
"@types/multer": "^1.4.7",
Expand All @@ -78,22 +74,20 @@
"@types/supertest": "^2.0.10",
"@types/tmp": "0.2.4",
"@types/uuid": "9.0.5",
"@vitest/coverage-istanbul": "^2.1.8",
"@votingworks/fixtures": "workspace:*",
"esbuild": "0.21.2",
"esbuild-runner": "2.2.2",
"eslint-plugin-vx": "workspace:*",
"fast-check": "2.23.2",
"is-ci-cli": "2.2.0",
"jest": "^29.6.2",
"jest-image-snapshot": "^6.4.0",
"jest-junit": "^16.0.0",
"jest-watch-typeahead": "^2.2.2",
"lint-staged": "11.0.0",
"nock": "^13.1.0",
"nodemon": "^3.1.7",
"sort-package-json": "^1.50.0",
"supertest": "^6.0.1",
"ts-jest": "29.1.1",
"vitest": "^2.1.8",
"wait-for-expect": "^3.0.2"
},
"engines": {
Expand Down
5 changes: 3 additions & 2 deletions apps/scan/backend/src/app_auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, beforeEach, expect, test, vi } from 'vitest';
import { DateTime } from 'luxon';
import { electionFamousNames2021Fixtures } from '@votingworks/fixtures';
import {
Expand Down Expand Up @@ -40,8 +41,8 @@ beforeAll(() => {

const mockFeatureFlagger = getFeatureFlagMock();

jest.mock('@votingworks/utils', (): typeof import('@votingworks/utils') => ({
...jest.requireActual('@votingworks/utils'),
vi.mock(import('@votingworks/utils'), async (importActual) => ({
...(await importActual()),
isFeatureFlagEnabled: (flag) => mockFeatureFlagger.isEnabled(flag),
}));

Expand Down
14 changes: 7 additions & 7 deletions apps/scan/backend/src/app_config.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeEach, expect, test, vi } from 'vitest';
import {
electionFamousNames2021Fixtures,
electionTwoPartyPrimaryFixtures,
Expand All @@ -13,7 +14,6 @@ import { err, ok } from '@votingworks/basics';
import {
mockElectionManagerUser,
mockSessionExpiresAt,
mockOf,
} from '@votingworks/test-utils';
import { mockElectionPackageFileTree } from '@votingworks/backend';
import { InsertedSmartCardAuthApi } from '@votingworks/auth';
Expand All @@ -31,20 +31,20 @@ import { PrecinctScannerPollsInfo } from '.';
const electionGeneralDefinition = readElectionGeneralDefinition();
const electionGeneral = electionGeneralDefinition.election;

jest.setTimeout(30_000);
vi.setConfig({ testTimeout: 30_000 });

const mockFeatureFlagger = getFeatureFlagMock();

jest.mock('@votingworks/utils', (): typeof import('@votingworks/utils') => ({
...jest.requireActual('@votingworks/utils'),
vi.mock(import('@votingworks/utils'), async (importActual) => ({
...(await importActual()),
isFeatureFlagEnabled: (flag) => mockFeatureFlagger.isEnabled(flag),
}));

function mockElectionManager(
mockAuth: InsertedSmartCardAuthApi,
electionDefinition: ElectionDefinition
) {
mockOf(mockAuth.getAuthStatus).mockImplementation(() =>
vi.mocked(mockAuth.getAuthStatus).mockImplementation(() =>
Promise.resolve({
status: 'logged_in',
user: mockElectionManagerUser({
Expand All @@ -56,7 +56,7 @@ function mockElectionManager(
}

function mockLoggedOut(mockAuth: InsertedSmartCardAuthApi) {
mockOf(mockAuth.getAuthStatus).mockImplementation(() =>
vi.mocked(mockAuth.getAuthStatus).mockImplementation(() =>
Promise.resolve({ status: 'logged_out', reason: 'no_card' })
);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ test('unconfiguring machine', async () => {
async ({ apiClient, mockUsbDrive, workspace, mockAuth, logger }) => {
await configureApp(apiClient, mockAuth, mockUsbDrive);

jest.spyOn(workspace, 'reset');
vi.spyOn(workspace, 'reset');

await apiClient.unconfigureElection();

Expand Down
28 changes: 13 additions & 15 deletions apps/scan/backend/src/app_diagnostics.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { beforeEach, expect, test, vi } from 'vitest';
import {
BooleanEnvironmentVariableName,
getFeatureFlagMock,
} from '@votingworks/utils';
import { err } from '@votingworks/basics';
import { LogEventId } from '@votingworks/logging';
import { DiagnosticRecord } from '@votingworks/types';
import { mockOf } from '@votingworks/test-utils';
import {
DiskSpaceSummary,
initializeGetWorkspaceDiskSpaceSummary,
Expand All @@ -14,12 +14,12 @@ import { withApp } from '../test/helpers/pdi_helpers';
import { TEST_PRINT_USER_FAIL_REASON } from './util/diagnostics';
import { configureApp } from '../test/helpers/shared_helpers';

jest.setTimeout(60_000);
vi.setConfig({ testTimeout: 60_000 });

const mockFeatureFlagger = getFeatureFlagMock();

jest.mock('@votingworks/utils', (): typeof import('@votingworks/utils') => ({
...jest.requireActual('@votingworks/utils'),
vi.mock(import('@votingworks/utils'), async (importActual) => ({
...(await importActual()),
isFeatureFlagEnabled: (flag) => mockFeatureFlagger.isEnabled(flag),
}));

Expand All @@ -30,24 +30,22 @@ beforeEach(() => {
});

const mockTime = new Date('2021-01-01T00:00:00.000');
jest.mock('./util/get_current_time', () => ({
vi.mock(import('./util/get_current_time.js'), async (importActual) => ({
...(await importActual()),
getCurrentTime: () => mockTime.getTime(),
}));

async function wrapWithFakeSystemTime<T>(fn: () => Promise<T>): Promise<T> {
jest.useFakeTimers().setSystemTime(mockTime.getTime());
vi.useFakeTimers().setSystemTime(mockTime.getTime());
const result = await fn();
jest.useRealTimers();
vi.useRealTimers();
return result;
}

jest.mock(
'@votingworks/backend',
(): typeof import('@votingworks/backend') => ({
...jest.requireActual('@votingworks/backend'),
initializeGetWorkspaceDiskSpaceSummary: jest.fn(),
})
);
vi.mock(import('@votingworks/backend'), async (importActual) => ({
...(await importActual()),
initializeGetWorkspaceDiskSpaceSummary: vi.fn(),
}));

const MOCK_DISK_SPACE_SUMMARY: DiskSpaceSummary = {
total: 10 * 1_000_000,
Expand All @@ -56,7 +54,7 @@ const MOCK_DISK_SPACE_SUMMARY: DiskSpaceSummary = {
};

beforeEach(() => {
mockOf(initializeGetWorkspaceDiskSpaceSummary).mockReturnValue(() =>
vi.mocked(initializeGetWorkspaceDiskSpaceSummary).mockReturnValue(() =>
Promise.resolve(MOCK_DISK_SPACE_SUMMARY)
);
});
Expand Down
7 changes: 4 additions & 3 deletions apps/scan/backend/src/app_export.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeEach, expect, test, vi } from 'vitest';
import {
getCastVoteRecordExportDirectoryPaths,
readCastVoteRecordExport,
Expand All @@ -15,12 +16,12 @@ import {
import { scanBallot, withApp } from '../test/helpers/pdi_helpers';
import { configureApp } from '../test/helpers/shared_helpers';

jest.setTimeout(30_000);
vi.setConfig({ testTimeout: 30_000 });

const mockFeatureFlagger = getFeatureFlagMock();

jest.mock('@votingworks/utils', (): typeof import('@votingworks/utils') => ({
...jest.requireActual('@votingworks/utils'),
vi.mock(import('@votingworks/utils'), async (importActual) => ({
...(await importActual()),
isFeatureFlagEnabled: (flag) => mockFeatureFlagger.isEnabled(flag),
}));

Expand Down
Loading