Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support mocking WebSocket APIs #2011

Merged
merged 123 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
a94fe81
test(matchRequestUrl): add ws scheme tests
kettanaito Feb 3, 2024
f1a7f12
chore(ws): draft public api
kettanaito Feb 3, 2024
ae70c43
Merge branch 'main' into feat/ws
kettanaito Feb 6, 2024
d5a9b4c
chore: design "ws.link" api
kettanaito Feb 7, 2024
47ca629
chore: add agnostic "Handler" class
kettanaito Feb 8, 2024
4fe7989
chore: drop non-extendable "Handler"
kettanaito Feb 8, 2024
2f90708
fix: support "WebSocketHandler" in setup apis
kettanaito Feb 8, 2024
ad82a54
feat: export "ws" from core
kettanaito Feb 8, 2024
38f5d27
fix(setupServer): invalid return type
kettanaito Feb 9, 2024
e82d9a7
test(ws): add interception tests
kettanaito Feb 9, 2024
d795e15
chore: update @mswjs/interceptors
kettanaito Feb 14, 2024
a1fb047
fix(ws): opt-out form native event cancellation
kettanaito Feb 14, 2024
2f91ac8
test(ws): add server tests
kettanaito Feb 14, 2024
76ae7a3
Merge branch 'main' into feat/ws
kettanaito Feb 14, 2024
292104c
fix(ws): stale ".currentHandlers()" ref
kettanaito Feb 14, 2024
decffc0
test(ws): add runtime handler tests
kettanaito Feb 15, 2024
245f55f
test(ws): add server event patching tests
kettanaito Feb 15, 2024
2e7863f
chore: update @mswjs/interceptors
kettanaito Feb 15, 2024
5c72475
test(ws): add server error forwarding test
kettanaito Feb 15, 2024
317a3db
fix(setupWorker): add websocket event handling
kettanaito Feb 16, 2024
0a389e7
feat(ws): add "broadcast" and "broadcastExcept" apis
kettanaito Feb 16, 2024
073fe99
chore: update @mswjs/interceptors
kettanaito Feb 18, 2024
654c91d
feat: implement "clients" and "WebSocketClientManager"
kettanaito Feb 18, 2024
ec0154f
chore(WebSocketClientManager): annotate channel messages
kettanaito Feb 25, 2024
e22174f
chore: rename file to "webSocketClientManager"
kettanaito Feb 25, 2024
54c5baf
test(WebSocketClientManager): add unit tests
kettanaito Feb 27, 2024
8f1071b
test(ws): add unit tests
kettanaito Feb 27, 2024
b070b34
chore: upgrade @mswjs/interceptors to 0.26.6
kettanaito Feb 27, 2024
8f07015
chore: fix "singleThread" vitest option
kettanaito Feb 28, 2024
7fed973
chore: tidying up
kettanaito Feb 28, 2024
9c6eeba
fix: apply interceptor in listen/start
kettanaito Feb 29, 2024
082610a
fix: updates interceptors to ditch revocable proxy
kettanaito Feb 29, 2024
c5f6e52
chore: remove "tsconfigPaths" from vitest.config.ts
kettanaito Feb 29, 2024
5306564
Merge branch 'main' into feat/ws
kettanaito Feb 29, 2024
9750c3b
chore: forcefully exit in node-esm tests
kettanaito Feb 29, 2024
0329b52
Merge branch 'main' into feat/ws
kettanaito Mar 12, 2024
1bb42ae
fix(WebSocketClientManager): post URL string, cannot clone URL instances
kettanaito Mar 12, 2024
69f1390
test: add client interception browser tests
kettanaito Mar 12, 2024
f1f9f73
chore: update @mswjs/interceptors to 0.26.8
kettanaito Mar 12, 2024
3b5fa3d
chore(WebSocketServer): use ipv4 addresses for "path-to-regexp" matching
kettanaito Mar 12, 2024
01ccef7
test: call socket instance "socket" in tests
kettanaito Mar 12, 2024
7daef9e
test: add server websocket tests
kettanaito Mar 12, 2024
7ca1306
test(WebSocketClientManager): adjust tests for "url" type change
kettanaito Mar 12, 2024
082d628
test: assert on ArrayBuffer instead of Blob
kettanaito Mar 13, 2024
a0e0db1
test: add server.connect() browser tests
kettanaito Mar 13, 2024
38ea842
test: add no error on non-existing connect browser test
kettanaito Mar 13, 2024
8ec2183
test: add ws.use() browser tests
kettanaito Mar 13, 2024
47aa473
test: fix leftout test
kettanaito Mar 13, 2024
09b4087
chore(release): v2.3.0-ws.rc-1
kettanaito Mar 13, 2024
372f183
fix: export "WebSocketHandler" and "WebSocketHandlerEventMap"
kettanaito Mar 14, 2024
c7b5c60
Merge branch 'main' into feat/ws
kettanaito Mar 17, 2024
b04859c
fix: marks "WebSocketHandlerEventMap" as type export
kettanaito Mar 17, 2024
3e8a345
chore: update @mswjs/interceptors to 0.26.11 (server.close)
kettanaito Mar 24, 2024
7a93c95
test(setupServer): ws apply test
kettanaito Mar 24, 2024
04ae9e9
test(setupWorker): ws apply test
kettanaito Mar 24, 2024
59a648b
test: fix typo in "ws.intercept.client.browser.test.ts"
kettanaito Mar 24, 2024
32dacec
test: rename test for consistency
kettanaito Mar 24, 2024
180205d
fix(getTimestamp): support milliseconds
kettanaito Mar 26, 2024
84ad998
Merge branch 'main' into feat/ws
kettanaito Mar 27, 2024
64b6a82
test(ws): assert WebSocket patch without event handlers
kettanaito Mar 29, 2024
fc8b67d
feat(ws): add logging to WebSocket connections (#2112)
kettanaito Mar 30, 2024
0776e73
chore(release): v2.3.0-ws.rc-2
kettanaito Apr 1, 2024
c6450d9
chore: move "handleWebSocketEvent" to "ws"
kettanaito Apr 2, 2024
b29ceea
fix: export "WebSocketLink" type
kettanaito Apr 2, 2024
2ace289
chore: move "ws" to core root
kettanaito Apr 2, 2024
bfd9130
Merge branch 'main' into feat/ws
kettanaito Apr 2, 2024
718cf0e
chore(release): v2.3.0-ws.rc-3
kettanaito Apr 2, 2024
1ffaed9
fix: use pretty colors for logs
kettanaito Apr 2, 2024
46ffbc4
test(ws): fix wrong assertion message
kettanaito Apr 6, 2024
dddd4fb
feat(ws): enable client-to-server forwarding by default
kettanaito Apr 7, 2024
7d2a971
chore(release): v2.3.0-ws.rc-4
kettanaito Apr 9, 2024
f6a8723
fix: update @mswjs/interceptors to 0.27.1
kettanaito Apr 9, 2024
74215a3
chore(release): v2.3.0-ws.rc-5
kettanaito Apr 9, 2024
ef0ebe3
fix(WebSocketClientManager): use localStorage for clients persistence…
kettanaito Apr 12, 2024
25da0da
chore(release): v2.3.0-ws.rc-6
kettanaito Apr 12, 2024
026f24f
fix: purge persisted clients on page reload (#2133)
kettanaito Apr 15, 2024
a79d50a
Merge branch 'main' into feat/ws
kettanaito May 8, 2024
f5f6020
fix: update `@mswjs/interceptors` to 0.30.0 (#2175)
DanielleHuisman Jun 13, 2024
8817812
Merge branch 'main' into feat/ws
kettanaito Jun 13, 2024
d7a6ce9
chore(release): v2.3.0-ws.rc-7
kettanaito Jun 13, 2024
37f5d29
Merge branch 'main' into feat/ws
kettanaito Jul 4, 2024
f692222
fix(ws): call BroadcastChannel.unref in Node.js environment (#2196)
DanielleHuisman Jul 5, 2024
1889dab
chore: polish the implementation
kettanaito Jul 31, 2024
a556b7c
docs: add jsdoc to "ws" link
kettanaito Jul 31, 2024
9a14c77
Merge branch 'main' into feat/ws
kettanaito Jul 31, 2024
f27dd03
chore: update @mswjs/interceptors
kettanaito Aug 1, 2024
1b98e1b
Merge branch 'main' into feat/ws
kettanaito Aug 1, 2024
8dd31a1
test(ws.logging): closure do not trigger errors
kettanaito Aug 6, 2024
907ae2a
Merge branch 'main' into feat/ws
kettanaito Aug 6, 2024
e006296
Merge branch 'main' into feat/ws
kettanaito Aug 29, 2024
c5b1581
Merge branch 'main' into feat/ws
kettanaito Sep 17, 2024
6e0cbc6
feat(ws): use IndexedDB to store clients
kettanaito Sep 17, 2024
a50bed2
fix(ws): delete runtime clients when worker stops
kettanaito Sep 17, 2024
434e4cf
fix: use different websocket client store in browser and node
kettanaito Sep 17, 2024
fde2b4e
chore: fix logger console usage
kettanaito Sep 17, 2024
06c9cf2
fix(WebSocketClientManager): account for async nature of "addConnection"
kettanaito Sep 17, 2024
bdf9e88
chore(release): v2.3.0-ws.rc-8
kettanaito Sep 17, 2024
96319c9
fix: export `WebSocketData` and `WebSocketEventListener` types
kettanaito Sep 17, 2024
f7f9f8a
feat: rename ".on()" to ".addEventListener()" on ws.link
kettanaito Sep 18, 2024
0c99078
chore(release): v2.3.0-ws.rc-9
kettanaito Sep 19, 2024
a45981f
test: check `event.data` before resolving
kettanaito Sep 19, 2024
4bf38e0
test: add `client.send` tests
kettanaito Sep 19, 2024
b12d53e
chore: iterate over handlers via for/of
kettanaito Sep 23, 2024
4b60591
feat: support `onUnhandledRequest` for WebSocket
kettanaito Sep 23, 2024
5041433
fix: ignore duplicate saves of clients in the database
kettanaito Sep 23, 2024
37831ac
Merge branch 'main' into feat/ws
kettanaito Sep 24, 2024
c384c13
fix(handleRequest): use `RequestHandler` as `handlers` type
kettanaito Sep 26, 2024
1b1e0f8
fix: make `close` event cancelable
kettanaito Sep 27, 2024
6b8b0a2
fix: cancelable server closures, `server.socket`
kettanaito Sep 30, 2024
ab543ac
chore(release): v2.3.0-ws.rc-10
kettanaito Sep 30, 2024
d9a0480
fix: simplify websocket logging
kettanaito Oct 2, 2024
a9cd861
fix: prevent internal `server.send` being logged out
kettanaito Oct 2, 2024
b6c8374
chore(release): v2.3.0-ws.rc-11
kettanaito Oct 2, 2024
7f89cac
fix: support stopping event propagation
kettanaito Oct 7, 2024
92f1d53
chore(release): v2.3.0-ws.rc-12
kettanaito Oct 7, 2024
7b7aa3d
Merge branch 'main' into feat/ws
kettanaito Oct 23, 2024
a2fd5d5
Merge branch 'main' into feat/ws
kettanaito Oct 28, 2024
8ea8487
test(modules): remove `process.exit(0)` from runtime scripts
kettanaito Oct 28, 2024
dba8d20
chore: revert version to upstream
kettanaito Oct 28, 2024
4847e75
fix: add "msw/core/ws" export
kettanaito Oct 28, 2024
d82bef6
fix: export `WebSocketHandlerConnection` type
kettanaito Oct 28, 2024
bbc98ca
test: add type tests
kettanaito Oct 28, 2024
773a6d2
test(WebSocketClientManager): increase max listeners count
kettanaito Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ msw-*.tgz
# Smoke test temporary files.
/package.json.copy
/examples

tsconfig.vitest-temp.json
/test/modules/node/node-esm-tests
tsconfig.vitest-temp.json
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
"import": "./lib/core/graphql.mjs",
"default": "./lib/core/graphql.js"
},
"./core/ws": {
"types": "./lib/core/ws.d.ts",
"require": "./lib/core/ws.js",
"import": "./lib/core/ws.mjs",
"default": "./lib/core/ws.js"
},
"./mockServiceWorker.js": "./lib/mockServiceWorker.js",
"./package.json": "./package.json"
},
Expand Down Expand Up @@ -138,6 +144,7 @@
"@bundled-es-modules/tough-cookie": "^0.1.6",
"@inquirer/confirm": "^5.0.0",
"@mswjs/interceptors": "^0.36.5",
"@open-draft/deferred-promise": "^2.2.0",
"@open-draft/until": "^2.1.0",
"@types/cookie": "^0.6.0",
"@types/statuses": "^2.0.4",
Expand All @@ -154,6 +161,7 @@
"devDependencies": {
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@fastify/websocket": "^8.3.1",
"@open-draft/test-server": "^0.4.2",
"@ossjs/release": "^0.8.1",
"@playwright/test": "^1.48.0",
Expand All @@ -177,6 +185,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"express": "^5.0.0",
"fastify": "^4.26.0",
"fs-extra": "^11.2.0",
"fs-teardown": "^0.3.0",
"glob": "^11.0.0",
Expand Down
Loading
Loading