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