Skip to content

Commit 589312d

Browse files
committedSep 4, 2023
Add swc/jest tests. Upgrade packages
1 parent 5a9b53b commit 589312d

7 files changed

+4439
-24005
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ vi.useFakeTimers({
7575

7676
## Testing framework support
7777

78-
We aim to support all major testing frameworks that support jsdom. Internally, there are no dependencies on any of them, so it's likely that it will work out of the box. Currently tested and confirmed to work with [jest](https://jestjs.io/) and [vitest](https://vitest.dev/). If you encounter any problems with other testing frameworks, please open an issue.
78+
We aim to support all major testing frameworks that support jsdom. Internally, there are no dependencies on any of them, so it's likely that it will work out of the box. Currently tested and confirmed to work with [jest](https://jestjs.io/), [@swc/jest](https://swc.rs/docs/usage/jest) and [vitest](https://vitest.dev/) (with [some setup](#with-vitest)). If you encounter any problems with other testing frameworks, please open an issue.
7979

8080
## Mock viewport
8181

‎examples/package-lock.json

+59-12,916
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
"scripts": {
2121
"start": "react-scripts start",
2222
"build": "react-scripts build",
23-
"test": "react-scripts test --watchAll=false",
24-
"eject": "react-scripts eject",
25-
"vitest": "vitest --config ./vitest.config.ts run"
23+
"test:jest": "react-scripts test --watchAll=false",
24+
"test:swc": "jest --config ./swcjest.config.js",
25+
"test:vi": "vitest --config ./vitest.config.ts run",
26+
"test:all": "npm run test:jest && npm run test:vi && npm run test:swc",
27+
"eject": "react-scripts eject"
2628
},
2729
"eslintConfig": {
2830
"extends": [

‎examples/swcjest.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
testEnvironment: 'jsdom',
3+
transform: {
4+
'^.+\\.(t|j)sx?$': [
5+
'@swc/jest',
6+
// This is needed to make swc/jest work with React 18 in github actions
7+
{
8+
jsc: {
9+
transform: {
10+
react: {
11+
runtime: 'automatic',
12+
},
13+
},
14+
},
15+
},
16+
],
17+
},
18+
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
19+
moduleNameMapper: {
20+
'\\.(css|less)$': 'identity-obj-proxy',
21+
},
22+
};

‎package-lock.json

+4,332-11,075
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsdom-testing-mocks",
3-
"version": "1.10.0",
3+
"version": "1.11.0",
44
"author": "Ivan Galiatin",
55
"license": "MIT",
66
"description": "A set of tools for emulating browser behavior in jsdom environment",
@@ -37,11 +37,11 @@
3737
"scripts": {
3838
"watch": "tsup --watch",
3939
"build": "tsup",
40-
"test": "jest",
41-
"vitest": "vitest --config ./vitest.config.ts run",
42-
"test:examples": "npm --prefix ./examples run test",
43-
"vitest:examples": "npm --prefix ./examples run vitest",
44-
"test:all": "npm run test && npm run vitest && npm run test:examples && npm run vitest:examples",
40+
"test:jest": "jest",
41+
"test:swc": "jest --config ./swcjest.config.ts",
42+
"test:vi": "vitest --config ./vitest.config.ts run",
43+
"test:examples": "npm --prefix ./examples run test:all",
44+
"test:all": "npm run test:jest && npm run test:vi && npm run test:swc && npm run test:examples",
4545
"lint": "eslint src/ --ext .ts,.tsx",
4646
"prepare": "tsup"
4747
},
@@ -76,8 +76,10 @@
7676
"css-mediaquery": "^0.1.2"
7777
},
7878
"devDependencies": {
79+
"@swc/core": "^1.3.82",
80+
"@swc/jest": "^0.2.29",
7981
"@types/css-mediaquery": "^0.1.1",
80-
"@types/jest": "^28.1.4",
82+
"@types/jest": "^28.1.8",
8183
"@types/testing-library__jest-dom": "^5.14.5",
8284
"@typescript-eslint/eslint-plugin": "^5.30.3",
8385
"@typescript-eslint/parser": "^5.30.3",
@@ -86,11 +88,11 @@
8688
"eslint-plugin-jsx-a11y": "^6.6.0",
8789
"eslint-plugin-react": "^7.30.1",
8890
"husky": "4.2.3",
89-
"jest": "^28.1.2",
90-
"jest-environment-jsdom": "^28.1.2",
91+
"jest": "^28.1.3",
92+
"jest-environment-jsdom": "^28.1.3",
9193
"jest-fail-on-console": "^3.1.1",
9294
"prettier": "^2.7.1",
93-
"ts-jest": "^28.0.5",
95+
"ts-jest": "^28.0.8",
9496
"ts-node": "^10.8.2",
9597
"tslib": "^2.4.0",
9698
"tsup": "^6.1.3",

‎swcjest.config.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
testEnvironment: 'jsdom',
3+
transform: {
4+
'^.+\\.(t|j)sx?$': '@swc/jest',
5+
},
6+
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
7+
testPathIgnorePatterns: ['/node_modules/', '/examples/'],
8+
};

0 commit comments

Comments
 (0)
Please sign in to comment.