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(ballot-interpreter): switch from jest to vitest #5705

Merged
merged 12 commits into from
Dec 10, 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
2 changes: 1 addition & 1 deletion libs/ballot-interpreter/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
build
coverage
jest.config.js
vitest.config.mts
2 changes: 1 addition & 1 deletion libs/ballot-interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ballot-interpreter"
version = "0.1.0"
edition = "2021"
exclude = ["build/rust_addon.node"]
exclude = ["build/addon.node"]

[lib]
crate-type = ["cdylib", "rlib"]
Expand Down
3 changes: 1 addition & 2 deletions libs/ballot-interpreter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ $ pnpm build

This command uses the
[cargo-cp-artifact](https://github.com/neon-bindings/cargo-cp-artifact) utility
to run the Rust build and copy the built library into
`./build/hmpb-ts/rust_addon.node`.
to run the Rust build and copy the built library into `./build/addon.node`.

## CLI

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable vx/gts-safe-number-parse */
/* eslint-disable import/no-extraneous-dependencies, vx/gts-safe-number-parse */
import { expect } from 'vitest';
import { assertDefined, iter, range } from '@votingworks/basics';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, test } from 'vitest';
import { assertDefined } from '@votingworks/basics';
import { readElection } from '@votingworks/fs';
import { famousNamesFixtures } from '@votingworks/hmpb';
Expand All @@ -14,11 +15,9 @@ import {
renderBmdBallotFixture,
} from '@votingworks/bmd-ballot-fixtures';
import { electionFamousNames2021Fixtures } from '@votingworks/fixtures';
import { interpretSheet } from '../src';
import { pdfToPageImages } from '../test/helpers/interpretation';
import { benchmarkRegressionTest } from './benchmarking';

jest.setTimeout(60_000);
import { interpretSheet } from '../src/index.js';
import { pdfToPageImages } from '../test/helpers/interpretation.mjs';
import { benchmarkRegressionTest } from './benchmarking.mjs';

