Socket
Socket
Sign inDemoInstall

superwstest

Package Overview
Dependencies
46
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.2 to 2.0.3

58

build/superwstest.js

@@ -6,2 +6,3 @@ 'use strict';

var https = require('https');
var net = require('net');

@@ -384,17 +385,19 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

function performShutdown(sockets, shutdownDelay) {
if (shutdownDelay <= 0) {
[...sockets].forEach((s) => s.end());
return;
}
async function performShutdown(sockets, shutdownDelay) {
const awaiting = [...sockets];
const expire = Date.now() + shutdownDelay;
if (shutdownDelay > 0 && awaiting.length > 0) {
const expire = Date.now() + shutdownDelay;
[...sockets].forEach(async (s) => {
while (Date.now() < expire && sockets.has(s)) {
while (Date.now() < expire && awaiting.some((s) => sockets.has(s))) {
/* eslint-disable-next-line no-await-in-loop */ // polling
await new Promise((r) => setTimeout(r, 20));
await new Promise((r) => setTimeout(r, 0));
}
if (sockets.has(s)) {
}
[...sockets].forEach((s) => {
if (s instanceof net.Socket) {
s.end();
} else if (s.close) {
s.close(); // WebSocketServer
}

@@ -437,2 +440,22 @@ });

function getProtocol(server) {
if (!(server instanceof net.Server)) {
// could be WebSocketServer
server = (server.options || {}).server || server;
}
return server instanceof https__default["default"].Server ? 'https' : 'http';
}
function getHostname(address) {
if (typeof address === 'string') {
return address;
}
const { family } = address;
// check for Node 18.0-18.3 (numeric) and Node <18.0 / >=18.4 (string) APIs for address.family
if (family === 6 || family === 'IPv6') {
return `[${address.address}]`;
}
return address.address;
}
function getHttpBase(server) {

@@ -455,16 +478,3 @@ if (typeof server === 'string') {

const protocol = server instanceof https__default["default"].Server ? 'https' : 'http';
let hostname;
if (typeof address === 'object') {
const { family } = address;
// check for Node 18 (numeric) and Node <18 (string) APIs for address.family
if (family === 6 || family === 'IPv6') {
hostname = `[${address.address}]`;
} else {
hostname = address.address;
}
} else {
hostname = address;
}
return `${protocol}://${hostname}:${address.port}`;
return `${getProtocol(server)}://${getHostname(address)}:${address.port}`;
}

@@ -471,0 +481,0 @@

declare module 'superwstest' {
import type { Server, ClientRequestArgs, IncomingMessage } from 'http';
import type { WebSocket, ClientOptions } from 'ws';
import type { Server } from 'net';
import type { ClientRequestArgs, IncomingMessage } from 'http';
import type { WebSocket, ClientOptions, WebSocketServer } from 'ws';
import type { SuperTest, Test } from 'supertest';

@@ -95,3 +96,3 @@

interface SuperWSRequest {
(app: Server | string, options?: RequestOptions | undefined): SuperWSTest;
(app: Server | WebSocketServer | string, options?: RequestOptions | undefined): SuperWSTest;
scoped(): SuperWSRequest;

@@ -98,0 +99,0 @@ closeAll(): void;

{
"name": "superwstest",
"version": "2.0.2",
"version": "2.0.3",
"description": "supertest with added WebSocket capabilities",

@@ -51,6 +51,6 @@ "files": [

"devDependencies": {
"lean-test": "1.x",
"prettier": "2.5.1",
"lean-test": "2.x",
"prettier": "2.6.2",
"rollup": "2.x"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc