File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15,15 +15,15 @@ npm install --save-dev superwstest
1515You can also optionally install supertest for access to ` .get ` , ` .post ` , etc.:
1616
1717``` bash
18- npm install --save-dev superwstest supertest
18+ npm install --save-dev superwstest supertest @types/supertest
1919```
2020
2121## Usage
2222
2323### Example server implementation
2424
2525``` javascript
26- import http from ' http' ;
26+ import http from ' node: http' ;
2727import WebSocket from ' ws' ;
2828
2929const server = http .createServer ();
@@ -744,7 +744,7 @@ this reason supertest has become optional and not included by default
744744To restore the ability to use ` .get ` , ` .post ` , etc. simply run:
745745
746746``` shell
747- npm install --save-dev supertest
747+ npm install --save-dev supertest @types/supertest
748748```
749749
750750The presence of this package will detected automatically and the supertest
Original file line number Diff line number Diff line change 11declare module 'superwstest' {
2- import type { Server } from 'net' ;
3- import type { ClientRequestArgs , IncomingMessage } from 'http' ;
2+ import type { Server } from 'node: net' ;
3+ import type { ClientRequestArgs , IncomingMessage } from 'node: http' ;
44 import type { WebSocket , ClientOptions , WebSocketServer } from 'ws' ;
5- import type { SuperTest , Test } from 'supertest' ;
5+
6+ // import SuperTest type if available, else fall-back to SuperTest = {}
7+ // @ts -ignore
8+ import type { SuperTest as MaybeSuperTest } from 'supertest' ;
9+ type IfKnown < T , Fallback > = 0 extends 1 & T ? Fallback : T ;
10+ type SuperTest = IfKnown < MaybeSuperTest , { } > ;
611
712 type JsonObject = { [ member : string ] : JsonValue } ;
813 interface JsonArray extends Array < JsonValue > { }
@@ -120,7 +125,7 @@ declare module 'superwstest' {
120125 expectConnectionError ( expectedCode ?: number | string | null | undefined ) : Promise < WebSocket > ;
121126 }
122127
123- export interface SuperWSTest extends SuperTest < Test > {
128+ export interface SuperWSTest extends SuperTest {
124129 ws ( path : string , options ?: ClientOptions | ClientRequestArgs | undefined ) : WSChain ;
125130 ws (
126131 path : string ,
Original file line number Diff line number Diff line change 3535 },
3636 "homepage" : " https://github.com/davidje13/superwstest#readme" ,
3737 "dependencies" : {
38- "@types/supertest" : " *" ,
3938 "@types/ws" : " 7.x || 8.x" ,
4039 "ws" : " 7.x || 8.x"
4140 },
4241 "peerDependencies" : {
42+ "@types/supertest" : " *" ,
4343 "supertest" : " *"
4444 },
4545 "peerDependenciesMeta" : {
46+ "@types/supertest" : {
47+ "optional" : true
48+ },
4649 "supertest" : {
4750 "optional" : true
4851 }
4952 },
5053 "devDependencies" : {
5154 "lean-test" : " 2.x" ,
52- "prettier" : " 3.6.2 " ,
55+ "prettier" : " 3.8.3 " ,
5356 "rollup" : " 4.x"
5457 }
5558}
Original file line number Diff line number Diff line change 1+ package-lock = false
2+ ignore-scripts = true
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " superwstest-without-supertest-package-test" ,
3+ "private" : true ,
4+ "scripts" : {
5+ "test" : " tsc"
6+ },
7+ "devDependencies" : {
8+ "@types/node" : " 24.x" ,
9+ "superwstest" : " file:superwstest.tgz" ,
10+ "typescript" : " 6.0.x"
11+ }
12+ }
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "types" : [" node" ],
4+
5+ "strict" : true ,
6+ "allowUnusedLabels" : false ,
7+ "allowUnreachableCode" : false ,
8+ "exactOptionalPropertyTypes" : true ,
9+ "noFallthroughCasesInSwitch" : true ,
10+ "noImplicitOverride" : true ,
11+ "noImplicitReturns" : true ,
12+ "noPropertyAccessFromIndexSignature" : true ,
13+ "noUncheckedIndexedAccess" : true ,
14+ "noUnusedLocals" : true ,
15+ "noUnusedParameters" : true ,
16+
17+ "isolatedModules" : true ,
18+ "verbatimModuleSyntax" : true ,
19+
20+ "lib" : [" es2022" ],
21+ "target" : " es2022" ,
22+ "module" : " esnext" ,
23+ "moduleResolution" : " bundler" ,
24+ "noEmit" : true
25+ },
26+ "typeAcquisition" : {
27+ "enable" : false
28+ },
29+ "include" : [" typescript.ts" ]
30+ }
Original file line number Diff line number Diff line change 1+ import request from 'superwstest' ;
2+
3+ // this file just checks types; the code is not executed
4+
5+ request ( 'hello' )
6+ . ws ( 'foo' )
7+ . send ( 'hi' )
8+ . exec ( ( ws ) => ws . ping ( 'blah' ) )
9+ . close ( ) ;
10+
11+ // @ts -expect-error
12+ request ( 'hello' ) . get ( '/hi' ) ;
Original file line number Diff line number Diff line change 22 "name" : " superwstest-package-test" ,
33 "private" : true ,
44 "scripts" : {
5- "test" : " node commonjs.js && node es6modules.mjs && tsc typescript.ts --noEmit "
5+ "test" : " node commonjs.js && node es6modules.mjs && tsc"
66 },
77 "devDependencies" : {
8+ "@types/node" : " 24.x" ,
9+ "@types/supertest" : " 7.x" ,
810 "superwstest" : " file:superwstest.tgz" ,
911 "supertest" : " 7.x" ,
10- "typescript" : " 5.8 .x"
12+ "typescript" : " 6.0 .x"
1113 }
1214}
Original file line number Diff line number Diff line change 11{
22 "compilerOptions" : {
3+ "types" : [" node" ],
4+
35 "strict" : true ,
4- "noImplicitAny" : true
6+ "allowUnusedLabels" : false ,
7+ "allowUnreachableCode" : false ,
8+ "exactOptionalPropertyTypes" : true ,
9+ "noFallthroughCasesInSwitch" : true ,
10+ "noImplicitOverride" : true ,
11+ "noImplicitReturns" : true ,
12+ "noPropertyAccessFromIndexSignature" : true ,
13+ "noUncheckedIndexedAccess" : true ,
14+ "noUnusedLocals" : true ,
15+ "noUnusedParameters" : true ,
16+
17+ "isolatedModules" : true ,
18+ "verbatimModuleSyntax" : true ,
19+
20+ "lib" : [" es2022" ],
21+ "target" : " es2022" ,
22+ "module" : " esnext" ,
23+ "moduleResolution" : " bundler" ,
24+ "noEmit" : true
525 },
6- "include" : [" **/*" ],
7- "exclude" : [" node_modules" ]
26+ "typeAcquisition" : {
27+ "enable" : false
28+ },
29+ "include" : [" typescript.ts" ]
830}
Original file line number Diff line number Diff line change 1- import request from 'superwstest' ;
21import { createServer as httpCreateServer } from 'node:http' ;
32import { createServer as httpsCreateServer } from 'node:https' ;
3+ import request from 'superwstest' ;
44import { WebSocketServer } from 'ws' ;
55
66// this file just checks types; the code is not executed
@@ -11,6 +11,8 @@ request('hello')
1111 . exec ( ( ws ) => ws . ping ( 'blah' ) )
1212 . close ( ) ;
1313
14+ request ( 'hello' ) . get ( '/hi' ) ;
15+
1416request ( httpCreateServer ( ) ) . ws ( 'foo' ) ;
1517request ( httpsCreateServer ( ) ) . ws ( 'foo' ) ;
1618request ( new WebSocketServer ( { port : 0 } ) ) . ws ( 'foo' ) ;
@@ -41,3 +43,6 @@ request('hello').ws(1);
4143
4244// @ts -expect-error
4345scopedRequest ( 'hello' ) . ws ( 1 ) ;
46+
47+ // @ts -expect-error
48+ request ( 'hello' ) . get ( 0 ) ;
You can’t perform that action at this time.
0 commit comments