describe('Interpretation benchmark', () => {
const { electionPath, precinctId } = famousNamesFixtures;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { beforeAll, describe, test } from 'vitest';
import { assertDefined } from '@votingworks/basics';
import { readElection } from '@votingworks/fs';
import { famousNamesFixtures } from '@votingworks/hmpb';
Expand All @@ -7,11 +8,9 @@ import {
ElectionDefinition,
} from '@votingworks/types';
import { singlePrecinctSelectionFor } from '@votingworks/utils';
import { interpretSheet } from '../src';
import { pdfToPageImages } from '../test/helpers/interpretation';
import { benchmarkRegressionTest } from './benchmarking';

jest.setTimeout(60_000);
import { interpretSheet } from '../src/index.js';
import { pdfToPageImages } from '../test/helpers/interpretation.mjs';
import { benchmarkRegressionTest } from './benchmarking.mjs';

describe('Interpretation benchmark', () => {
const { electionPath, precinctId, blankBallotPath, markedBallotPath } =
Expand Down
13 changes: 0 additions & 13 deletions libs/ballot-interpreter/benchmarks/jest.config.js

This file was deleted.

9 changes: 9 additions & 0 deletions libs/ballot-interpreter/benchmarks/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @ts-ignore
import { defineConfig } from '../../../vitest.config.shared.mjs';

export default defineConfig({
test: {
include: ['**/*.bench.mts'],
maxConcurrency: 1,
},
});
4 changes: 2 additions & 2 deletions libs/ballot-interpreter/bin/diagnostic
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
const fs = require('fs');
const { join } = require('path');

if (!fs.existsSync(join(__dirname, '../build/hmpb-ts/rust_addon.node'))) {
if (!fs.existsSync(join(__dirname, '../build/addon.node'))) {
process.stderr.write(
'Error: native rust_addon has not been built. Please run `pnpm build` first.\n'
'Error: native addon has not been built. Please run `pnpm build` first.\n'
);
process.exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/ballot-interpreter/bin/interpret
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
const fs = require('fs');
const { join } = require('path');

if (!fs.existsSync(join(__dirname, '../build/hmpb-ts/rust_addon.node'))) {
if (!fs.existsSync(join(__dirname, '../build/addon.node'))) {
process.stderr.write(
'Error: native rust_addon has not been built. Please run `pnpm build` first.\n'
'Error: native addon has not been built. Please run `pnpm build` first.\n'
);
process.exit(1);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/ballot-interpreter/bin/scoring-report
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
const fs = require('fs');
const { join } = require('path');

if (!fs.existsSync(join(__dirname, '../build/hmpb-ts/rust_addon.node'))) {
if (!fs.existsSync(join(__dirname, '../build/addon.node'))) {
process.stderr.write(
'Error: native rust_addon has not been built. Please run `pnpm build` first.\n'
'Error: native addon has not been built. Please run `pnpm build` first.\n'
);
process.exit(1);
}
Expand Down
23 changes: 0 additions & 23 deletions libs/ballot-interpreter/jest.config.js

This file was deleted.

19 changes: 8 additions & 11 deletions libs/ballot-interpreter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"build"
],
"scripts": {
"benchmark": "jest --runInBand --projects benchmarks",
"benchmark": "cd benchmarks && vitest",
"build": "pnpm --filter $npm_package_name... build:self",
"build:self": "pnpm install:rust-addon && pnpm build:rust-addon && pnpm build:ts",
"build:rust-addon": "cargo-cp-artifact -nc build/hmpb-ts/rust_addon.node -- cargo build --message-format=json-render-diagnostics --release --offline",
"build:rust-addon": "cargo-cp-artifact -nc build/addon.node -- cargo build --message-format=json-render-diagnostics --release --offline",
"build:ts": "tsc --build tsconfig.build.json",
"clean": "pnpm --filter $npm_package_name... clean:self",
"clean:self": "cargo clean --release --package ballot-interpreter && rm -rf build && tsc --build --clean tsconfig.build.json",
Expand All @@ -22,11 +22,11 @@
"lint:fix": "pnpm type-check && eslint . --fix",
"pre-commit": "lint-staged",
"test": "pnpm test:rust-addon && pnpm test:ts",
"test:ci": "pnpm build && pnpm test:ts:coverage --reporters=default --reporters=jest-junit --maxWorkers=6",
"test:ci": "pnpm build && pnpm test:ts:coverage --run",
"test:rust-addon": "cargo test",
"test:ts": "is-ci test:ci test:ts:watch",
"test:ts:coverage": "jest --coverage",
"test:ts:watch": "jest --watch",
"test:ts:coverage": "vitest --coverage",
"test:ts:watch": "vitest",
"type-check": "tsc --build"
},
"dependencies": {
Expand All @@ -35,7 +35,7 @@
"@votingworks/fixtures": "workspace:*",
"@votingworks/image-utils": "workspace:*",
"@votingworks/qrdetect": "^1.0.1",
"@votingworks/test-utils": "workspace:*",
"@votingworks/test-utils-vitest": "workspace:*",
"@votingworks/types": "workspace:*",
"@votingworks/utils": "workspace:*",
"better-sqlite3": "8.2.0",
Expand All @@ -50,11 +50,11 @@
"@types/chalk": "^2.2.0",
"@types/debug": "4.1.8",
"@types/fs-extra": "11.0.1",
"@types/jest": "^29.5.3",
"@types/jest-image-snapshot": "^6.4.0",
"@types/node": "20.16.0",
"@types/node-quirc": "workspace:*",
"@types/tmp": "0.2.4",
"@vitest/coverage-istanbul": "^2.1.8",
"@votingworks/bmd-ballot-fixtures": "workspace:*",
"@votingworks/fs": "workspace:*",
"@votingworks/hmpb": "workspace:*",
Expand All @@ -64,13 +64,10 @@
"eslint-plugin-vx": "workspace:*",
"fs-extra": "11.1.1",
"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",
"sort-package-json": "^1.50.0",
"ts-jest": "29.1.1"
"vitest": "^2.1.8"
},
"packageManager": "[email protected]"
}
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[`VX BMD interpretation extracts votes encoded in a QR code 1`] = `
exports[`VX BMD interpretation > extracts votes encoded in a QR code 1`] = `
[
{
"adjudicationInfo": {
Expand Down Expand Up @@ -141,7 +141,7 @@ exports[`VX BMD interpretation extracts votes encoded in a QR code 1`] = `
]
`;

exports[`VX BMD interpretation interpretSimplexBmdBallot 1`] = `
exports[`VX BMD interpretation > interpretSimplexBmdBallot 1`] = `
[
{
"adjudicationInfo": {
Expand Down Expand Up @@ -282,7 +282,7 @@ exports[`VX BMD interpretation interpretSimplexBmdBallot 1`] = `
]
`;

exports[`adjudication reporting correctly reports blank ballot adjudication flag 1`] = `
exports[`adjudication reporting > correctly reports blank ballot adjudication flag 1`] = `
{
"enabledReasonInfos": [
{
Expand Down Expand Up @@ -418,7 +418,7 @@ exports[`adjudication reporting correctly reports blank ballot adjudication flag
}
`;

exports[`adjudication reporting ignores blank ballot adjudication flag when configured to do so 1`] = `
exports[`adjudication reporting > ignores blank ballot adjudication flag when configured to do so 1`] = `
{
"enabledReasonInfos": [
{
Expand Down Expand Up @@ -554,7 +554,7 @@ exports[`adjudication reporting ignores blank ballot adjudication flag when conf
}
`;

exports[`adjudication reporting ignores undervote adjudication flag when configured to do so 1`] = `
exports[`adjudication reporting > ignores undervote adjudication flag when configured to do so 1`] = `
[
{
"contestId": "president",
Expand Down
Loading