Skip to content

Commit 8e9d25d

Browse files
authored
Convert Jest to Vitest (#1479)
* init convertion * get rid of jest * Fix tests with vitest * minor fixes
1 parent 2407448 commit 8e9d25d

13 files changed

+968
-1999
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
project: "./tsconfig.json",
77
createDefaultProgram: true,
88
},
9-
extends: ["react-app", "react-app/jest", "prettier"],
9+
extends: ["react-app", "prettier"],
1010
rules: {
1111
"import/no-extraneous-dependencies": [
1212
"error",

package.json

+1-8
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,17 @@
4444
"@babel/preset-env": "^7.22.5",
4545
"@babel/preset-react": "^7.22.5",
4646
"@hot-loader/react-dom": "^17.0.2",
47-
"@jest/globals": "^28.1.3",
4847
"@types/asap": "^2.0.0",
4948
"@types/chrome": "^0.0.237",
5049
"@types/copy-webpack-plugin": "^10.1.0",
51-
"@types/jest": "^28.1.8",
52-
"@types/jsdom": "^20.0.1",
50+
"@types/jsdom": "^21.1.1",
5351
"@types/node": "^18.16.17",
5452
"@types/qrcode.react": "^1.0.2",
5553
"@types/react": "^18.2.14",
5654
"@types/react-dom": "^18.2.6",
5755
"@types/react-hot-loader": "^4.1.1",
5856
"@types/react-router-dom": "^5.3.3",
5957
"@typescript-eslint/parser": "^5.59.9",
60-
"babel-jest": "^28.1.3",
6158
"babel-loader": "^8.3.0",
6259
"bn.js": "^5.2.1",
6360
"buffer": "^6.0.3",
@@ -73,17 +70,13 @@
7370
"html-minimizer-webpack-plugin": "^4.3.0",
7471
"html-webpack-plugin": "^5.5.3",
7572
"http-server": "^14.1.1",
76-
"jest": "^28.1.3",
77-
"jest-environment-jsdom": "^28.1.3",
78-
"jest-silent-reporter": "^0.5.0",
7973
"jsdom": "^19.0.0",
8074
"nodemon": "^2.0.22",
8175
"prettier": "^2.8.8",
8276
"regenerator-runtime": "^0.13.11",
8377
"rimraf": "^3.0.2",
8478
"stream-browserify": "^3.0.0",
8579
"style-loader": "^3.3.3",
86-
"ts-jest": "^28.0.8",
8780
"ts-loader": "^9.4.3",
8881
"ts-node": "^10.9.1",
8982
"typedoc": "^0.24.8",

packages/connect/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ coverage
77
.chains
88

99
/src/specs/*.json
10+
/src/connector/specs/*.ts
1011
jest.*.ts

packages/connect/jest.config.cjs

-17
This file was deleted.

packages/connect/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"postinstall": "node build-js-specs.mjs",
3030
"build-js-specs": "node build-js-specs.mjs",
3131
"pretest": "yarn build",
32-
"test": "node --no-warnings --experimental-vm-modules ../../node_modules/jest/bin/jest.js --colors --coverage",
32+
"test": "vitest",
3333
"deep-clean": "yarn clean && rm -rf node_modules",
3434
"clean": "rm -rf dist tsconfig.tsbuildinfo",
3535
"build": "yarn run build:mjs && yarn run build:cjs && bash ./fix-package-type.sh",
@@ -42,6 +42,7 @@
4242
"smoldot": "1.0.12"
4343
},
4444
"devDependencies": {
45-
"eslint": "^8.44.0"
45+
"eslint": "^8.44.0",
46+
"vitest": "^0.33.0"
4647
}
4748
}

packages/connect/src/connector/extension.test.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { it, describe, expect } from "vitest"
15
import { randomBytes } from "crypto"
26
import {
37
ToApplication,
@@ -8,18 +12,21 @@ import { AlreadyDestroyedError, CrashError } from "./types"
812

913
// we have to fake this API on node
1014
import { WellKnownChain } from "../WellKnownChain.js"
11-
;(globalThis.crypto as any) = {
12-
getRandomValues: <T extends ArrayBufferView | null>(arr: T) => {
13-
if (!arr) return arr
14-
const tmp = new Uint8Array(arr.byteLength)
15-
const randomBytesBuffer = randomBytes(tmp.length)
16-
tmp.set(randomBytesBuffer)
17-
const test = new DataView(arr.buffer)
18-
for (let i = 0; i < tmp.length; i++) {
19-
test.setUint8(i, tmp[i])
20-
}
21-
return arr
22-
},
15+
16+
if (!globalThis.crypto) {
17+
;(globalThis.crypto as any) = {
18+
getRandomValues: <T extends ArrayBufferView | null>(arr: T) => {
19+
if (!arr) return arr
20+
const tmp = new Uint8Array(arr.byteLength)
21+
const randomBytesBuffer = randomBytes(tmp.length)
22+
tmp.set(randomBytesBuffer)
23+
const test = new DataView(arr.buffer)
24+
for (let i = 0; i < tmp.length; i++) {
25+
test.setUint8(i, tmp[i])
26+
}
27+
return arr
28+
},
29+
}
2330
}
2431

2532
const getClientMessage = (timeout = 10) =>

0 commit comments

Comments
 (0)