From 124a4ecaa58279eb8f31b8dc934127615d6064a7 Mon Sep 17 00:00:00 2001 From: Richard Zampieri Date: Wed, 13 Nov 2024 19:20:57 -0800 Subject: [PATCH] feat: migrate from Vitest to Jest for testing framework --- .eslintrc.cjs | 2 +- .gitignore | 3 +- jest.config.ts | 24 +++++++++++ package.json | 17 ++++---- .../__tests__/project.commands.spec.ts | 7 ---- tsconfig.json | 2 +- vitest.config.ts | 41 ------------------- 7 files changed, 36 insertions(+), 60 deletions(-) create mode 100644 jest.config.ts delete mode 100644 src/commands/__tests__/project.commands.spec.ts delete mode 100644 vitest.config.ts diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 64dec25..53e0874 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -20,7 +20,7 @@ module.exports = { "node_modules/*", "expressots.config.ts", "commitlint.config.ts", - "vitest.config.ts", + "jest.config.ts", ".eslintrc.cjs", "coverage/*", ], diff --git a/.gitignore b/.gitignore index 7ef4f15..c10c608 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ expressots.config.ts *.container.ts -coverage/ \ No newline at end of file +coverage/ +.early.coverage diff --git a/jest.config.ts b/jest.config.ts new file mode 100644 index 0000000..b07211a --- /dev/null +++ b/jest.config.ts @@ -0,0 +1,24 @@ +import type { JestConfigWithTsJest } from "ts-jest"; + +const config: JestConfigWithTsJest = { + testEnvironment: "node", + roots: ["/src"], + testRegex: ".*\\.spec\\.ts$", + testPathIgnorePatterns: ["/node_modules/", "/bin/"], + collectCoverageFrom: ["src/**/*.ts", "!**/*.spec.ts", "src/**/index.ts"], + moduleNameMapper: { + "^@src/(.*)$": "/src/$1", + }, + setupFiles: ["reflect-metadata"], + transform: { + "^.+\\.ts$": [ + "ts-jest", + { + tsconfig: "tsconfig.json", + // Add any ts-jest specific options here + }, + ], + }, +}; + +export default config; diff --git a/package.json b/package.json index 361a139..9e1e397 100644 --- a/package.json +++ b/package.json @@ -44,9 +44,9 @@ "lint": "eslint \"./src/**/*.ts\"", "lint:fix": "eslint \"./src/**/*.ts\" --fix", "release": "release-it", - "test": "vitest run --reporter default", - "test:watch": "vitest", - "coverage": "vitest run --coverage" + "test": "jest", + "coverage": "jest --coverage", + "test:watch": "jest --watch" }, "dependencies": { "@expressots/boost-ts": "1.3.0", @@ -66,32 +66,31 @@ "@codecov/vite-plugin": "^0.0.1-beta.9", "@commitlint/cli": "19.2.1", "@commitlint/config-conventional": "19.1.0", - "@expressots/shared": "file:../shared/expressots-shared-0.0.1-beta.1.tgz", + "@expressots/shared": "0.1.0", "@release-it/conventional-changelog": "7.0.2", "@types/chalk-animation": "1.6.1", "@types/cli-progress": "3.11.0", "@types/degit": "2.8.3", "@types/inquirer": "9.0.3", + "@types/jest": "^29.5.14", "@types/mustache": "4.2.2", "@types/node": "20.12.7", "@types/yargs": "17.0.22", "@typescript-eslint/eslint-plugin": "7.6.0", "@typescript-eslint/parser": "7.6.0", - "@vitest/coverage-v8": "1.4.0", "chalk": "4.1.2", "eslint": "8.57.0", "eslint-config-prettier": "9.1.0", "husky": "9.0.11", + "jest": "^29.7.0", "prettier": "3.2.5", "reflect-metadata": "0.2.2", "release-it": "16.3.0", "rimraf": "5.0.5", "shx": "0.3.4", + "ts-jest": "^29.2.5", "ts-node-dev": "2.0.0", - "typescript": "5.2.2", - "vite": "5.2.8", - "vite-tsconfig-paths": "4.3.2", - "vitest": "1.4.0" + "typescript": "5.2.2" }, "release-it": { "git": { diff --git a/src/commands/__tests__/project.commands.spec.ts b/src/commands/__tests__/project.commands.spec.ts deleted file mode 100644 index e331cb5..0000000 --- a/src/commands/__tests__/project.commands.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { describe, it, expect } from "vitest"; - -describe("project.commands", () => { - it("should return a list of commands", () => { - expect(true).toBe(true); - }); -}); diff --git a/tsconfig.json b/tsconfig.json index 91d0322..dcf9ee3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,7 +15,7 @@ "skipLibCheck": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, - "types": ["node", "reflect-metadata", "vitest/globals"] + "types": ["node", "reflect-metadata", "jest"] }, "include": ["./src/**/*.ts"], "exclude": ["node_modules", "test/**/*.spec.ts", "./bin/**/*"] diff --git a/vitest.config.ts b/vitest.config.ts deleted file mode 100644 index aa2776a..0000000 --- a/vitest.config.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { defineConfig } from "vitest/config"; -import { codecovVitePlugin } from "@codecov/vite-plugin"; -import tsconfigPaths from "vite-tsconfig-paths"; - -/** - * @see {@link https://vitejs.dev/config/} - * @see {@link https://vitest.dev/config/} - */ -export default defineConfig({ - plugins: [ - tsconfigPaths(), - codecovVitePlugin({ - enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined, - bundleName: "expresso-ts-cli-coverage", - uploadToken: process.env.CODECOV_TOKEN, - }), - ], - test: { - globals: true, - environment: "node", - setupFiles: ["reflect-metadata"], - exclude: ["**/node_modules/**", "**/benchmark/**", "**/bin/**"], - coverage: { - all: true, - include: ["./src/**"], - exclude: ["**/node_modules/**", "**/bin/**", "**/index.ts/**"], - thresholds: { - global: { - statements: 85, - branches: 85, - functions: 85, - lines: 85, - }, - }, - reporter: ["text", "html", "json"], - provider: "v8", - }, - // ref: https://vitest.dev/config/#testtimeout - testTimeout: 10000, - }, -});