Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

superwstest

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superwstest - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

2

index.d.ts

@@ -45,3 +45,3 @@ declare module 'superwstest' {

wait(milliseconds: number): this;
exec(fn: (ws: WebSocket) => Promise<void> | void): this;
exec(fn: (ws: WebSocket) => Promise<unknown> | void): this;

@@ -48,0 +48,0 @@ expectMessage<T>(

{
"name": "superwstest",
"version": "2.0.0",
"version": "2.0.1",
"description": "supertest with added WebSocket capabilities",

@@ -5,0 +5,0 @@ "files": [

@@ -513,2 +513,6 @@ # SuperWSTest

See [the FAQ](#how-can-i-perform-another-asynchronous-task-while-a-connection-is-open)
for examples of how `exec` can be used to perform side operations
during a connection.
## FAQ

@@ -582,1 +586,55 @@

and any dangling connections will prevent the test process from terminating).
### How can I perform another asynchronous task while a connection is open?
Often when testing websockets, you will want to perform another action and
check for a reaction on the websocket. This can be achieved using `exec`:
```javascript
await request(server).ws('here')
.sendText('hello')
.expectText('session open')
.exec(async () => {
await myOtherOperation();
})
.expectText('something happened')
.close();
```
The recommended approach is to pull these out as helper functions, for example:
```javascript
const makeThing = (name) => () => request(server)
.post('blah')
.expect(200);
await request(server).ws('here')
.sendText('hello')
.expectText('session open')
.exec(makeThing('my first thing'))
.expectText('made "my first thing"')
.exec(makeThing('my second thing'))
.expectText('made "my second thing"')
.close();
```
If you need 2 websocket connections to interact with each other, you can use
`Promise.all`:
```javascript
await Promise.all([
request(server).ws('here')
.expectText('Welcome to the chat room')
.sendText('Hi all! I am foo')
.expectText('Hi foo, I am bar')
.close(),
request(server).ws('here')
.expectText('Welcome to the chat room')
.expectText('Hi all! I am foo')
.sendText('Hi foo, I am bar')
.close(),
]);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc