Initial commit

This commit is contained in:
2025-12-27 20:24:47 +01:00
commit 7b6f164130
5573 changed files with 727178 additions and 0 deletions

84
node_modules/mock-socket/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,84 @@
# Mock Socket Changelog
### v9.3.1 (Sep 11th, 2023)
- [#383](https://github.com/thoov/mock-socket/pull/383) [BUGFIX] Calling close in the CONNECTING state should not cause onopen to be called #383
### v9.3.0 (Sep 5th, 2023)
- [#382](https://github.com/thoov/mock-socket/pull/382) The send() method now only throws when the socket is in the CONNECTING state
### v9.2.1 (Feb 14th, 2023)
- [#376](https://github.com/thoov/mock-socket/pull/376) Do not normalize data when emitting to socket.io sockets
### v9.2.0 (Feb 9th, 2023)
- [#373](https://github.com/thoov/mock-socket/pull/373) Handle proxy events properly
- [#370](https://github.com/thoov/mock-socket/pull/370),
[#368](https://github.com/thoov/mock-socket/pull/368),
[#313](https://github.com/thoov/mock-socket/pull/313),
[#333](https://github.com/thoov/mock-socket/pull/333),
[#334](https://github.com/thoov/mock-socket/pull/334),
[#369](https://github.com/thoov/mock-socket/pull/369),
[#375](https://github.com/thoov/mock-socket/pull/375) Bump dependencies
### v9.1.5 (June 5th, 2022)
- [#362](https://github.com/thoov/mock-socket/pull/362) [BUGFIX] Event handler getters should return a single function
### v9.1.4 (May 25th, 2022)
- [#298](https://github.com/thoov/mock-socket/pull/298) [BUGFIX] close listener of the socket isn't called when client close
### v9.1.3 (April 20th, 2022)
- [#355](https://github.com/thoov/mock-socket/pull/355) Bump url-parse from 1.5.2 to 1.5.9
### v9.1.2 (January 25th, 2022)
- [#352](https://github.com/thoov/mock-socket/pull/352) fix SocketIO types
### v9.1.1 (January 25th, 2022)
- [#351](https://github.com/thoov/mock-socket/pull/351) add types for SocketIO
### v9.1.0 (January 13th, 2022)
- [#348](https://github.com/thoov/mock-socket/pull/348) [BUGFIX] Address misspelling of cancelBuble
- [#349](https://github.com/thoov/mock-socket/pull/349) add mock options param to prevent stubbing global
### v9.0.8 (November 15th, 2021)
- [#343](https://github.com/thoov/mock-socket/pull/343) trim query params for attachServer method lookup
- [#335](https://github.com/thoov/mock-socket/pull/335) Update type of url parameter of websocket constructor
### v9.0.7 (November 1st, 2021)
- [#342](https://github.com/thoov/mock-socket/pull/342) Accessing to websocket proxy via server clients
### v9.0.6 (October 18th, 2021)
- [#338](https://github.com/thoov/mock-socket/pull/338) [BUGFIX] Use default codes for close event
- [#340](https://github.com/thoov/mock-socket/pull/340) Build optimisations
### v9.0.5 (September 30th, 2021)
- [#312](https://github.com/thoov/mock-socket/pull/312) [BUGFIX] Fix null pointer exceptions
- [#296](https://github.com/thoov/mock-socket/pull/296) [BUGFIX] Add the hasListeners method to client socket
- [#314](https://github.com/thoov/mock-socket/pull/314), \#316, \#318, \#321, \#323, \#330, \#331, \#332 Bump versions
- [#336](https://github.com/thoov/mock-socket/pull/336) Remove src folder from npm
### v9.0.4 (September 27th, 2021)
- [#240](https://github.com/thoov/mock-socket/pull/240) [BUGFIX] Fixed undefined readyState for WebSockets after closing connection in Server
- [#328](https://github.com/thoov/mock-socket/pull/328) [BUGFIX] Use native typed arguments for WebSocket event handlers
### v9.0.2 (October 9th, 2019)
- [#285](https://github.com/thoov/mock-socket/pull/285) [BUGFIX] Removing .git directory from npm package + cleanup
### v9.0.1 (October 5th, 2019)
- [#281](https://github.com/thoov/mock-socket/pull/281) [BUGFIX] Updating the workflow
- [#276](https://github.com/thoov/mock-socket/pull/276) [BUGFIX] Export ES Module format with .mjs extension

21
node_modules/mock-socket/LICENSE.txt generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 Travis Hoover
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

237
node_modules/mock-socket/README.md generated vendored Normal file
View File

@@ -0,0 +1,237 @@
<p align="center">
<img width=600 src="http://imgur.com/Xt9X83M.png">
</p>
<p align="center">
Javascript mocking library for <a href="https://developer.mozilla.org/en-US/docs/WebSockets">websockets</a> and <a href="http://socket.io/">socket.io</a>
</p>
<p align="center">
<a href="https://github.com/thoov/mock-socket/actions">
<img src="https://github.com/thoov/mock-socket/workflows/CI/badge.svg" alt="Build Status">
</a>
</p>
## Contents
- [Installation](#installation)
- [Basic Usage](#usage)
- [Advanced Usage](#advanced-usage)
- [Typescript Support](#typescript-support)
- [Socket.IO](#socket-io)
- [Contributing](#contributing)
- [Feedback](#feedback)
## Installation
```shell
npm install mock-socket
```
```js
import { WebSocket, Server } from 'mock-socket';
```
## Usage
```js
import test from 'ava';
import { Server } from 'mock-socket';
class ChatApp {
constructor(url) {
this.messages = [];
this.connection = new WebSocket(url);
this.connection.onmessage = event => {
this.messages.push(event.data);
};
}
sendMessage(message) {
this.connection.send(message);
}
}
test.cb('that chat app can be mocked', t => {
const fakeURL = 'ws://localhost:8080';
const mockServer = new Server(fakeURL);
mockServer.on('connection', socket => {
socket.on('message', data => {
t.is(data, 'test message from app', 'we have intercepted the message and can assert on it');
socket.send('test message from mock server');
});
});
const app = new ChatApp(fakeURL);
app.sendMessage('test message from app'); // NOTE: this line creates a micro task
// NOTE: this timeout is for creating another micro task that will happen after the above one
setTimeout(() => {
t.is(app.messages.length, 1);
t.is(app.messages[0], 'test message from mock server', 'we have stubbed our websocket backend');
mockServer.stop(t.done);
}, 100);
});
```
## Advanced Usage
### Stubbing the "global"
```js
import { WebSocket, Server } from 'mock-socket';
/*
* By default the global WebSocket object is stubbed out when
* a new Server instance is created and is restored when you stop
* the server.
* However, you can disable this behavior by passing `mock: false`
* to the options and manually mock the socket when you need it.
*/
const server = new Server('ws://localhost:8080', { mock: false });
/*
* If you need to stub something else out you can like so:
*/
window.WebSocket = WebSocket; // Here we stub out the window object
```
### Server Methods
```js
const mockServer = new Server('ws://localhost:8080');
mockServer.on('connection', socket => {
socket.on('message', () => {});
socket.on('close', () => {});
socket.on('error', () => {});
socket.send('message');
socket.close();
});
mockServer.clients(); // array of all connected clients
mockServer.emit('room', 'message');
mockServer.stop(optionalCallback);
```
## Typescript Support
A [declaration file](https://github.com/thoov/mock-socket/blob/master/index.d.ts) is included by default. If you notice any issues with the types please create an issue or a PR!
## Socket IO
[Socket.IO](https://socket.io/) has **limited support**. Below is a similar example to the one above but modified to show off socket.io support.
```js
import test from 'ava';
import { SocketIO, Server } from 'mock-socket';
class ChatApp {
constructor(url) {
this.messages = [];
this.connection = new io(url);
this.connection.on('chat-message', data => {
this.messages.push(event.data);
});
}
sendMessage(message) {
this.connection.emit('chat-message', message);
}
}
test.cb('that socket.io works', t => {
const fakeURL = 'ws://localhost:8080';
const mockServer = new Server(fakeURL);
window.io = SocketIO;
mockServer.on('connection', socket => {
socket.on('chat-message', data => {
t.is(data, 'test message from app', 'we have intercepted the message and can assert on it');
socket.emit('chat-message', 'test message from mock server');
});
});
const app = new ChatApp(fakeURL);
app.sendMessage('test message from app');
setTimeout(() => {
t.is(app.messages.length, 1);
t.is(app.messages[0], 'test message from mock server', 'we have subbed our websocket backend');
mockServer.stop(t.done);
}, 100);
});
```
## Contributing
The easiest way to work on the project is to clone the repo down via:
```shell
git clone git@github.com:thoov/mock-socket.git
cd mock-socket
yarn install
```
Then to create a local build via:
```shell
yarn build
```
Then create a local npm link via:
```shell
yarn link
```
At this point you can create other projects / apps locally and reference this local build via:
```shell
yarn link mock-socket
```
from within your other projects folder. Make sure that after any changes you run `yarn build`!
### Tests
This project uses [ava.js](https://github.com/avajs/ava) as its test framework. Tests are located in /tests. To run tests:
```shell
yarn test
```
### Linting
This project uses eslint and a rules set from [airbnb's javascript style guides](https://github.com/airbnb/javascript). To run linting:
```shell
yarn lint
```
### Formatting
This project uses [prettier](https://github.com/prettier/prettier). To run the formatting:
```shell
yarn format
```
### Code Coverage
Code coverage reports are created in /coverage after all of the tests have successfully passed. To run the coverage:
```shell
yarn test:coverage
```
## Feedback
If you have any feedback, encounter any bugs, or just have a question, please feel free to create a [github issue](https://github.com/thoov/mock-socket/issues/new) or send me a tweet at [@thoov](https://twitter.com/thoov).

2216
node_modules/mock-socket/dist/mock-socket.amd.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2214
node_modules/mock-socket/dist/mock-socket.cjs.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2208
node_modules/mock-socket/dist/mock-socket.es.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2208
node_modules/mock-socket/dist/mock-socket.es.mjs generated vendored Normal file

File diff suppressed because it is too large Load Diff

2220
node_modules/mock-socket/dist/mock-socket.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

140
node_modules/mock-socket/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,140 @@
// Type definitions for Mock Socket 8.X+
// Project: Mock Socket
// Definitions by: Travis Hoover <https://github.com/thoov/mock-socket>
declare module 'mock-socket' {
// support TS under 3.5
type _Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
class EventTarget {
listeners: any;
addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
dispatchEvent(evt: Event): boolean;
removeEventListener(type: string, listener?: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
}
interface WebSocketCallbackMap {
close: () => void;
error: (err: Error) => void;
message: (message: string | Blob | ArrayBuffer | ArrayBufferView) => void;
}
//
// https://html.spec.whatwg.org/multipage/web-sockets.html#websocket
//
class WebSocket extends EventTarget {
constructor(url: string | URL, protocols?: string|string[]);
static readonly CONNECTING: 0;
static readonly OPEN: 1;
static readonly CLOSING: 2;
static readonly CLOSED: 3;
readonly url: string;
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSING: 2;
readonly CLOSED: 3;
readonly readyState: number;
readonly bufferedAmount: number;
onopen: (event: Event) => void;
onerror: (event: Event) => void;
onclose: (event: CloseEvent) => void;
onmessage: (event: MessageEvent) => void;
readonly extensions: string;
readonly protocol: string;
close(code?: number, reason?: string): void;
binaryType: BinaryType;
send(data: string | Blob | ArrayBuffer | ArrayBufferView): void;
}
interface Client extends _Omit<WebSocket, 'close'> {
target: WebSocket;
close(options?: CloseOptions): void;
on<K extends keyof WebSocketCallbackMap>(type: K, callback: WebSocketCallbackMap[K]): void;
off<K extends keyof WebSocketCallbackMap>(type: K, callback: WebSocketCallbackMap[K]): void;
}
class Server extends EventTarget {
constructor(url: string, options?: ServerOptions);
readonly options?: ServerOptions;
stop(callback?: () => void): void;
mockWebsocket(): void;
restoreWebsocket(): void;
on(type: string, callback: (socket: Client) => void): void;
off(type: string, callback: (socket: Client) => void): void;
close(options?: CloseOptions): void;
emit(event: string, data: any, options?: EmitOptions): void;
clients(): Client[];
to(room: any, broadcaster: any, broadcastList?: object): ToReturnObject;
in(any: any): ToReturnObject;
simulate(event: string): void;
static of(url: string): Server;
}
interface SocketIOClient extends EventTarget {
binaryType: BinaryType;
readonly CONNECTING: 0;
readonly OPEN: 1;
readonly CLOSING: 2;
readonly CLOSED: 3;
readonly url: string;
readonly readyState: number;
readonly protocol: string;
readonly target: this;
close(): this;
disconnect(): this;
emit(event: string, data: any): this;
send(data: any): this;
on(type: string, callback: (socket: SocketIOClient) => void): this;
off(type: string, callback: (socket: SocketIOClient) => void): void;
hasListeners(type: string): boolean;
join(room: string): void;
leave(room: string): void;
to(room: string): ToReturnObject;
in(room: string): ToReturnObject;
readonly broadcast: {
emit(event: string, data: any): SocketIOClient;
to(room: string): ToReturnObject;
in(room: string): ToReturnObject;
};
}
const SocketIO: {
(url: string, protocol?: string | string[]): SocketIOClient;
connect(url: string, protocol?: string | string[]): SocketIOClient;
}
interface CloseOptions {
code: number;
reason: string;
wasClean: boolean;
}
interface EmitOptions {
websockets: Client[];
}
interface ToReturnObject {
to: (chainedRoom: any, chainedBroadcaster: any) => ToReturnObject;
emit(event: Event, data: any): void;
}
interface ServerOptions {
mock?: boolean;
verifyClient?: () => boolean;
selectProtocol?: (protocols: string[]) => string | null;
}
}

89
node_modules/mock-socket/package.json generated vendored Normal file
View File

@@ -0,0 +1,89 @@
{
"name": "mock-socket",
"description": "Javascript mocking library for websockets and socket.io",
"version": "9.3.1",
"license": "MIT",
"author": "Travis Hoover",
"main": "./dist/mock-socket",
"directories": {
"test": "tests"
},
"engines": {
"node": ">= 8"
},
"scripts": {
"build": "rm -rf dist && rollup -c rollup.config.js",
"lint": "eslint src tests",
"prepublishOnly": "yarn build",
"test": "ava --serial --verbose"
},
"repository": {
"type": "git",
"url": "https://github.com/thoov/mock-socket.git"
},
"keywords": [
"websockets",
"mock",
"mocksocket",
"sockets"
],
"bugs": {
"url": "https://github.com/thoov/mock-socket/issues"
},
"homepage": "https://github.com/thoov/mock-socket",
"dependencies": {
},
"devDependencies": {
"ava": "^0.19.1",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-polyfill": "^6.23.0",
"babel-preset-latest": "^6.24.1",
"eslint": "^4.18.2",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.0.1",
"husky": "^1.3.1",
"jsdom": "^11.5.1",
"lint-staged": "^3.4.1",
"nyc": "^10.3.2",
"prettier": "^1.3.1",
"rollup": "^0.41.6",
"rollup-plugin-buble": "^0.15.0",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-node-resolve": "^3.0.0",
"systemjs": "^0.20.12",
"typescript": "^2.9.2",
"typescript-eslint-parser": "^16.0.1",
"url-parse": "^1.5.2"
},
"ava": {
"files": [
"tests/**/*.test.js"
],
"require": [
"babel-register",
"babel-polyfill"
],
"babel": "inherit"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"prettier": {
"singleQuote": true,
"printWidth": 120
},
"lint-staged": {
"*.{js}": [
"prettier --write",
"eslint",
"git add"
]
},
"volta": {
"node": "10.16.0",
"yarn": "1.17.3"
}
}