Skip to content

Commit 5af5b2d

Browse files
committed
switch testing library to vitest
1 parent c12773a commit 5af5b2d

File tree

10 files changed

+65
-51
lines changed

10 files changed

+65
-51
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818

1919
- run: ./setup # change this to: npm install
2020
- run: npm run lint
21-
- run: npm run test:cov
21+
- run: npm run test:coverage
2222
env:
2323
CI: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# TS
66
/dist
77

8-
# Jest
8+
# Code Coverage
99
/coverage
1010

1111
# OS generated files

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,3 @@ Simple skeleton for TypeScript Node programs.
1313
2. After this is done you you can remove the `setup` file.
1414
3. Make sure you edit `package.json` with a new name and meta information.
1515
4. Open `.github/workflows/tests.yml` and change `run: ./setup` to: `run: npm install`.
16-
17-
## NPM Dependencies
18-
19-
* [typescript](https://www.typescriptlang.org/) + types/tools
20-
* [jest](https://jestjs.io/) (testing)
21-
* [eslint](https://github.com/eslint/eslint) (linter) + typescript-eslint/airbnb

jest.config.json

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

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"test": "npx jest test",
9-
"test:cov": "npx jest test --coverage",
10-
"lint": "npx ts-standard .",
8+
"test": "vitest --run",
9+
"test:watch": "vitest --watch",
10+
"test:coverage": "vitest --coverage --watch=false",
11+
"lint": "npx ts-standard",
1112
"build": "npx tsc"
1213
},
1314
"author": "Tobias Sandelius @tobidelius",
@@ -19,5 +20,12 @@
1920
"repository": {
2021
"type": "git",
2122
"url": "git+https://github.com/tobidelius/typescript-node-skeleton.git"
23+
},
24+
"devDependencies": {
25+
"@types/node": "^22.14.0",
26+
"@vitest/coverage-v8": "^3.1.1",
27+
"ts-standard": "^12.0.2",
28+
"typescript": "^5.8.2",
29+
"vitest": "^3.1.1"
2230
}
2331
}

setup

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
npm i -D typescript \
2-
jest \
3-
ts-jest \
4-
@types/jest \
2+
@types/node \
3+
@vitest/coverage-v8 \
4+
vitest \
55
ts-standard

test/setup.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
// Setup for the entire suit.
2-
global.beforeAll((done) => {
3-
// console.log('BEFORE ALL')
4-
done()
1+
beforeAll(async () => {
2+
// is run before all tests
53
})
64

7-
// Teardown for the entire suit.
8-
global.afterAll((done) => {
9-
// console.log('AFTER ALL')
10-
done()
5+
afterAll(async () => {
6+
// is run after all tests
117
})
128

13-
// Setup before each spec
14-
global.beforeEach((done) => {
15-
// console.log('BEFORE EACH')
16-
done()
9+
beforeEach(async () => {
10+
// is run before each test
1711
})
1812

19-
// Teardown after each spec.
20-
global.afterEach((done) => {
21-
// console.log('AFTER EACH')
22-
done()
13+
afterEach(async () => {
14+
// is run after each test
2315
})

tsconfig.eslint.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"extends": "./tsconfig.json",
3-
"include": ["src/**/*.ts", "test/**/*.ts"]
3+
"include": [
4+
"src/**/*.ts",
5+
"test/**/*.ts",
6+
]
47
}

tsconfig.json

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
{
22
"compilerOptions": {
3-
"target": "ESNext",
4-
"module": "commonjs",
5-
"strict": true,
6-
"esModuleInterop": true,
7-
"skipLibCheck": true,
8-
"forceConsistentCasingInFileNames": true,
9-
"sourceMap": true,
10-
"outDir": "./dist",
11-
"rootDir": "./src",
12-
"baseUrl": "."
3+
"target": "ES2020", // Set to a modern ECMAScript version (or "ESNext" for the latest)
4+
"module": "CommonJS", // Set module system to CommonJS (for Node.js)
5+
"moduleResolution": "node", // Helps TypeScript find modules in Node.js
6+
"lib": [
7+
"ES2020"
8+
], // Include necessary libraries for Node.js runtime
9+
"esModuleInterop": true, // Allow default imports from modules that don't have a default export
10+
"skipLibCheck": true, // Skip type checking of declaration files (speeds up build)
11+
"strict": true, // Enable strict type checking
12+
"forceConsistentCasingInFileNames": true, // Enforce consistent file naming
13+
"outDir": "./dist", // Directory where compiled JavaScript will go
14+
"declaration": true, // Generate TypeScript declaration files (.d.ts)
15+
"declarationMap": true, // Generate map files for declarations
16+
"sourceMap": true, // Enable source maps for debugging
17+
"allowJs": false, // Do not allow JavaScript files in the project
18+
"resolveJsonModule": true, // Allow importing JSON modules (if needed)
19+
"noEmitOnError": true, // Don't emit any files if there are errors
20+
"types": [
21+
"node",
22+
"vitest/globals"
23+
]
1324
},
14-
"include": ["src/**/*.ts"],
15-
"exclude": ["node_modules", "dist"]
25+
"include": [
26+
"src/**/*.ts",
27+
"test/**/*.ts"
28+
],
29+
"exclude": [
30+
"node_modules",
31+
"dist"
32+
]
1633
}

vitest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
setupFiles: './test/setup.ts',
6+
globals: true
7+
}
8+
})

0 commit comments

Comments
 (0)