vitest-websocket-mock 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,7 +97,7 @@ A `WS` instance has the following attributes:
97
97
  on received messages easier:
98
98
 
99
99
  - `.toReceiveMessage`: async matcher that waits for the next message received
100
- by the the mock websocket server, and asserts its content. It will time out
100
+ by the mock websocket server, and asserts its content. It will time out
101
101
  with a helpful message after 1000ms.
102
102
  - `.toHaveReceivedMessages`: synchronous matcher that checks that all the
103
103
  expected messages have been received by the mock websocket server.
@@ -319,7 +319,7 @@ under the hood to mock out WebSocket clients.
319
319
  Out of the box, Mock Socket will only mock out the global `WebSocket` object.
320
320
  If you are using a third-party WebSocket client library (eg. a Node.js
321
321
  implementation, like [`ws`](https://github.com/websockets/ws)), you'll need
322
- to set up a [manual mock](https://jestjs.io/docs/en/manual-mocks#mocking-node-modules):
322
+ to set up a [manual mock](https://vitest.dev/api/vi.html#vi-mock):
323
323
 
324
324
  - Create a `__mocks__` folder in your project root
325
325
  - Add a new file in the `__mocks__` folder named after the library you want to
@@ -333,6 +333,19 @@ to set up a [manual mock](https://jestjs.io/docs/en/manual-mocks#mocking-node-mo
333
333
  export { WebSocket as default } from 'mock-socket';
334
334
  ```
335
335
 
336
+ - Somewhere in the test files, call `vi.mock` with the name of the library you want to mock. For instance, for the `ws` library:
337
+
338
+ ```js
339
+ // foo.test.js
340
+
341
+ import WebSocket from 'ws';
342
+ import { vi } from 'vitest';
343
+
344
+ vi.mock('ws');
345
+
346
+ // do some tests...
347
+ ```
348
+
336
349
  **NOTE** The `ws` library is not 100% compatible with the browser API, and
337
350
  the `mock-socket` library that `vitest-websocket-mock` uses under the hood only
338
351
  implements the browser API.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Server, Client, CloseOptions, ServerOptions } from 'mock-socket';
1
+ import { Server, ServerOptions, Client, CloseOptions } from 'mock-socket';
2
2
  import { RawMatcherFn } from '@vitest/expect';
3
3
 
4
4
  /**
@@ -78,11 +78,11 @@ interface CustomMatchers<R = unknown> {
78
78
  * @copyright Akiomi Kamakura 2023
79
79
  */
80
80
 
81
- declare module 'vitest' {
81
+ declare module '@vitest/expect' {
82
82
  interface Assertion<T = any> extends CustomMatchers<T> {
83
83
  }
84
84
  interface AsymmetricMatchersContaining extends CustomMatchers {
85
85
  }
86
86
  }
87
87
 
88
- export { ReceiveMessageOptions, WS, WS as default, deriveToHaveReceivedMessage, deriveToReceiveMessage };
88
+ export { type ReceiveMessageOptions, WS, WS as default, deriveToHaveReceivedMessage, deriveToReceiveMessage };
package/dist/index.js CHANGED
@@ -2,8 +2,7 @@ var __defProp = Object.defineProperty;
2
2
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
3
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
4
  }) : x)(function(x) {
5
- if (typeof require !== "undefined")
6
- return require.apply(this, arguments);
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
7
6
  throw Error('Dynamic require of "' + x + '" is not supported');
8
7
  });
9
8
  var __export = (target, all) => {
@@ -172,7 +171,7 @@ function deriveToHaveReceivedMessage(name, fn) {
172
171
 
173
172
  // src/derivers/deriveToReceiveMessage.ts
174
173
  var WAIT_DELAY = 1e3;
175
- var TIMEOUT = Symbol("timeout");
174
+ var TIMEOUT = /* @__PURE__ */ Symbol("timeout");
176
175
  function deriveToReceiveMessage(name, fn) {
177
176
  return async function(ws, expected, options) {
178
177
  const isWS = ws instanceof WS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitest-websocket-mock",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Mock websockets and assert complex websocket interactions with Vitest",
5
5
  "type": "module",
6
6
  "repository": {
@@ -36,7 +36,7 @@
36
36
  "devDependencies": {
37
37
  "@typescript-eslint/eslint-plugin": "^5.59.0",
38
38
  "@typescript-eslint/parser": "^5.59.0",
39
- "@vitest/coverage-v8": "^2.0.3",
39
+ "@vitest/coverage-v8": "4.1.1",
40
40
  "eslint": "^8.38.0",
41
41
  "eslint-config-prettier": "^8.5.0",
42
42
  "eslint-config-react-app": "^7.0.1",
@@ -45,20 +45,23 @@
45
45
  "eslint-plugin-simple-import-sort": "^10.0.0",
46
46
  "prettier": "^2.0.2",
47
47
  "rimraf": "^4.1.2",
48
- "tsup": "^7.0.0",
48
+ "tsup": "^8.5.1",
49
49
  "typescript": "^4.0.2",
50
- "vite": "^5.0.6",
51
- "vitest": "^2.0.3"
50
+ "vite": "^8.1.4",
51
+ "vitest": "4.1.1"
52
52
  },
53
53
  "peerDependencies": {
54
- "vitest": ">=2"
54
+ "vitest": ">=4"
55
55
  },
56
56
  "dependencies": {
57
- "@vitest/utils": "^2.0.3",
57
+ "@vitest/utils": "4.1.1",
58
58
  "mock-socket": "^9.2.1"
59
59
  },
60
60
  "files": [
61
61
  "dist",
62
62
  "LICENSE"
63
- ]
63
+ ],
64
+ "overrides": {
65
+ "esbuild": "^0.28.1"
66
+ }
64
67
  }