Skip to content

Commit 102e634

Browse files
authored
refactor: migrate to vitest (#606)
1 parent ed5fd0d commit 102e634

20 files changed

+1697
-3768
lines changed

.github/workflows/continuous-integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ jobs:
5959
- name: Install
6060
run: yarn install --immutable
6161
- name: Test
62-
run: yarn test --forceExit
62+
run: yarn test

babel.config.js

-16
This file was deleted.

jest.config.js

-10
This file was deleted.

package.json

+3-13
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"lint:prettier": "prettier -c .",
9292
"lint": "yarn lint:eslint && yarn lint:prettier",
9393
"type-check": "tsc --noEmit",
94-
"test": "jest",
94+
"test": "vitest",
9595
"bench:start-servers": "NODE_ENV=production node benchmark/servers/index.mjs",
9696
"bench": "k6 run benchmark/k6.mjs",
9797
"build:esm": "tsc -b tsconfig.esm.json && node scripts/esm-post-process.mjs",
@@ -107,35 +107,24 @@
107107
"graphql": ">=0.11 <=16"
108108
},
109109
"devDependencies": {
110-
"@babel/core": "^7.24.4",
111-
"@babel/plugin-proposal-class-properties": "^7.18.6",
112-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
113-
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
114-
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
115-
"@babel/preset-env": "^7.24.4",
116-
"@babel/preset-typescript": "^7.24.1",
117110
"@fastify/websocket": "^9.0.0",
118111
"@rollup/plugin-terser": "^0.4.4",
119112
"@rollup/plugin-typescript": "^11.1.6",
120113
"@semantic-release/changelog": "^6.0.3",
121114
"@semantic-release/git": "^10.0.1",
122115
"@types/eslint": "^8.56.10",
123116
"@types/glob": "^8.1.0",
124-
"@types/jest": "^29.5.12",
125117
"@types/ws": "^8.5.10",
126118
"@typescript-eslint/eslint-plugin": "^7.7.0",
127119
"@typescript-eslint/parser": "^7.7.0",
128-
"babel-jest": "^29.7.0",
129120
"bun-types": "^1.1.4",
130121
"eslint": "^8.57.0",
131122
"eslint-config-prettier": "^9.1.0",
132123
"fastify": "^4.26.2",
133124
"fastify-websocket": "4.2.2",
134125
"glob": "^10.3.12",
135126
"graphql": "^16.8.1",
136-
"jest": "^29.7.0",
137-
"jest-environment-jsdom": "^29.7.0",
138-
"jest-jasmine2": "^29.7.0",
127+
"jsdom": "^25.0.1",
139128
"prettier": "^3.2.5",
140129
"replacestream": "^4.0.3",
141130
"rollup": "^4.14.3",
@@ -146,6 +135,7 @@
146135
"typedoc-plugin-markdown": "^3.17.1",
147136
"typescript": "^5.4.5",
148137
"uWebSockets.js": "uNetworking/uWebSockets.js#v20.43.0",
138+
"vitest": "^2.1.8",
149139
"ws": "8.12.0",
150140
"ws7": "npm:ws@^7.5.9"
151141
},

src/__tests__/jest.d.ts

