Skip to content

Commit a723d73

Browse files
authored
refactor: add Jest directly (#755)
* refactor: use jest directly * ci: enable coverage collecting
1 parent 6ee5f8f commit a723d73

File tree

7 files changed

+1374
-6870
lines changed

7 files changed

+1374
-6870
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ jobs:
2020
install-command: yarn --frozen-lockfile --ignore-engines
2121
- name: Run tests
2222
run: yarn test
23-
# - name: Collect coverage
24-
# uses: coverallsapp/github-action@master
25-
# if: success()
26-
# with:
27-
# github-token: ${{ secrets.GITHUB_TOKEN }}
23+
- name: Collect coverage
24+
uses: codecov/codecov-action@v2
25+
if: success()
26+
with:
27+
files: ./coverage/lcov.info
28+
fail_ci_if_error: true

jest.config.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"testEnvironment": "jsdom",
3+
"testRegex": "test/.*\\.test\\.(jsx?|tsx?)$",
4+
"setupFilesAfterEnv": ["<rootDir>/test/setup.js"],
5+
"transform": {
6+
"^.+\\.(t|j)sx?$": ["@swc/jest", {
7+
"module": {
8+
"type": "commonjs"
9+
},
10+
"env": {
11+
"targets": {
12+
"node": 12
13+
}
14+
}
15+
}]
16+
},
17+
"collectCoverage": true,
18+
"collectCoverageFrom": [
19+
"src/**/*.{js,jsx,ts,tsx}",
20+
"!**/node_modules/**"
21+
],
22+
"coverageReporters": [
23+
"lcovonly",
24+
"text"
25+
]
26+
}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
"test": "yarn test:unit && yarn test:lint && yarn test:build",
3232
"test:build": "yarn build",
3333
"test:lint": "eslint src/**/*.{ts,tsx}",
34-
"test:unit": "cross-env CI=1 react-scripts test --env=jsdom",
35-
"test:watch": "react-scripts test --env=jsdom",
34+
"test:unit": "jest -c jest.config.json",
3635
"format": "prettier --write src",
3736
"predeploy": "cd example && yarn && yarn build",
3837
"deploy": "gh-pages -d example/build"
@@ -45,16 +44,17 @@
4544
"react": "^16.8.0 || ^17.0.0"
4645
},
4746
"devDependencies": {
47+
"@swc/core": "^1.2.95",
48+
"@swc/jest": "^0.2.4",
4849
"@testing-library/jest-dom": "^5.5.0",
49-
"@testing-library/react": "^10.0.3",
50-
"@types/jest": "^25.1.4",
50+
"@testing-library/react": "^12.1.2",
51+
"@types/jest": "^27.0.2",
5152
"@types/lodash": "^4.14.150",
5253
"@types/react": "^16.9.27",
5354
"@typescript-eslint/eslint-plugin": "^2.26.0",
5455
"@typescript-eslint/parser": "^2.26.0",
5556
"babel-eslint": "^10.0.3",
5657
"chart.js": "^3.1.0",
57-
"cross-env": "^7.0.2",
5858
"eslint": "^6.8.0",
5959
"eslint-config-prettier": "^6.7.0",
6060
"eslint-config-standard": "^14.1.0",
@@ -66,12 +66,12 @@
6666
"eslint-plugin-react": "^7.17.0",
6767
"eslint-plugin-standard": "^4.0.1",
6868
"gh-pages": "^2.2.0",
69+
"jest": "^27.2.5",
6970
"jest-canvas-mock": "^2.2.0",
7071
"microbundle-crl": "^0.13.11",
7172
"prettier": "^2.0.4",
7273
"react": "^17.0.1",
7374
"react-dom": "^17.0.1",
74-
"react-scripts": "^3.4.3",
7575
"react-test-renderer": "^17.0.1"
7676
},
7777
"files": [
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import * as React from 'react';
1+
import React from 'react';
22
import { render, cleanup, fireEvent } from '@testing-library/react';
33
import Chart from 'chart.js/auto';
4-
import ChartComponent from '../chart';
4+
import ChartComponent from '../src/chart';
55

66
describe('<ChartComponent />', () => {
77
const data = {
File renamed without changes.

yarn.lock

Lines changed: 1334 additions & 6857 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)