From ee9d8d8490d95652a1ccdf6b34fcb52034593b9d Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:11:12 -0800 Subject: [PATCH] test(ballot-interpreter): use `vitest` API --- libs/ballot-interpreter/src/adjudication_reasons.test.ts | 1 + libs/ballot-interpreter/src/bmd/interpret.test.tsx | 1 + libs/ballot-interpreter/src/bmd/utils/qrcode.test.ts | 1 + libs/ballot-interpreter/src/bmd/utils/rotate.test.ts | 1 + libs/ballot-interpreter/src/hmpb-ts/cli.test.ts | 1 + libs/ballot-interpreter/src/hmpb-ts/debug.test.ts | 6 ++---- libs/ballot-interpreter/src/hmpb-ts/diagnostic.test.ts | 1 + .../src/hmpb-ts/find_template_grid_and_bubbles.test.ts | 1 + libs/ballot-interpreter/src/hmpb-ts/interpret.test.ts | 1 + libs/ballot-interpreter/src/hmpb-ts/types.test.ts | 1 + .../src/interpret_all_bubble_ballot.test.ts | 1 + .../ballot-interpreter/src/interpret_and_save_files.test.ts | 1 + .../src/interpret_bmd_and_hmp_ballots.test.ts | 1 + libs/ballot-interpreter/src/interpret_bmd_ballots.test.ts | 3 ++- libs/ballot-interpreter/src/interpret_nh_hmpb.test.ts | 3 ++- libs/ballot-interpreter/src/interpret_vx_hmpb.test.ts | 3 ++- libs/ballot-interpreter/src/save_images.test.ts | 1 + libs/ballot-interpreter/src/setupTests.ts | 1 + libs/ballot-interpreter/src/validation.test.ts | 1 + libs/ballot-interpreter/test/helpers/tmp.ts | 1 + 20 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libs/ballot-interpreter/src/adjudication_reasons.test.ts b/libs/ballot-interpreter/src/adjudication_reasons.test.ts index df9343acb6..415b162878 100644 --- a/libs/ballot-interpreter/src/adjudication_reasons.test.ts +++ b/libs/ballot-interpreter/src/adjudication_reasons.test.ts @@ -1,3 +1,4 @@ +import { describe, expect, test } from 'vitest'; import { AdjudicationReason, AdjudicationReasonInfo, diff --git a/libs/ballot-interpreter/src/bmd/interpret.test.tsx b/libs/ballot-interpreter/src/bmd/interpret.test.tsx index 7f9c9381db..c8ec7f6f28 100644 --- a/libs/ballot-interpreter/src/bmd/interpret.test.tsx +++ b/libs/ballot-interpreter/src/bmd/interpret.test.tsx @@ -1,3 +1,4 @@ +import { beforeAll, expect, test } from 'vitest'; import { sliceBallotHashForEncoding } from '@votingworks/ballot-encoder'; import { assert, err } from '@votingworks/basics'; import { diff --git a/libs/ballot-interpreter/src/bmd/utils/qrcode.test.ts b/libs/ballot-interpreter/src/bmd/utils/qrcode.test.ts index b22521a5c4..09bd3fc3ff 100644 --- a/libs/ballot-interpreter/src/bmd/utils/qrcode.test.ts +++ b/libs/ballot-interpreter/src/bmd/utils/qrcode.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { Buffer } from 'node:buffer'; import { err, ok } from '@votingworks/basics'; import { diff --git a/libs/ballot-interpreter/src/bmd/utils/rotate.test.ts b/libs/ballot-interpreter/src/bmd/utils/rotate.test.ts index 0fbe297b3e..373579c1d5 100644 --- a/libs/ballot-interpreter/src/bmd/utils/rotate.test.ts +++ b/libs/ballot-interpreter/src/bmd/utils/rotate.test.ts @@ -1,3 +1,4 @@ +import { test } from 'vitest'; import { assert } from '@votingworks/basics'; import { sampleBallotImages } from '@votingworks/fixtures'; import { ImageData } from 'canvas'; diff --git a/libs/ballot-interpreter/src/hmpb-ts/cli.test.ts b/libs/ballot-interpreter/src/hmpb-ts/cli.test.ts index 1ec147a2b2..6d99f2d2f4 100644 --- a/libs/ballot-interpreter/src/hmpb-ts/cli.test.ts +++ b/libs/ballot-interpreter/src/hmpb-ts/cli.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { electionGridLayoutNewHampshireTestBallotFixtures } from '@votingworks/fixtures'; import { DEFAULT_SYSTEM_SETTINGS } from '@votingworks/types'; import { dirSync, fileSync } from 'tmp'; diff --git a/libs/ballot-interpreter/src/hmpb-ts/debug.test.ts b/libs/ballot-interpreter/src/hmpb-ts/debug.test.ts index 2145137de8..0745054dcb 100644 --- a/libs/ballot-interpreter/src/hmpb-ts/debug.test.ts +++ b/libs/ballot-interpreter/src/hmpb-ts/debug.test.ts @@ -1,3 +1,4 @@ +import { beforeAll, expect, test, vi } from 'vitest'; import { ImageData } from 'canvas'; import { electionGridLayoutNewHampshireTestBallotFixtures } from '@votingworks/fixtures'; import * as addon from './addon'; @@ -5,10 +6,7 @@ import { interpret } from './interpret'; jest.mock('./addon'); -const interpretImplMock = addon.interpret as jest.MockedFunction< - typeof addon.interpret ->; - +const interpretImplMock = vi.mocked(addon.interpret); let frontImageData!: ImageData; let backImageData!: ImageData; diff --git a/libs/ballot-interpreter/src/hmpb-ts/diagnostic.test.ts b/libs/ballot-interpreter/src/hmpb-ts/diagnostic.test.ts index 4598dd52e0..916019bb67 100644 --- a/libs/ballot-interpreter/src/hmpb-ts/diagnostic.test.ts +++ b/libs/ballot-interpreter/src/hmpb-ts/diagnostic.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { join } from 'node:path'; import { runBlankPaperDiagnostic } from './diagnostic'; diff --git a/libs/ballot-interpreter/src/hmpb-ts/find_template_grid_and_bubbles.test.ts b/libs/ballot-interpreter/src/hmpb-ts/find_template_grid_and_bubbles.test.ts index 8ac40d0bba..4b50622f26 100644 --- a/libs/ballot-interpreter/src/hmpb-ts/find_template_grid_and_bubbles.test.ts +++ b/libs/ballot-interpreter/src/hmpb-ts/find_template_grid_and_bubbles.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { ImageData } from 'canvas'; import { err } from '@votingworks/basics'; import { diff --git a/libs/ballot-interpreter/src/hmpb-ts/interpret.test.ts b/libs/ballot-interpreter/src/hmpb-ts/interpret.test.ts index 6281974b4c..883f3a55fc 100644 --- a/libs/ballot-interpreter/src/hmpb-ts/interpret.test.ts +++ b/libs/ballot-interpreter/src/hmpb-ts/interpret.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { assertDefined, iter, ok, unique } from '@votingworks/basics'; import { ImageData } from 'canvas'; import { electionGridLayoutNewHampshireTestBallotFixtures } from '@votingworks/fixtures'; diff --git a/libs/ballot-interpreter/src/hmpb-ts/types.test.ts b/libs/ballot-interpreter/src/hmpb-ts/types.test.ts index 8c08637e25..ddbd382029 100644 --- a/libs/ballot-interpreter/src/hmpb-ts/types.test.ts +++ b/libs/ballot-interpreter/src/hmpb-ts/types.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { BallotSide } from './types'; test('has BallotSide enum', () => { diff --git a/libs/ballot-interpreter/src/interpret_all_bubble_ballot.test.ts b/libs/ballot-interpreter/src/interpret_all_bubble_ballot.test.ts index bcab82aac5..94bc2105eb 100644 --- a/libs/ballot-interpreter/src/interpret_all_bubble_ballot.test.ts +++ b/libs/ballot-interpreter/src/interpret_all_bubble_ballot.test.ts @@ -1,3 +1,4 @@ +import { beforeAll, describe, expect, test } from 'vitest'; import { assert, Optional } from '@votingworks/basics'; import { readElection } from '@votingworks/fs'; import { allBubbleBallotFixtures } from '@votingworks/hmpb'; diff --git a/libs/ballot-interpreter/src/interpret_and_save_files.test.ts b/libs/ballot-interpreter/src/interpret_and_save_files.test.ts index a04b8855d4..704f283133 100644 --- a/libs/ballot-interpreter/src/interpret_and_save_files.test.ts +++ b/libs/ballot-interpreter/src/interpret_and_save_files.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { DEFAULT_FAMOUS_NAMES_BALLOT_STYLE_ID, DEFAULT_FAMOUS_NAMES_PRECINCT_ID, diff --git a/libs/ballot-interpreter/src/interpret_bmd_and_hmp_ballots.test.ts b/libs/ballot-interpreter/src/interpret_bmd_and_hmp_ballots.test.ts index 2195443d07..1b6a779371 100644 --- a/libs/ballot-interpreter/src/interpret_bmd_and_hmp_ballots.test.ts +++ b/libs/ballot-interpreter/src/interpret_bmd_and_hmp_ballots.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { renderBmdBallotFixture } from '@votingworks/bmd-ballot-fixtures'; import { readElection } from '@votingworks/fs'; import { famousNamesFixtures } from '@votingworks/hmpb'; diff --git a/libs/ballot-interpreter/src/interpret_bmd_ballots.test.ts b/libs/ballot-interpreter/src/interpret_bmd_ballots.test.ts index d04ad700ec..92ae437d40 100644 --- a/libs/ballot-interpreter/src/interpret_bmd_ballots.test.ts +++ b/libs/ballot-interpreter/src/interpret_bmd_ballots.test.ts @@ -1,3 +1,4 @@ +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; import { sliceBallotHashForEncoding } from '@votingworks/ballot-encoder'; import { DEFAULT_ELECTION_GENERAL_BALLOT_STYLE_ID, @@ -42,7 +43,7 @@ import { interpretSheet, interpretSimplexBmdBallot } from './interpret'; import { InterpreterOptions } from './types'; import { normalizeBallotMode } from './validation'; -jest.mock('./validation'); +vi.mock('./validation'); beforeEach(() => { mockOf(normalizeBallotMode).mockImplementation((input) => input); diff --git a/libs/ballot-interpreter/src/interpret_nh_hmpb.test.ts b/libs/ballot-interpreter/src/interpret_nh_hmpb.test.ts index 27039b0184..d3710c1ac0 100644 --- a/libs/ballot-interpreter/src/interpret_nh_hmpb.test.ts +++ b/libs/ballot-interpreter/src/interpret_nh_hmpb.test.ts @@ -1,3 +1,4 @@ +import { beforeEach, describe, expect, test, vi } from 'vitest'; import { assert, unique } from '@votingworks/basics'; import { electionGridLayoutNewHampshireTestBallotFixtures, @@ -24,7 +25,7 @@ import { interpretSheet } from './interpret'; import { InterpreterOptions } from './types'; import { normalizeBallotMode } from './validation'; -jest.mock('./validation'); +vi.mock('./validation'); beforeEach(() => { mockOf(normalizeBallotMode).mockImplementation((input) => input); diff --git a/libs/ballot-interpreter/src/interpret_vx_hmpb.test.ts b/libs/ballot-interpreter/src/interpret_vx_hmpb.test.ts index a0a4fb4d18..806a1f1a0b 100644 --- a/libs/ballot-interpreter/src/interpret_vx_hmpb.test.ts +++ b/libs/ballot-interpreter/src/interpret_vx_hmpb.test.ts @@ -1,3 +1,4 @@ +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; import { sliceBallotHashForEncoding } from '@votingworks/ballot-encoder'; import { assert, assertDefined, iter } from '@votingworks/basics'; import { readElection } from '@votingworks/fs'; @@ -32,7 +33,7 @@ import { interpretSheet } from './interpret'; import { InterpreterOptions } from './types'; import { normalizeBallotMode } from './validation'; -jest.mock('./validation'); +vi.mock('./validation'); beforeEach(() => { mockOf(normalizeBallotMode).mockImplementation((input) => input); diff --git a/libs/ballot-interpreter/src/save_images.test.ts b/libs/ballot-interpreter/src/save_images.test.ts index 764af2d8ea..d0bd9ef155 100644 --- a/libs/ballot-interpreter/src/save_images.test.ts +++ b/libs/ballot-interpreter/src/save_images.test.ts @@ -1,3 +1,4 @@ +import { expect, test } from 'vitest'; import { createImageData, ImageData } from '@votingworks/image-utils'; import { SheetOf } from '@votingworks/types'; import { join } from 'node:path'; diff --git a/libs/ballot-interpreter/src/setupTests.ts b/libs/ballot-interpreter/src/setupTests.ts index 579dbe11f8..2adc7ff74c 100644 --- a/libs/ballot-interpreter/src/setupTests.ts +++ b/libs/ballot-interpreter/src/setupTests.ts @@ -1,3 +1,4 @@ +import { expect } from 'vitest'; import { toMatchImageSnapshot } from 'jest-image-snapshot'; expect.extend({ toMatchImageSnapshot }); diff --git a/libs/ballot-interpreter/src/validation.test.ts b/libs/ballot-interpreter/src/validation.test.ts index ae2b2a45ec..9b87b56742 100644 --- a/libs/ballot-interpreter/src/validation.test.ts +++ b/libs/ballot-interpreter/src/validation.test.ts @@ -1,3 +1,4 @@ +import { describe, expect, test } from 'vitest'; import { electionGeneralDefinition } from '@votingworks/fixtures'; import { BallotId, diff --git a/libs/ballot-interpreter/test/helpers/tmp.ts b/libs/ballot-interpreter/test/helpers/tmp.ts index 04e04b0050..0565e0f157 100644 --- a/libs/ballot-interpreter/test/helpers/tmp.ts +++ b/libs/ballot-interpreter/test/helpers/tmp.ts @@ -1,3 +1,4 @@ +import { afterAll } from 'vitest'; import { removeSync } from 'fs-extra'; import { dirSync } from 'tmp';