From 86c1e88a7c0a3d533b03f1b86843f09d6574a1af Mon Sep 17 00:00:00 2001 From: Dominik Zogg Date: Tue, 18 Jun 2024 20:21:37 +0200 Subject: [PATCH] jest => vitest --- .github/workflows/ci.yml | 6 +++--- jest.config.cjs | 15 --------------- package.json | 24 +++++++++++------------- stryker.conf.json | 5 ++++- tests/message-factory.test.ts | 2 +- vitest.config.ts | 19 +++++++++++++++++++ 6 files changed, 38 insertions(+), 33 deletions(-) delete mode 100644 jest.config.cjs create mode 100644 vitest.config.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4683be1..ce29f19 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: with: node-version: '16' - run: npm install - - run: npm test + - run: npm test -- --run --no-cache node18: name: Node 18 runs-on: ubuntu-22.04 @@ -32,7 +32,7 @@ jobs: with: node-version: '18' - run: npm install - - run: npm test + - run: npm test -- --run --no-cache node20: name: Node 20 runs-on: ubuntu-22.04 @@ -46,7 +46,7 @@ jobs: - run: npm install - run: npm run lint - run: npm run cs - - run: npm test -- --coverage --no-cache + - run: npm test -- --run --coverage --no-cache - run: npm run infection env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/jest.config.cjs b/jest.config.cjs deleted file mode 100644 index 581a3a6..0000000 --- a/jest.config.cjs +++ /dev/null @@ -1,15 +0,0 @@ -/* eslint-disable no-undef */ -/* eslint-disable functional/immutable-data */ -module.exports = { - 'preset': 'ts-jest', - 'testEnvironment': 'node', - 'collectCoverageFrom': [ - 'src/**/*.ts' - ], - 'coverageThreshold': { - 'global': { - 'lines': 100 - } - }, - prettierPath: require.resolve('prettier-2'), -}; diff --git a/package.json b/package.json index 661f26c..0b253fb 100644 --- a/package.json +++ b/package.json @@ -17,13 +17,13 @@ "repository": "chubbyts/chubbyts-http", "scripts": { "build": "node ./build.js", - "cs-fix": "./node_modules/prettier/bin/prettier.cjs --write src tests", - "cs": "./node_modules/prettier/bin/prettier.cjs --check src tests", + "cs-fix": "prettier --write src tests", + "cs": "prettier --check src tests", "infection": "stryker run", "lint-fix": "eslint src tests --fix", "lint": "eslint src tests", "prepare": "npm run build", - "test": "jest" + "test": "vitest" }, "prettier": { "printWidth": 120, @@ -51,17 +51,15 @@ }, "devDependencies": { "@chubbyts/chubbyts-eslint": "^2.0.3", - "@chubbyts/chubbyts-packaging": "^2.0.6", + "@chubbyts/chubbyts-packaging": "^2.0.7", "@stryker-mutator/core": "^8.2.6", - "@stryker-mutator/jest-runner": "^8.2.6", - "@types/jest": "^29.5.12", - "@types/node": "^20.11.30", - "@types/qs": "^6.9.14", - "jest": "^29.7.0", - "prettier": "^3.2.5", - "prettier-2": "npm:prettier@^2.8.8", - "ts-jest": "^29.1.2", - "typescript": "^5.4.3" + "@stryker-mutator/vitest-runner": "^8.2.6", + "@types/node": "^20.14.5", + "@types/qs": "^6.9.15", + "@vitest/coverage-v8": "^1.6.0", + "prettier": "^3.3.2", + "typescript": "^5.4.5", + "vitest": "^1.6.0" }, "publishConfig": { "access": "public" diff --git a/stryker.conf.json b/stryker.conf.json index dd79970..9a92983 100644 --- a/stryker.conf.json +++ b/stryker.conf.json @@ -1,6 +1,9 @@ { "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json", - "testRunner": "jest", + "testRunner": "vitest", + "vitest": { + "configFile": "vitest.config.ts" + }, "coverageAnalysis": "off", "reporters": [ "clear-text", diff --git a/tests/message-factory.test.ts b/tests/message-factory.test.ts index 56b31a4..c034bfe 100644 --- a/tests/message-factory.test.ts +++ b/tests/message-factory.test.ts @@ -2,7 +2,7 @@ import { randomBytes } from 'crypto'; import { createReadStream, unlinkSync, writeFileSync } from 'fs'; import { tmpdir } from 'os'; import { PassThrough, Stream } from 'stream'; -import { describe, expect, test } from '@jest/globals'; +import { describe, expect, test } from 'vitest'; import { Method } from '@chubbyts/chubbyts-http-types/dist/message'; import { createUriFactory, diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 0000000..68374ec --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,19 @@ +import { defineConfig } from 'vitest/config'; + +export default defineConfig({ + test: { + globals: true, + environment: 'node', + include: ['tests/**/*.test.*'], + coverage: { + all: true, + clean: true, + reporter: ['clover', ['html', { subdir: 'html' }], 'json', 'lcovonly', 'text'], + provider: 'v8', + thresholds: { + lines: 100, + }, + include: ['src/**/*.ts'], + }, + }, +});