-6
This file was deleted.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should report close error even if complete message followed 1`] = `""error" message expects the 'payload' property to be an array of GraphQL errors, but got "malformed""`;
4+
5+
exports[`should report close error even if complete message followed 2`] = `""error" message expects the 'payload' property to be an array of GraphQL errors, but got "malformed""`;
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`should report invalid message "" with descriptive error 1`] = `[Error: Message is expected to be an object, but got string]`;
4+
5+
exports[`should report invalid message %j with descriptive error 1`] = `[Error: Message is expected to be an object, but got array]`;
6+
7+
exports[`should report invalid message {"id":"","type":"complete"} with descriptive error 1`] = `[Error: "complete" message requires a non-empty 'id' property]`;
8+
9+
exports[`should report invalid message {"id":"","type":"error"} with descriptive error 1`] = `[Error: "error" message requires a non-empty 'id' property]`;
10+
11+
exports[`should report invalid message {"id":"","type":"next"} with descriptive error 1`] = `[Error: "next" message requires a non-empty 'id' property]`;
12+
13+
exports[`should report invalid message {"id":"","type":"subscribe"} with descriptive error 1`] = `[Error: "subscribe" message requires a non-empty 'id' property]`;
14+
15+
exports[`should report invalid message {"id":"id","type":"error","payload":""} with descriptive error 1`] = `[Error: "error" message expects the 'payload' property to be an array of GraphQL errors, but got ""]`;
16+
17+
exports[`should report invalid message {"id":"id","type":"error","payload":[]} with descriptive error 1`] = `[Error: "error" message expects the 'payload' property to be an array of GraphQL errors, but got []]`;
18+
19+
exports[`should report invalid message {"id":"id","type":"error","payload":[{"iam":"invalid"}]} with descriptive error 1`] = `[Error: "error" message expects the 'payload' property to be an array of GraphQL errors, but got [{"iam":"invalid"}]]`;
20+
21+
exports[`should report invalid message {"id":"id","type":"error","payload":{}} with descriptive error 1`] = `[Error: "error" message expects the 'payload' property to be an array of GraphQL errors, but got {}]`;
22+
23+
exports[`should report invalid message {"id":"id","type":"error"} with descriptive error 1`] = `[Error: "error" message expects the 'payload' property to be an array of GraphQL errors, but got undefined]`;
24+
25+
exports[`should report invalid message {"id":"id","type":"next","payload":""} with descriptive error 1`] = `[Error: "next" message expects the 'payload' property to be an object, but got string]`;
26+
27+
exports[`should report invalid message {"id":"id","type":"next"} with descriptive error 1`] = `[Error: "next" message expects the 'payload' property to be an object, but got undefined]`;
28+
29+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":""} with descriptive error 1`] = `[Error: "subscribe" message expects the 'payload' property to be an object, but got string]`;
30+
31+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":[]} with descriptive error 1`] = `[Error: "subscribe" message expects the 'payload' property to be an object, but got array]`;
32+
33+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{"operationName":{},"query":""}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'operationName' property to be a string or nullish or missing, but got object]`;
34+
35+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{"operationName":0,"query":""}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'operationName' property to be a string or nullish or missing, but got number]`;
36+
37+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{"query":"","extensions":""}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'extensions' property to be a an object or nullish or missing, but got string]`;
38+
39+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{"query":"","extensions":0}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'extensions' property to be a an object or nullish or missing, but got number]`;
40+
41+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{"query":"","variables":""}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'variables' property to be a an object or nullish or missing, but got string]`;
42+
43+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{"query":{}}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'query' property to be a string, but got object]`;
44+
45+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{"query":0}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'query' property to be a string, but got number]`;
46+
47+
exports[`should report invalid message {"id":"id","type":"subscribe","payload":{}} with descriptive error 1`] = `[Error: "subscribe" message payload expects the 'query' property to be a string, but got undefined]`;
48+
49+
exports[`should report invalid message {"id":"id","type":"subscribe"} with descriptive error 1`] = `[Error: "subscribe" message expects the 'payload' property to be an object, but got undefined]`;
50+
51+
exports[`should report invalid message {"id":0,"type":"complete"} with descriptive error 1`] = `[Error: "complete" message expects the 'id' property to be a string, but got number]`;
52+
53+
exports[`should report invalid message {"id":0,"type":"subscribe"} with descriptive error 1`] = `[Error: "subscribe" message expects the 'id' property to be a string, but got number]`;
54+
55+
exports[`should report invalid message {"type":""} with descriptive error 1`] = `[Error: Message is missing the 'type' property]`;
56+
57+
exports[`should report invalid message {"type":"complete"} with descriptive error 1`] = `[Error: "complete" message expects the 'id' property to be a string, but got undefined]`;
58+
59+
exports[`should report invalid message {"type":"connection_ack","payload":""} with descriptive error 1`] = `[Error: "connection_ack" message expects the 'payload' property to be an object or nullish or missing, but got ""]`;
60+
61+
exports[`should report invalid message {"type":"connection_init","payload":""} with descriptive error 1`] = `[Error: "connection_init" message expects the 'payload' property to be an object or nullish or missing, but got ""]`;
62+
63+
exports[`should report invalid message {"type":"connection_init","payload":0} with descriptive error 1`] = `[Error: "connection_init" message expects the 'payload' property to be an object or nullish or missing, but got "0"]`;
64+
65+
exports[`should report invalid message {"type":"error"} with descriptive error 1`] = `[Error: "error" message expects the 'id' property to be a string, but got undefined]`;
66+
67+
exports[`should report invalid message {"type":"next"} with descriptive error 1`] = `[Error: "next" message expects the 'id' property to be a string, but got undefined]`;
68+
69+
exports[`should report invalid message {"type":"next"} with descriptive error 2`] = `[Error: "next" message expects the 'id' property to be a string, but got undefined]`;
70+
71+
exports[`should report invalid message {"type":"nuxt"} with descriptive error 1`] = `[Error: Invalid message 'type' property "nuxt"]`;
72+
73+
exports[`should report invalid message {"type":"ping","payload":0} with descriptive error 1`] = `[Error: "ping" message expects the 'payload' property to be an object or nullish or missing, but got "0"]`;
74+
75+
exports[`should report invalid message {"type":"subscribe"} with descriptive error 1`] = `[Error: "subscribe" message expects the 'id' property to be a string, but got undefined]`;
76+
77+
exports[`should report invalid message {"type":0} with descriptive error 1`] = `[Error: Message is missing the 'type' property]`;
78+
79+
exports[`should report invalid message {} with descriptive error 1`] = `[Error: Message is missing the 'type' property]`;
80+
81+
exports[`should report invalid message {} with descriptive error 2`] = `[Error: Message is missing the 'type' property]`;
82+
83+
exports[`should report invalid message 0 with descriptive error 1`] = `[Error: Message is expected to be an object, but got number]`;
84+
85+
exports[`should report invalid message 9 with descriptive error 1`] = `[Error: Message is expected to be an object, but got number]`;
86+
87+
exports[`should report invalid message undefined with descriptive error 1`] = `[Error: Message is expected to be an object, but got function]`;
88+
89+
exports[`should report invalid message undefined with descriptive error 2`] = `[Error: Message is expected to be an object, but got function]`;
90+
91+
exports[`should report invalid message undefined with descriptive error 3`] = `[Error: Message is expected to be an object, but got function]`;

0 commit comments

Comments
 (0)