Skip to content

Commit b571de4

Browse files
authored
Merge pull request #2 from jdevelop-io/feature/jest
✨ feat(jest): add jest
2 parents b509c32 + d6a9fd1 commit b571de4

File tree

7 files changed

+2752
-21
lines changed

7 files changed

+2752
-21
lines changed

.github/workflows/test.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch: ~
11+
12+
jobs:
13+
unit_tests:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- uses: pnpm/action-setup@v4
21+
name: Install pnpm
22+
with:
23+
version: 9.12.0
24+
run_install: false
25+
26+
- name: Install Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 20.18.0
30+
cache: 'pnpm'
31+
32+
- name: Install dependencies
33+
run: pnpm install
34+
35+
- name: Run unit tests
36+
run: pnpm test:coverage --verbose

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/.idea/
22
/node_modules/
33
/dist/
4+
/coverage/

jest.config.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* For a detailed explanation regarding each configuration property, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
import type { Config } from 'jest'
7+
8+
const config: Config = {
9+
preset: 'ts-jest',
10+
11+
// Automatically clear mock calls, instances, contexts and results before every test
12+
clearMocks: true,
13+
14+
// Indicates whether the coverage information should be collected while executing the test
15+
collectCoverage: false,
16+
17+
// The directory where Jest should output its coverage files
18+
coverageDirectory: 'coverage',
19+
20+
// An array of glob patterns indicating a set of files for which coverage information should be collected
21+
collectCoverageFrom: ['src/**/*.ts'],
22+
23+
// An array of regexp pattern strings used to skip coverage collection
24+
coveragePathIgnorePatterns: ['/node_modules/', '/coverage/', '/dist/'],
25+
26+
// Indicates which provider should be used to instrument code for coverage
27+
coverageProvider: 'babel',
28+
29+
// A list of reporter names that Jest uses when writing coverage reports
30+
coverageReporters: ['json', 'text', 'lcov', 'clover'],
31+
32+
// An object that configures minimum threshold enforcement for coverage results
33+
coverageThreshold: {
34+
global: {
35+
branches: 100,
36+
functions: 100,
37+
lines: 100,
38+
statements: 100,
39+
},
40+
},
41+
42+
// Make calling deprecated APIs throw helpful error messages
43+
errorOnDeprecated: true,
44+
45+
// An array of directory names to be searched recursively up from the requiring module's location
46+
moduleDirectories: ['node_modules'],
47+
48+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
49+
moduleNameMapper: {
50+
'^@/(.*)$': '<rootDir>/src/$1',
51+
},
52+
}
53+
54+
export default config

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,18 @@
1414
"scripts": {
1515
"prebuild": "rimraf dist",
1616
"build": "pnpm prebuild && tsc",
17-
"build:watch": "pnpm build --watch"
17+
"build:watch": "pnpm build --watch",
18+
"test": "jest",
19+
"test:watch": "jest --watch",
20+
"test:coverage": "jest --coverage",
21+
"test:coverage:watch": "jest --coverage --watch"
1822
},
1923
"devDependencies": {
24+
"@types/jest": "^29.5.13",
25+
"jest": "^29.7.0",
2026
"rimraf": "^6.0.1",
27+
"ts-jest": "^29.2.5",
28+
"ts-node": "^10.9.2",
2129
"typescript": "^5.6.2"
2230
}
2331
}

0 commit comments

Comments
 (0)