Skip to content

Commit

Permalink
test(image-utils): replace jest with vitest (#5711)
Browse files Browse the repository at this point in the history
* test(image-utils): replace `jest` with `vitest`

* test(image-utils): replace `jest` API with `vitest` API

* chore: re-sync pnpm lockfile

* make `test/arbitraries` a module and exclude `.mts` from build

* remove outdated jest config
  • Loading branch information
eventualbuddha committed Dec 11, 2024
1 parent 9252ccd commit 125a017
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 55 deletions.
2 changes: 1 addition & 1 deletion libs/image-utils/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bin
build
coverage
jest.config.js
vitest.config.mts
13 changes: 0 additions & 13 deletions libs/image-utils/jest.config.js

This file was deleted.

14 changes: 5 additions & 9 deletions libs/image-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"lint": "pnpm type-check && eslint .",
"lint:fix": "pnpm type-check && eslint . --fix",
"test": "is-ci test:ci test:watch",
"test:ci": "jest --coverage --ci --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"
},
"packageManager": "[email protected]",
"dependencies": {
Expand All @@ -32,23 +32,19 @@
"tmp": "^0.2.1"
},
"devDependencies": {
"@jest/types": "^29.6.1",
"@types/debug": "4.1.8",
"@types/jest": "^29.5.3",
"@types/jest-image-snapshot": "^6.4.0",
"@types/node": "20.16.0",
"@types/pdfjs-dist": "2.1.3",
"@types/pixelmatch": "^5.2.6",
"@types/tmp": "0.2.4",
"@vitest/coverage-istanbul": "^2.1.8",
"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-junit": "^16.0.0",
"jest-watch-typeahead": "^2.2.2",
"lint-staged": "11.0.0",
"ts-jest": "29.1.1"
"vitest": "^2.1.8"
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { expect, test } from 'vitest';
import { Rect } from '@votingworks/types';
import { createImageData, ImageData } from 'canvas';
import fc from 'fast-check';
import { arbitraryImageData, arbitraryRect } from '../test/arbitraries';
import { crop } from './crop';
import { int } from './types';
import { RGBA_CHANNEL_COUNT } from '.';
import { arbitraryImageData, arbitraryRect } from '../test/arbitraries.mjs';
import { crop } from './crop.js';
import { int } from './types.js';
import { RGBA_CHANNEL_COUNT } from './index.js';

/**
* A slow-but-accurate implementation of `crop` to compare against.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { expect, test } from 'vitest';
import { Buffer } from 'node:buffer';
import { ImageData, createImageData } from 'canvas';
import fc from 'fast-check';
import { writeFile } from 'node:fs/promises';
import { fileSync } from 'tmp';
import { randomFillSync } from 'node:crypto';
import { MaybePromise } from '@votingworks/basics';
import { arbitraryImageData } from '../test/arbitraries';
import { arbitraryImageData } from '../test/arbitraries.mjs';
import {
RGBA_CHANNEL_COUNT,
encodeImageData,
Expand All @@ -17,7 +18,7 @@ import {
toDataUrl,
toImageBuffer,
writeImageData,
} from './image_data';
} from './image_data.js';

test('channels', () => {
const rgbaImage = createImageData(1, 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect, test } from 'vitest';
import { sampleBallotImages } from '@votingworks/fixtures';
import { createImageData } from 'canvas';
import { basename } from 'node:path';
import { crop } from './crop';
import { crop } from './crop.js';

test('matching images', async () => {
const image = createImageData(1, 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test } from 'vitest';
import fc from 'fast-check';
import { assertInteger, EPSILON, isCloseToZero } from './numeric';
import { assertInteger, EPSILON, isCloseToZero } from './numeric.js';

test('isCloseToZero', () => {
expect(isCloseToZero(0)).toEqual(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from 'vitest';
import { iter } from '@votingworks/basics';
import { electionGridLayoutNewHampshireHudsonFixtures } from '@votingworks/fixtures';
import { Size } from '@votingworks/types';
Expand All @@ -9,7 +10,7 @@ import {
parsePdf,
pdfToImages,
setPdfRenderWorkerSrc,
} from './pdf_to_images';
} from './pdf_to_images.js';

const pdfNotRequiringPdfjsIntermediateCanvasBuffer = readFileSync(
join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { assert } from '@votingworks/basics';
import { Rect } from '@votingworks/types';
import { createImageData, ImageData } from 'canvas';
import fc from 'fast-check';
import { int, RGBA_CHANNEL_COUNT } from '../src';
import { assertInteger } from '../src/numeric';
import { int, RGBA_CHANNEL_COUNT } from '../src/index.js';
import { assertInteger } from '../src/numeric.js';

/**
* Options for building an arbitrary image data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from 'vitest';
import fc from 'fast-check';
import { assertInteger } from '../src/numeric';
import { arbitraryImageData, arbitraryRect } from './arbitraries';
import { assertInteger } from '../src/numeric.js';
import { arbitraryImageData, arbitraryRect } from './arbitraries.mjs';

test('arbitraryImageData has sensible values', () => {
fc.assert(
Expand Down
1 change: 1 addition & 0 deletions libs/image-utils/test/setupTests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ImageData } from 'canvas';
import { expect } from 'vitest';
import { toMatchImage, ToMatchImageOptions } from '../src';

declare global {
Expand Down
7 changes: 6 additions & 1 deletion libs/image-utils/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"extends": "./tsconfig.json",
"include": ["src"],
"exclude": ["**/*.test.ts", "**/*.test.tsx"],
"exclude": [
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.mts",
"**/*.test.mtsx"
],
"compilerOptions": {
"noEmit": false,
"outDir": "build",
Expand Down
10 changes: 10 additions & 0 deletions libs/image-utils/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from '../../vitest.config.shared.mjs';

export default defineConfig({
test: {
setupFiles: ['test/setupTests.ts'],
coverage: {
exclude: ['src/jest_pdf_snapshot.ts', 'src/cli/pdf_to_images.ts'],
},
},
});
24 changes: 6 additions & 18 deletions pnpm-lock.yaml

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

0 comments on commit 125a017

Please sign in to comment.