From d5a197253df5f8affdda9d767040156b8873def0 Mon Sep 17 00:00:00 2001 From: Brian Donovan <1938+eventualbuddha@users.noreply.github.com> Date: Mon, 16 Dec 2024 21:03:50 -0800 Subject: [PATCH] test(grout): replace `jest` with `vitest` (#5764) --- libs/grout/.eslintignore | 1 + libs/grout/jest.config.js | 8 -------- libs/grout/package.json | 13 +++++-------- libs/grout/src/grout.test.ts | 3 ++- libs/grout/src/serialization.test.ts | 1 + libs/grout/vitest.config.ts | 3 +++ pnpm-lock.yaml | 21 ++++++--------------- vitest.config.shared.mts | 2 +- 8 files changed, 19 insertions(+), 33 deletions(-) delete mode 100644 libs/grout/jest.config.js create mode 100644 libs/grout/vitest.config.ts diff --git a/libs/grout/.eslintignore b/libs/grout/.eslintignore index 9dde9fd960..5def58657b 100644 --- a/libs/grout/.eslintignore +++ b/libs/grout/.eslintignore @@ -1,5 +1,6 @@ *.js *.d.ts +vitest.config.ts build coverage test-utils \ No newline at end of file diff --git a/libs/grout/jest.config.js b/libs/grout/jest.config.js deleted file mode 100644 index 0c9a77bd87..0000000000 --- a/libs/grout/jest.config.js +++ /dev/null @@ -1,8 +0,0 @@ -const shared = require('../../jest.config.shared'); - -/** - * @type {import('@jest/types').Config.InitialOptions} - */ -module.exports = { - ...shared, -}; diff --git a/libs/grout/package.json b/libs/grout/package.json index dc4e91fa9c..aaee4e2d6d 100644 --- a/libs/grout/package.json +++ b/libs/grout/package.json @@ -15,9 +15,9 @@ "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": { @@ -29,19 +29,16 @@ "devDependencies": { "@types/debug": "4.1.8", "@types/express": "4.17.14", - "@types/jest": "^29.5.3", "@types/luxon": "^3.0.0", "@types/node-fetch": "^2.6.0", + "@vitest/coverage-istanbul": "^2.1.8", "eslint-plugin-vx": "workspace:*", "expect-type": "^0.15.0", "express": "4.18.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", "sort-package-json": "^1.50.0", - "ts-jest": "29.1.1" + "vitest": "^2.1.8" }, "packageManager": "pnpm@8.15.5" } diff --git a/libs/grout/src/grout.test.ts b/libs/grout/src/grout.test.ts index f3131c3853..5a0be74fd8 100644 --- a/libs/grout/src/grout.test.ts +++ b/libs/grout/src/grout.test.ts @@ -1,5 +1,6 @@ /* eslint-disable no-unused-expressions */ /* eslint-disable @typescript-eslint/require-await */ +import { expect, test, vi } from 'vitest'; import { AddressInfo } from 'node:net'; import express from 'express'; import { err, ok, Result } from '@votingworks/basics'; @@ -83,7 +84,7 @@ test('registers Express routes for an API', async () => { }); test('sends a 500 for unexpected errors', async () => { - const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); + const consoleErrorSpy = vi.spyOn(console, 'error').mockReturnValue(); const api = createApi({ async getStuff(): Promise { throw new Error('Unexpected error'); diff --git a/libs/grout/src/serialization.test.ts b/libs/grout/src/serialization.test.ts index 98238600eb..13ffa3eef7 100644 --- a/libs/grout/src/serialization.test.ts +++ b/libs/grout/src/serialization.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import { expect, test } from 'vitest'; import { Buffer } from 'node:buffer'; import { DateWithoutTime, err, ok } from '@votingworks/basics'; import { DateTime } from 'luxon'; diff --git a/libs/grout/vitest.config.ts b/libs/grout/vitest.config.ts new file mode 100644 index 0000000000..1cc9c7884b --- /dev/null +++ b/libs/grout/vitest.config.ts @@ -0,0 +1,3 @@ +import { defineConfig } from '../../vitest.config.shared.mjs'; + +export default defineConfig(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c687121365..837cae6771 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4216,15 +4216,15 @@ importers: '@types/express': specifier: 4.17.14 version: 4.17.14 - '@types/jest': - specifier: ^29.5.3 - version: 29.5.3 '@types/luxon': specifier: ^3.0.0 version: 3.2.0 '@types/node-fetch': specifier: ^2.6.0 version: 2.6.2 + '@vitest/coverage-istanbul': + specifier: ^2.1.8 + version: 2.1.8(vitest@2.1.8) eslint-plugin-vx: specifier: workspace:* version: link:../eslint-plugin-vx @@ -4237,24 +4237,15 @@ importers: is-ci-cli: specifier: 2.2.0 version: 2.2.0 - jest: - specifier: ^29.6.2 - version: 29.6.2(@types/node@20.16.0) - jest-junit: - specifier: ^16.0.0 - version: 16.0.0 - jest-watch-typeahead: - specifier: ^2.2.2 - version: 2.2.2(jest@29.6.2) lint-staged: specifier: 11.0.0 version: 11.0.0 sort-package-json: specifier: ^1.50.0 version: 1.53.1 - ts-jest: - specifier: 29.1.1 - version: 29.1.1(@babel/core@7.26.0)(@jest/types@29.6.1)(esbuild@0.18.17)(jest@29.6.2)(typescript@5.6.2) + vitest: + specifier: ^2.1.8 + version: 2.1.8 libs/grout/test-utils: dependencies: diff --git a/vitest.config.shared.mts b/vitest.config.shared.mts index f4cc4a1be9..fdfebeba93 100644 --- a/vitest.config.shared.mts +++ b/vitest.config.shared.mts @@ -1,10 +1,10 @@ import * as vitest from 'vitest/config'; -import { join } from 'node:path'; const isCI = process.env['CI'] === 'true'; export const base: vitest.ViteUserConfig = { test: { + include: ['src/**/*.test.{ts,tsx}', 'test/**/*.test.{ts,tsx}'], coverage: { thresholds: { lines: 100,