Skip to content

Commit 4404e56

Browse files
committed
feat: 添加Jest
1 parent e608184 commit 4404e56

File tree

7 files changed

+8904
-5038
lines changed

7 files changed

+8904
-5038
lines changed

.github/workflows/coveralls.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
node: [ 18, 20, 21]
14+
node: [18, 20, 21]
1515
os: [ubuntu-latest, windows-latest]
1616

1717
steps:
@@ -24,31 +24,30 @@ jobs:
2424
node-version: ${{ matrix.node }}
2525

2626
- name: Install npm dependencies
27-
run: npm install # switch to `npm ci` when Node.js 6 support is dropped
27+
run: npm install
2828

2929
# - name: Run Build
3030
# run: npm run docs:build
31+
- name: Run tests with coverage
32+
run: npm run coverage
3133

32-
- name: test token
33-
run: echo "${{ secrets.COVERALLS_REPO_TOKEN }}"
34-
35-
- name: Coveralls
34+
- name: Upload coverage to Coveralls
3635
uses: coverallsapp/github-action@v2
3736
with:
3837
github-token: ${{ secrets.GITHUB_TOKEN }}
39-
flag-name: ${{matrix.os}}-node-${{ matrix.node }}
38+
path-to-lcov: ./coverage/lcov.info
39+
flag-name: ${{ matrix.os }}-node-${{ matrix.node }}
4040
parallel: true
4141

4242
finish:
4343
needs: test
4444
runs-on: ubuntu-latest
4545
steps:
4646
- name: Clone repository
47-
uses: actions/checkout@v2
47+
uses: actions/checkout@v3
4848

4949
- name: Coveralls Finished
5050
uses: coverallsapp/github-action@v2
5151
with:
5252
github-token: ${{ secrets.GITHUB_TOKEN }}
53-
parallel-finished: true
54-
53+
parallel-finished: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ node_modules/
33
src/.vuepress/.cache/
44
src/.vuepress/.temp/
55
src/.vuepress/dist/
6+
coverage

babel.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['@babel/preset-env', '@babel/preset-typescript'],
3+
};

jest.config.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/** @type {import('jest').Config} */
2+
const config = {
3+
collectCoverage: true,
4+
coverageDirectory: "coverage",
5+
coverageProvider: "v8",
6+
testEnvironment: "node",
7+
transform: {
8+
"^.+\\.tsx?$": "babel-jest",
9+
},
10+
moduleFileExtensions: ["js", "jsx", "ts", "tsx", "json", "node"],
11+
testMatch: [
12+
"**/__tests__/**/*.[jt]s?(x)",
13+
"**/?(*.)+(spec|test).[tj]s?(x)"
14+
],
15+
collectCoverageFrom: [
16+
"src/**/*.{js,jsx,ts,tsx}",
17+
"!src/**/*.d.ts", // 排除类型声明文件
18+
],
19+
};
20+
21+
export default config;

0 commit comments

Comments
 (0)