Skip to content

Commit 0aa9355

Browse files
committed
use vitest instread of jest
1 parent fb126d7 commit 0aa9355

17 files changed

+907
-2453
lines changed

Diff for: .github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on: push
44

55
jobs:
6-
lint-test-build:
6+
lint-test:
77
runs-on: ubuntu-20.04
88
steps:
99
- name: Checkout repository
@@ -40,8 +40,8 @@ jobs:
4040
- name: Run unit tests
4141
run: yarn test
4242

43-
- name: Build library
44-
run: yarn build
43+
# - name: Build library
44+
# run: yarn build
4545

4646
# - name: Publish library
4747
# if: ${{ github.ref == 'refs/heads/main' }}

Diff for: .npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ tests/
55
.github
66
yarn.lock
77
eslint.config.mjs
8+
vitest.config.ts
9+
vitest.workspace.ts
10+
*.test.ts

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A quick start template for a new TypeScript library
1111
- 💎 ESLint 9 with [eslint-config-codex](http://github.com/codex-team/eslint-config/)
1212
- 🥃 Typescript 5
1313
- 🥊 npx only-allow yarn
14-
- 🌶️ Tests with [Jest](http://jestjs.io)
14+
- 🌶️ Tests with [Vitest](https://vitest.dev)
1515
- 🍀 GitHub Actions for test/lint/build/publish purposes
1616

1717
## How to use

Diff for: eslint.config.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import CodeX from 'eslint-config-codex';
22
import { plugin as TsPlugin, parser as TsParser } from 'typescript-eslint';
33
import path from 'path';
44
import { fileURLToPath } from 'url';
5+
import EslintTestsConfig from './eslint.config.test.mjs';
56

67
const __filename = fileURLToPath(import.meta.url);
78
const __dirname = path.dirname(__filename);
89

910
export default [
1011
...CodeX,
12+
...EslintTestsConfig,
1113
{
1214
name: 'codex-lib-ts',
1315
ignores: [

Diff for: eslint.config.test.mjs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default [
2+
{
3+
name: 'codex-lib-tests',
4+
files: [
5+
'packages/**/*.test.ts',
6+
],
7+
rules: {
8+
'n/no-missing-import': 'off',
9+
},
10+
},
11+
];

Diff for: jest.config.ts

-194
This file was deleted.

Diff for: package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
"clean": "rimraf -g \"packages/**/dist\" \"packages/**/*.tsbuildinfo\"",
1616
"lint": "yarn workspaces foreach -A run lint",
1717
"lint:fix": "yarn workspaces foreach -A run lint --fix",
18+
"test": "vitest --watch=false",
19+
"coverage": "vitest --watch=false --coverage",
1820
"preinstall": "npx only-allow yarn"
1921
},
2022
"devDependencies": {
21-
"@types/jest": "^29.5.14",
2223
"eslint": "^9.14.0",
2324
"eslint-config-codex": "2.0.3-rc.3",
24-
"jest": "^29.7.0",
2525
"rimraf": "^6.0.1",
26-
"ts-jest": "^29.2.5",
2726
"ts-node": "^10.9.2",
2827
"typescript": "^5.6.3",
29-
"typescript-eslint": "^8.13.0"
28+
"typescript-eslint": "^8.13.0",
29+
"vitest": "^2.1.4"
3030
},
3131
"packageManager": "[email protected]"
3232
}

Diff for: packages/core/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@
1919
"lint": "eslint ./src",
2020
"lint:fix": "yarn lint --fix",
2121
"build": "tsc -p tsconfig.build.json",
22-
"test": "jest"
22+
"test:dev": "vitest",
23+
"test": "vitest run",
24+
"coverage": "vitest run --coverage"
2325
},
2426
"dependencies": {
2527
"mylib-utils": "workspace:^"
2628
},
2729
"devDependencies": {
30+
"@vitest/coverage-v8": "^2.1.4",
2831
"eslint": "^9.14.0",
2932
"rimraf": "^6.0.1",
30-
"typescript": "^5.6.3"
33+
"typescript": "^5.6.3",
34+
"vitest": "^2.1.4"
3135
}
3236
}

Diff for: packages/core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { myUtil } from 'mylib-utils';
44
* Simple function that returns string
55
*/
66
export default function main(): string {
7-
return 'It works!' + myUtil(1, 2);
7+
return 'It works! ' + myUtil(1, 2);
88
}

Diff for: packages/core/tests/index.test.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import main from '../src';
1+
import main from '../src/index';
2+
import { describe, test, expect } from 'vitest';
23

3-
describe('TypeScript library template', () => {
4-
test('Should return correct result', () => {
5-
expect(main()).toBe('It works!');
4+
describe('My Package test', () => {
5+
describe('main()', () => {
6+
test('shoul return a contatinated string', () => {
7+
const result = main();
8+
9+
expect(result).toBe('It works! 3');
10+
});
611
});
712
});

Diff for: packages/utils/package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@
44
"main": "src/index.ts",
55
"type": "module",
66
"author": "CodeX <[email protected]>",
7+
"files": [
8+
"src"
9+
],
710
"scripts": {
811
"lint": "eslint ./src",
912
"lint:fix": "yarn lint --fix",
10-
"test": "jest"
13+
"test:dev": "vitest",
14+
"test": "vitest run",
15+
"coverage": "vitest run --coverage"
1116
},
1217
"devDependencies": {
18+
"@vitest/coverage-v8": "^2.1.4",
1319
"eslint": "^9.14.0",
14-
"typescript": "^5.6.3"
20+
"typescript": "^5.6.3",
21+
"vitest": "^2.1.4"
1522
}
1623
}

Diff for: packages/utils/tests/index.test.d.ts

-1
This file was deleted.

Diff for: packages/utils/tests/index.test.js

-6
This file was deleted.

Diff for: packages/utils/tests/index.test.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import main from '../../core/src';
1+
import { myUtil } from 'mylib-utils';
2+
import { describe, test, expect } from 'vitest';
23

3-
describe('TypeScript library template', () => {
4-
test('Should return correct result', () => {
5-
expect(main()).toBe('It works!');
4+
describe('My Utils package test', () => {
5+
describe('myUtil()', () => {
6+
test('shoul return a summ of two passed numbers', () => {
7+
const number1 = 5;
8+
const number2 = 10;
9+
10+
const summ = myUtil(number1, number2);
11+
12+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
13+
expect(summ).toBe(15);
14+
});
615
});
716
});

Diff for: vitest.config.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
coverage: {
6+
reporter: ['text'],
7+
reportOnFailure: true,
8+
thresholds: {
9+
lines: 80,
10+
branches: 80,
11+
functions: 80,
12+
statements: 80,
13+
},
14+
},
15+
},
16+
});

0 commit comments

Comments
 (0)