@eggjs/supertest 9.0.0-beta.34 → 9.0.0-beta.36
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.
- package/dist/agent.d.ts +31 -26
- package/dist/agent.js +72 -85
- package/dist/error/AssertError.d.ts +7 -4
- package/dist/error/AssertError.js +15 -12
- package/dist/index.d.ts +14 -11
- package/dist/index.js +20 -26
- package/dist/request.d.ts +23 -19
- package/dist/request.js +50 -55
- package/dist/test.d.ts +97 -93
- package/dist/test.js +232 -311
- package/dist/types.d.ts +13 -9
- package/package.json +21 -25
- package/dist/types.js +0 -2
package/dist/test.d.ts
CHANGED
|
@@ -1,96 +1,100 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Request,
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { AssertError } from "./error/AssertError.js";
|
|
2
|
+
import { Request, Response } from "superagent";
|
|
3
|
+
import { Server } from "node:net";
|
|
4
|
+
|
|
5
|
+
//#region src/test.d.ts
|
|
6
|
+
type TestApplication = Server | string;
|
|
7
|
+
type AssertFunction = (res: Response) => AssertError | void;
|
|
8
|
+
type CallbackFunction = (err: AssertError | Error | null, res: Response) => void;
|
|
9
|
+
type ResponseError = Error & {
|
|
10
|
+
syscall?: string;
|
|
11
|
+
code?: string;
|
|
12
|
+
status?: number;
|
|
11
13
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
interface ExpectHeader {
|
|
15
|
+
name: string;
|
|
16
|
+
value: string | number | RegExp;
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
18
|
+
declare class Test extends Request {
|
|
19
|
+
app: TestApplication;
|
|
20
|
+
_server: Server;
|
|
21
|
+
_asserts: AssertFunction[];
|
|
22
|
+
/**
|
|
23
|
+
* Initialize a new `Test` with the given `app`,
|
|
24
|
+
* request `method` and `path`.
|
|
25
|
+
*/
|
|
26
|
+
constructor(app: TestApplication, method: string, path: string);
|
|
27
|
+
/**
|
|
28
|
+
* Returns a URL, extracted from a server.
|
|
29
|
+
*
|
|
30
|
+
* @return {String} URL address
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
protected serverAddress(app: Server, path: string): string;
|
|
34
|
+
/**
|
|
35
|
+
* Expectations:
|
|
36
|
+
*
|
|
37
|
+
* ```js
|
|
38
|
+
* .expect(200)
|
|
39
|
+
* .expect(200, fn)
|
|
40
|
+
* .expect(200, body)
|
|
41
|
+
* .expect('Some body')
|
|
42
|
+
* .expect('Some body', fn)
|
|
43
|
+
* .expect(['json array body', { key: 'val' }])
|
|
44
|
+
* .expect('Content-Type', 'application/json')
|
|
45
|
+
* .expect('Content-Type', 'application/json', fn)
|
|
46
|
+
* .expect(fn)
|
|
47
|
+
* .expect([200, 404])
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @return {Test} The current Test instance for chaining.
|
|
51
|
+
*/
|
|
52
|
+
expect(a: number | string | RegExp | object | AssertFunction, b?: string | number | RegExp | CallbackFunction, c?: CallbackFunction): Test;
|
|
53
|
+
/**
|
|
54
|
+
* UnExpectations:
|
|
55
|
+
*
|
|
56
|
+
* .unexpectHeader('Content-Type')
|
|
57
|
+
* .unexpectHeader('Content-Type', fn)
|
|
58
|
+
*/
|
|
59
|
+
unexpectHeader(name: string, fn?: CallbackFunction): this;
|
|
60
|
+
/**
|
|
61
|
+
* Expectations:
|
|
62
|
+
*
|
|
63
|
+
* .expectHeader('Content-Type')
|
|
64
|
+
* .expectHeader('Content-Type', fn)
|
|
65
|
+
*/
|
|
66
|
+
expectHeader(name: string, fn?: CallbackFunction): this;
|
|
67
|
+
_unexpectHeader(name: string, res: Response): AssertError | void;
|
|
68
|
+
_expectHeader(name: string, res: Response): AssertError | void;
|
|
69
|
+
/**
|
|
70
|
+
* Defer invoking superagent's `.end()` until
|
|
71
|
+
* the server is listening.
|
|
72
|
+
*/
|
|
73
|
+
end(fn: CallbackFunction): this;
|
|
74
|
+
/**
|
|
75
|
+
* Perform assertions and invoke `fn(err, res)`.
|
|
76
|
+
*/
|
|
77
|
+
assert(resError: ResponseError | null, res: Response, fn: CallbackFunction): void;
|
|
78
|
+
/**
|
|
79
|
+
* Perform assertions on a response body and return an Error upon failure.
|
|
80
|
+
*/
|
|
81
|
+
_assertBody(body: RegExp | string | number | object | null | undefined, res: Response): AssertError | void;
|
|
82
|
+
/**
|
|
83
|
+
* Perform assertions on a response header and return an Error upon failure.
|
|
84
|
+
*/
|
|
85
|
+
_assertHeader(header: ExpectHeader, res: Response): AssertError | void;
|
|
86
|
+
/**
|
|
87
|
+
* Perform assertions on the response status and return an Error upon failure.
|
|
88
|
+
*/
|
|
89
|
+
_assertStatus(status: number, res: Response): AssertError | void;
|
|
90
|
+
/**
|
|
91
|
+
* Perform assertions on the response status and return an Error upon failure.
|
|
92
|
+
*/
|
|
93
|
+
_assertStatusArray(statusArray: number[], res: Response): AssertError | void;
|
|
94
|
+
/**
|
|
95
|
+
* Performs an assertion by calling a function and return an Error upon failure.
|
|
96
|
+
*/
|
|
97
|
+
_assertFunction(fn: AssertFunction, res: Response): Error | undefined;
|
|
96
98
|
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { AssertFunction, CallbackFunction, ExpectHeader, ResponseError, Test, TestApplication };
|