Skip to content

Commit 3edfc46

Browse files
authored
test: use Vitest for testing (#647)
* test: use Vitest for testing Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> * build: remove `esModuleInterop` option in TypeScript configuration Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com> --------- Signed-off-by: Alfi Maulana <alfi.maulana.f@gmail.com>
1 parent fc2779d commit 3edfc46

7 files changed

Lines changed: 982 additions & 2491 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This template provides a basic Node.js project containing a sample library writt
88

99
- Minimal Node.js project written in TypeScript with [ESM](https://nodejs.org/api/esm.html) support.
1010
- Uses [Yarn](https://yarnpkg.com/) as the package manager, with [Plug'n'Play](https://yarnpkg.com/features/pnp) support.
11-
- Supports formatting with [Prettier](https://prettier.io/), linting with [ESLint](https://eslint.org/), and testing with [Jest](https://jestjs.io/).
11+
- Supports formatting with [Prettier](https://prettier.io/), linting with [ESLint](https://eslint.org/), and testing with [Vitest](https://vitest.dev/).
1212
- Preconfigured workflows for [Dependabot](https://docs.github.com/en/code-security/dependabot) and [GitHub Actions](https://github.com/features/actions).
1313

1414
## Usage
@@ -82,7 +82,7 @@ yarn build
8282

8383
### Testing the Library
8484

85-
Test files in this template are named `*.test.ts` and typically correspond to the source files being tested. This template uses [Jest](https://jestjs.io/) as the testing framework. For more information on testing with Jest, refer to [this documentation](https://jestjs.io/docs/getting-started).
85+
Test files in this template are named `*.test.ts` and typically correspond to the source files being tested. This template uses [Vitest](https://vitest.dev/) as the testing framework. For more information on testing with Vitest, refer to [this documentation](https://vitest.dev/guide/).
8686

8787
After creating your test files, run tests with:
8888

jest.config.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,21 @@
2626
"format": "prettier --write --cache .",
2727
"lint": "eslint",
2828
"prepack": "tsc",
29-
"test": "jest"
29+
"test": "vitest"
3030
},
3131
"dependencies": {
3232
"yargs": "^17.7.2"
3333
},
3434
"devDependencies": {
3535
"@eslint/js": "^9.17.0",
36-
"@types/jest": "^29.5.14",
3736
"@types/node": "^22.10.2",
3837
"@types/yargs": "^17.0.33",
38+
"@vitest/coverage-v8": "^2.1.8",
3939
"eslint": "^9.17.0",
40-
"jest": "^29.7.0",
4140
"prettier": "^3.4.2",
42-
"ts-jest": "^29.2.5",
4341
"typescript": "^5.7.2",
44-
"typescript-eslint": "^8.18.2"
42+
"typescript-eslint": "^8.18.2",
43+
"vitest": "^2.1.8"
4544
},
4645
"packageManager": "yarn@4.5.3"
4746
}

src/sequence.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { it, expect } from "vitest";
12
import { fibonacciSequence } from "./sequence.js";
23

34
it("should generate a fibonacci sequence", () => {

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"module": "node16",
88
"declaration": true,
99
"outDir": "dist",
10-
"esModuleInterop": true,
1110
"target": "es2022",
1211
"skipLibCheck": true
1312
}

vitest.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
watch: false,
6+
coverage: {
7+
all: false,
8+
enabled: true,
9+
reporter: ["text"],
10+
thresholds: { 100: true },
11+
},
12+
},
13+
});

0 commit comments

Comments
 (0)