Skip to content

Commit

Permalink
test: migrate from jest to vitest (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertHernandez authored Mar 3, 2024
1 parent 9bf81e7 commit d592959
Show file tree
Hide file tree
Showing 15 changed files with 2,587 additions and 3,207 deletions.
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NODE_ENV=test
PORT=0
13 changes: 5 additions & 8 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:prettier/recommended",
"plugin:jest/recommended",
"plugin:jest/style",
"plugin:unicorn/recommended",
"plugin:node/recommended"
],
Expand Down Expand Up @@ -66,17 +64,16 @@
},
{
"files": ["tests/**"],
"plugins": ["jest"],
"plugins": ["vitest"],
"extends": ["plugin:vitest/recommended"],
"rules": {
"@typescript-eslint/unbound-method": "off",
"jest/unbound-method": "error",
"jest/expect-expect": "off",
"jest/no-standalone-expect": "off"
"vitest/expect-expect": "off",
"vitest/no-standalone-expect": "off"
}
}
],
"env": {
"node": true,
"jest": true
"node": true
}
}
9 changes: 6 additions & 3 deletions .github/pr-scope-labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
- changed-files:
- any-glob-to-any-file:
- tests/**
- .jest/**
- vitest.config.**.ts
- create-vitest-test-config.ts
- .env.test
- scripts/calculate-global-test-coverage.ts
- jest.config.ts
- nyc.config.js

📝 Documentation:
Expand Down Expand Up @@ -47,7 +48,9 @@
- .swcrc
- .yamllint.yml
- commitlint.config.ts
- jest.config.ts
- vitest.config.**.ts
- create-vitest-test-config.ts
- .env.test
- lint-staged.config.js
- nest-cli.json
- nyc.config.js
Expand Down
2 changes: 0 additions & 2 deletions .jest/set-env-vars.ts

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/typescript-5.x-blue.svg" alt="typescript"/></a>
<a href="https://www.npmjs.com/"><img src="https://img.shields.io/badge/npm-10.x-red.svg" alt="npm"/></a>
<a href="https://swc.rs/"><img src="https://img.shields.io/badge/Compiler-SWC_-orange.svg" alt="swc"/></a>
<a href="https://vitest.dev/"><img src="https://img.shields.io/badge/Test-Vitest_-yellow.svg" alt="swc"/></a>
<a href="https://www.docker.com/"><img src="https://img.shields.io/badge/Dockerized 🐳_-blue.svg" alt="docker"/></a>
</p>

Expand All @@ -33,7 +34,7 @@ The main objective of this template is to provide a good base configuration for
- 💬 Use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) to ensure our commits have a convention.
- ✅ Run the tests automatically.
- ⚙️ Check our project does not have type errors with Typescript.
5. 🧪 Testing with [Jest](https://jestjs.io/es-ES/) and [supertest](https://github.com/ladjs/supertest) for unit and e2e tests.
5. 🧪 Testing with [Vitest](https://vitest.dev/) and [supertest](https://github.com/ladjs/supertest) for unit and e2e tests.
6. 🤜🤛 Combine unit and e2e test coverage. In the services we may have both type of tests, unit and e2e tests, and usually we would like to see what is the combined test coverage, so we can see the full picture.
7. 📌 Custom path aliases, where you can define your own paths (you will be able to use imports like `@core/logger` instead of `../../../src/core/logger`).
8. 🚀 CI/CD using GitHub Actions, helping ensure a good quality of our code and providing useful insights about dependencies, security vulnerabilities and others.
Expand Down
19 changes: 19 additions & 0 deletions create-vitest-test-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { loadEnv } from "vite";
import { InlineConfig } from "vitest";

export const createVitestTestConfig = (testingType: string): InlineConfig => {
return {
root: "./",
globals: true,
isolate: false,
passWithNoTests: true,
include: [`tests/${testingType}/**/*.test.ts`],
env: loadEnv("test", process.cwd(), ""),
coverage: {
provider: "istanbul",
reporter: ["text", "json", "html"],
reportsDirectory: `coverage/${testingType}`,
include: ["src/**/*.ts"],
},
};
};
21 changes: 0 additions & 21 deletions jest.config.ts

This file was deleted.

5 changes: 1 addition & 4 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
const config = {
"**/*.ts?(x)": () => "tsc -p tsconfig.prod.json --noEmit",
"*.{js,jsx,ts,tsx}": [
"npm run lint",
"jest --findRelatedTests --passWithNoTests",
],
"*.{js,jsx,ts,tsx}": ["npm run lint", "vitest related --run"],
"*.{md,json}": "prettier --write",
};

Expand Down
Loading

0 comments on commit d592959

Please sign in to comment.