@hyper-fetch/plugin-devtools 7.5.2 → 7.5.3
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.
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Client } from "@hyper-fetch/core";
|
|
2
|
+
import { createHttpMockingServer, createWebsocketMockingServer } from "@hyper-fetch/testing";
|
|
3
|
+
|
|
4
|
+
import { DevtoolsPlugin } from "../../src/index";
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
startServer: startWebsocketServer,
|
|
8
|
+
stopServer: stopWebsocketServer,
|
|
9
|
+
// emitListenerEvent,
|
|
10
|
+
// expectEmitterEvent,
|
|
11
|
+
} = createWebsocketMockingServer("ws://localhost:2137");
|
|
12
|
+
const {
|
|
13
|
+
resetMocks,
|
|
14
|
+
startServer,
|
|
15
|
+
stopServer,
|
|
16
|
+
// mockRequest
|
|
17
|
+
} = createHttpMockingServer();
|
|
18
|
+
|
|
19
|
+
describe("Backend Devtools - Socket Test", () => {
|
|
20
|
+
let client = new Client({ url: "shared-base-url" }).addPlugin(DevtoolsPlugin({ appName: "TestApp" }));
|
|
21
|
+
let request = client.createRequest()({ endpoint: "/shared-endpoint" });
|
|
22
|
+
|
|
23
|
+
beforeAll(() => {
|
|
24
|
+
startServer();
|
|
25
|
+
startWebsocketServer();
|
|
26
|
+
});
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
client = new Client({ url: "shared-base-url" });
|
|
29
|
+
request = client.createRequest()({ endpoint: "/shared-endpoint" });
|
|
30
|
+
jest.resetAllMocks();
|
|
31
|
+
jest.clearAllMocks();
|
|
32
|
+
resetMocks();
|
|
33
|
+
});
|
|
34
|
+
afterAll(() => {
|
|
35
|
+
stopWebsocketServer();
|
|
36
|
+
stopServer();
|
|
37
|
+
});
|
|
38
|
+
it("should send REQUEST_CREATED event when a request is created", async () => {
|
|
39
|
+
console.warn("test", request);
|
|
40
|
+
expect(true).toBe(true);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "jest-extended";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
|
2
|
+
// allows you to do things like:
|
|
3
|
+
// expect(element).toHaveTextContent(/react/i)
|
|
4
|
+
// learn more: https://github.com/testing-library/jest-dom
|
|
5
|
+
import "@testing-library/jest-dom";
|
|
6
|
+
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
global.IS_REACT_ACT_ENVIRONMENT = true;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WebSocketServer } from "ws";
|
|
2
|
+
|
|
3
|
+
export const initializeWebsocketServer = (port: number) => {
|
|
4
|
+
const wss = new WebSocketServer({ port });
|
|
5
|
+
wss.on("connection", function connection(ws: any) {
|
|
6
|
+
ws.on("error", console.error);
|
|
7
|
+
|
|
8
|
+
ws.on("message", function message(data: any, isBinary: boolean) {
|
|
9
|
+
wss.clients.forEach(function each(c) {
|
|
10
|
+
if (c.readyState === WebSocket.OPEN) {
|
|
11
|
+
c.send(data, { binary: isBinary });
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return wss;
|
|
17
|
+
};
|
package/jest.config.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyper-fetch/plugin-devtools",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.3",
|
|
4
4
|
"description": "Socket devtool plugin for HyperFetch",
|
|
5
5
|
"author": "Maciej Pyrc <maciekpyrc@gmail.com>, Kacper Skawina <kacper.skawina@gmail.com>",
|
|
6
6
|
"homepage": "https://hyperfetch.bettertyped.com/",
|
package/project.json
ADDED