@mojojs/core 0.19.0 → 0.20.0
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/lib/app.d.ts +3 -0
- package/lib/app.js +3 -0
- package/lib/app.js.map +1 -1
- package/lib/body/params.d.ts +6 -0
- package/lib/body/params.js +6 -0
- package/lib/body/params.js.map +1 -1
- package/lib/cache.d.ts +23 -0
- package/lib/cache.js +45 -0
- package/lib/cache.js.map +1 -0
- package/lib/cli/create-full-app.d.ts +3 -0
- package/lib/cli/create-full-app.js +5 -2
- package/lib/cli/create-full-app.js.map +1 -1
- package/lib/cli/create-lite-app.d.ts +3 -0
- package/lib/cli/create-lite-app.js +3 -0
- package/lib/cli/create-lite-app.js.map +1 -1
- package/lib/cli/eval.d.ts +3 -0
- package/lib/cli/eval.js +3 -0
- package/lib/cli/eval.js.map +1 -1
- package/lib/cli/get.d.ts +3 -0
- package/lib/cli/get.js +3 -0
- package/lib/cli/get.js.map +1 -1
- package/lib/cli/repl.d.ts +3 -0
- package/lib/cli/repl.js +3 -0
- package/lib/cli/repl.js.map +1 -1
- package/lib/cli/routes.d.ts +3 -0
- package/lib/cli/routes.js +3 -0
- package/lib/cli/routes.js.map +1 -1
- package/lib/cli/server.d.ts +3 -0
- package/lib/cli/server.js +3 -0
- package/lib/cli/server.js.map +1 -1
- package/lib/cli/version.d.ts +3 -0
- package/lib/cli/version.js +3 -0
- package/lib/cli/version.js.map +1 -1
- package/lib/context.d.ts +1 -1
- package/lib/context.js +1 -1
- package/lib/core.d.ts +3 -0
- package/lib/core.js +3 -0
- package/lib/core.js.map +1 -1
- package/lib/hooks.d.ts +9 -0
- package/lib/hooks.js +9 -0
- package/lib/hooks.js.map +1 -1
- package/lib/logger.d.ts +69 -0
- package/lib/logger.js +63 -0
- package/lib/logger.js.map +1 -1
- package/lib/mime.d.ts +12 -0
- package/lib/mime.js +12 -0
- package/lib/mime.js.map +1 -1
- package/lib/mock/request.d.ts +3 -0
- package/lib/mock/request.js +3 -0
- package/lib/mock/request.js.map +1 -1
- package/lib/mock/response.d.ts +3 -0
- package/lib/mock/response.js +3 -0
- package/lib/mock/response.js.map +1 -1
- package/lib/plugins/default-helpers.d.ts +3 -0
- package/lib/plugins/default-helpers.js +3 -0
- package/lib/plugins/default-helpers.js.map +1 -1
- package/lib/plugins/exception-helpers.d.ts +3 -0
- package/lib/plugins/exception-helpers.js +3 -0
- package/lib/plugins/exception-helpers.js.map +1 -1
- package/lib/plugins/header-conditions.d.ts +3 -0
- package/lib/plugins/header-conditions.js +3 -0
- package/lib/plugins/header-conditions.js.map +1 -1
- package/lib/plugins/json-config.d.ts +3 -0
- package/lib/plugins/json-config.js +3 -0
- package/lib/plugins/json-config.js.map +1 -1
- package/lib/plugins/mt-engine.d.ts +3 -0
- package/lib/plugins/mt-engine.js +5 -2
- package/lib/plugins/mt-engine.js.map +1 -1
- package/lib/plugins/view-helpers.d.ts +3 -0
- package/lib/plugins/view-helpers.js +3 -0
- package/lib/plugins/view-helpers.js.map +1 -1
- package/lib/plugins/yaml-config.d.ts +3 -0
- package/lib/plugins/yaml-config.js +3 -0
- package/lib/plugins/yaml-config.js.map +1 -1
- package/lib/renderer.d.ts +38 -0
- package/lib/renderer.js +38 -0
- package/lib/renderer.js.map +1 -1
- package/lib/router/pattern.d.ts +33 -0
- package/lib/router/pattern.js +24 -0
- package/lib/router/pattern.js.map +1 -1
- package/lib/router/plan.d.ts +15 -0
- package/lib/router/plan.js +15 -0
- package/lib/router/plan.js.map +1 -1
- package/lib/router/route.d.ts +83 -0
- package/lib/router/route.js +83 -0
- package/lib/router/route.js.map +1 -1
- package/lib/router.d.ts +38 -2
- package/lib/router.js +38 -2
- package/lib/router.js.map +1 -1
- package/lib/server/cookie.d.ts +6 -0
- package/lib/server/cookie.js +6 -0
- package/lib/server/cookie.js.map +1 -1
- package/lib/server.d.ts +21 -0
- package/lib/server.js +15 -0
- package/lib/server.js.map +1 -1
- package/lib/session.d.ts +35 -0
- package/lib/session.js +35 -0
- package/lib/session.js.map +1 -1
- package/lib/static.d.ts +22 -0
- package/lib/static.js +22 -0
- package/lib/static.js.map +1 -1
- package/lib/user-agent/cookie-jar.d.ts +12 -0
- package/lib/user-agent/cookie-jar.js +12 -0
- package/lib/user-agent/cookie-jar.js.map +1 -1
- package/lib/user-agent/mock.d.ts +15 -0
- package/lib/user-agent/mock.js +15 -0
- package/lib/user-agent/mock.js.map +1 -1
- package/lib/user-agent/response.d.ts +27 -0
- package/lib/user-agent/response.js +27 -0
- package/lib/user-agent/response.js.map +1 -1
- package/lib/user-agent/test.d.ts +115 -2
- package/lib/user-agent/test.js +123 -10
- package/lib/user-agent/test.js.map +1 -1
- package/lib/user-agent/transport/http.d.ts +12 -0
- package/lib/user-agent/transport/http.js +12 -0
- package/lib/user-agent/transport/http.js.map +1 -1
- package/lib/user-agent/transport/https.d.ts +3 -0
- package/lib/user-agent/transport/https.js +3 -0
- package/lib/user-agent/transport/https.js.map +1 -1
- package/lib/user-agent/transport/ws.d.ts +6 -0
- package/lib/user-agent/transport/ws.js +6 -0
- package/lib/user-agent/transport/ws.js.map +1 -1
- package/lib/util.d.ts +30 -0
- package/lib/util.js +30 -0
- package/lib/util.js.map +1 -1
- package/lib/validator/result.d.ts +9 -0
- package/lib/validator/result.js +3 -0
- package/lib/validator/result.js.map +1 -1
- package/lib/validator.d.ts +9 -0
- package/lib/validator.js +9 -0
- package/lib/validator.js.map +1 -1
- package/lib/websocket.d.ts +18 -0
- package/lib/websocket.js +12 -0
- package/lib/websocket.js.map +1 -1
- package/package.json +2 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../src/user-agent/mock.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAE3C,MAAM,OAAO,aAAc,SAAQ,SAAS;
|
|
1
|
+
{"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+
* User agent response class.
|
|
4
|
+
*/
|
|
2
5
|
export declare class UserAgentResponse extends Body {
|
|
6
|
+
/**
|
|
7
|
+
* Check if response has a `4xx` response status code.
|
|
8
|
+
*/
|
|
3
9
|
get isClientError(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Check if response has a `4xx` or `5xx` response status code.
|
|
12
|
+
*/
|
|
4
13
|
get isError(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if response has a `3xx` response status code.
|
|
16
|
+
*/
|
|
5
17
|
get isRedirect(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check if response has a `5xx` response status code.
|
|
20
|
+
*/
|
|
6
21
|
get isServerError(): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Check if response has a `2xx` response status code.
|
|
24
|
+
*/
|
|
7
25
|
get isSuccess(): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Response status code.
|
|
28
|
+
*/
|
|
8
29
|
get status(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Get response message.
|
|
32
|
+
*/
|
|
9
33
|
get statusMessage(): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Get `Content-Type` header value.
|
|
36
|
+
*/
|
|
10
37
|
get type(): string | undefined;
|
|
11
38
|
}
|
|
@@ -1,30 +1,57 @@
|
|
|
1
1
|
import { Body } from '../body.js';
|
|
2
|
+
/**
|
|
3
|
+
* User agent response class.
|
|
4
|
+
*/
|
|
2
5
|
export class UserAgentResponse extends Body {
|
|
6
|
+
/**
|
|
7
|
+
* Check if response has a `4xx` response status code.
|
|
8
|
+
*/
|
|
3
9
|
get isClientError() {
|
|
4
10
|
const statusCode = this.status;
|
|
5
11
|
return statusCode >= 400 && statusCode <= 499;
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Check if response has a `4xx` or `5xx` response status code.
|
|
15
|
+
*/
|
|
7
16
|
get isError() {
|
|
8
17
|
return this.isClientError || this.isServerError;
|
|
9
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if response has a `3xx` response status code.
|
|
21
|
+
*/
|
|
10
22
|
get isRedirect() {
|
|
11
23
|
const statusCode = this.status;
|
|
12
24
|
return statusCode >= 300 && statusCode <= 399;
|
|
13
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Check if response has a `5xx` response status code.
|
|
28
|
+
*/
|
|
14
29
|
get isServerError() {
|
|
15
30
|
const statusCode = this.status;
|
|
16
31
|
return statusCode >= 500 && statusCode <= 599;
|
|
17
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if response has a `2xx` response status code.
|
|
35
|
+
*/
|
|
18
36
|
get isSuccess() {
|
|
19
37
|
const statusCode = this.status;
|
|
20
38
|
return statusCode >= 200 && statusCode <= 299;
|
|
21
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Response status code.
|
|
42
|
+
*/
|
|
22
43
|
get status() {
|
|
23
44
|
return this.raw.statusCode;
|
|
24
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Get response message.
|
|
48
|
+
*/
|
|
25
49
|
get statusMessage() {
|
|
26
50
|
return this.raw.statusMessage;
|
|
27
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Get `Content-Type` header value.
|
|
54
|
+
*/
|
|
28
55
|
get type() {
|
|
29
56
|
return this.headers['content-type'];
|
|
30
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/user-agent/response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,MAAM,YAAY,CAAC;AAEhC,MAAM,OAAO,iBAAkB,SAAQ,IAAI;IACzC,IAAI,aAAa;QACf,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;QAC/B,OAAO,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,GAAG,CAAC;IAChD,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC;IAClD,CAAC;IAED,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;OAEG;IACH,IAAI,aAAa;QACf,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;QAC/B,OAAO,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,GAAG,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;QAC/B,OAAO,UAAU,IAAI,GAAG,IAAI,UAAU,IAAI,GAAG,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,UAAoB,CAAC;IACvC,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IACtC,CAAC;CACF"}
|
package/lib/user-agent/test.d.ts
CHANGED
|
@@ -10,7 +10,13 @@ import { MockUserAgent } from './mock.js';
|
|
|
10
10
|
import DOM from '@mojojs/dom';
|
|
11
11
|
import StackUtils from 'stack-utils';
|
|
12
12
|
declare type SkipFunction = (...args: any[]) => any;
|
|
13
|
+
/**
|
|
14
|
+
* Test user agent class.
|
|
15
|
+
*/
|
|
13
16
|
export declare class TestUserAgent extends MockUserAgent {
|
|
17
|
+
/**
|
|
18
|
+
* Current HTTP response content.
|
|
19
|
+
*/
|
|
14
20
|
body: Buffer;
|
|
15
21
|
_assert: typeof assert | Tap.Tap | undefined;
|
|
16
22
|
_dom: DOM | undefined;
|
|
@@ -20,41 +26,148 @@ export declare class TestUserAgent extends MockUserAgent {
|
|
|
20
26
|
_stack: StackUtils;
|
|
21
27
|
_ws: WebSocket | undefined;
|
|
22
28
|
constructor(options?: TestUserAgentOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Delegate assertion to test framework currently in use.
|
|
31
|
+
*/
|
|
23
32
|
assert(name: string, args: any[], msg: string, skip: SkipFunction): void;
|
|
33
|
+
/**
|
|
34
|
+
* Check response content for exact match.
|
|
35
|
+
*/
|
|
24
36
|
bodyIs(body: string): this;
|
|
37
|
+
/**
|
|
38
|
+
* Opposite of `bodyIs`.
|
|
39
|
+
*/
|
|
25
40
|
bodyIsnt(body: string): this;
|
|
41
|
+
/**
|
|
42
|
+
* Check response content for similar match.
|
|
43
|
+
*/
|
|
26
44
|
bodyLike(regex: RegExp): this;
|
|
45
|
+
/**
|
|
46
|
+
* Opposite of `bodyLike`.
|
|
47
|
+
*/
|
|
27
48
|
bodyUnlike(regex: RegExp): this;
|
|
49
|
+
/**
|
|
50
|
+
* Close WebSocket connection gracefully.
|
|
51
|
+
*/
|
|
28
52
|
closeOk(code: number, reason: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Wait for WebSocket connection to be closed gracefully and check status.
|
|
55
|
+
*/
|
|
29
56
|
closedOk(code: number): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Perform a `DELETE` request and check for transport errors.
|
|
59
|
+
*/
|
|
30
60
|
deleteOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
61
|
+
/**
|
|
62
|
+
* Checks for existence of the CSS selectors first matching HTML/XML element.
|
|
63
|
+
*/
|
|
31
64
|
elementExists(selector: string): this;
|
|
65
|
+
/**
|
|
66
|
+
* Opposite of `elementExists`.
|
|
67
|
+
*/
|
|
32
68
|
elementExistsNot(selector: string): this;
|
|
69
|
+
/**
|
|
70
|
+
* Perform a `GET` request and check for transport errors.
|
|
71
|
+
*/
|
|
33
72
|
getOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
73
|
+
/**
|
|
74
|
+
* Perform a `HEAD` request and check for transport errors.
|
|
75
|
+
*/
|
|
34
76
|
headOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if response header exists.
|
|
79
|
+
*/
|
|
35
80
|
headerExists(name: string): this;
|
|
81
|
+
/**
|
|
82
|
+
* Opposite of `headerExists`.
|
|
83
|
+
*/
|
|
36
84
|
headerExistsNot(name: string): this;
|
|
85
|
+
/**
|
|
86
|
+
* Check response header for exact match.
|
|
87
|
+
*/
|
|
37
88
|
headerIs(name: string, value: string): this;
|
|
89
|
+
/**
|
|
90
|
+
* Opposite of `headerIs`.
|
|
91
|
+
*/
|
|
38
92
|
headerIsnt(name: string, value: string): this;
|
|
93
|
+
/**
|
|
94
|
+
* Check response header for similar match.
|
|
95
|
+
*/
|
|
39
96
|
headerLike(name: string, regex: RegExp): this;
|
|
40
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Check if JSON response contains a value that can be identified using the given JSON Pointer.
|
|
99
|
+
*/
|
|
41
100
|
jsonHas(pointer: string): this;
|
|
101
|
+
/**
|
|
102
|
+
* Check the value extracted from JSON response using the given JSON Pointerr, which defaults to the root value if it
|
|
103
|
+
* is omitted.
|
|
104
|
+
*/
|
|
105
|
+
jsonIs(value: JSONValue, pointer?: string): this;
|
|
106
|
+
/**
|
|
107
|
+
* Wait for next WebSocket message to arrive.
|
|
108
|
+
*/
|
|
42
109
|
messageOk(): Promise<JSONValue>;
|
|
110
|
+
/**
|
|
111
|
+
* Create a new test user agent.
|
|
112
|
+
*/
|
|
43
113
|
static newTestUserAgent(app: App, options?: TestUserAgentOptions): Promise<TestUserAgent>;
|
|
114
|
+
/**
|
|
115
|
+
* Perform a `OPTIONS` request and check for transport errors.
|
|
116
|
+
*/
|
|
44
117
|
optionsOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
118
|
+
/**
|
|
119
|
+
* Perform a `PATCH` request and check for transport errors.
|
|
120
|
+
*/
|
|
45
121
|
patchOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
122
|
+
/**
|
|
123
|
+
* Perform a `POST` request and check for transport errors.
|
|
124
|
+
*/
|
|
46
125
|
postOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
126
|
+
/**
|
|
127
|
+
* Perform a `PUT` request and check for transport errors.
|
|
128
|
+
*/
|
|
47
129
|
putOk(url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
|
130
|
+
/**
|
|
131
|
+
* Current HTTP response.
|
|
132
|
+
*/
|
|
48
133
|
get res(): UserAgentResponse;
|
|
134
|
+
/**
|
|
135
|
+
* Send message or frame via WebSocket.
|
|
136
|
+
*/
|
|
49
137
|
sendOk(message: JSONValue | Buffer): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Check response status for exact match.
|
|
140
|
+
*/
|
|
50
141
|
statusIs(status: number): this;
|
|
142
|
+
/**
|
|
143
|
+
* Checks text content of the CSS selectors first matching HTML/XML element for similar match.
|
|
144
|
+
*/
|
|
51
145
|
textLike(selector: string, regex: RegExp): this;
|
|
146
|
+
/**
|
|
147
|
+
* Check response `Content-Type` header for exact match.
|
|
148
|
+
*/
|
|
52
149
|
typeIs(value: string): this;
|
|
150
|
+
/**
|
|
151
|
+
* Check response `Content-Type` header for similar match.
|
|
152
|
+
*/
|
|
53
153
|
typeLike(regex: RegExp): this;
|
|
154
|
+
/**
|
|
155
|
+
* Open a WebSocket connection with transparent handshake.
|
|
156
|
+
*/
|
|
54
157
|
websocketOk(url: string | URL, options?: UserAgentWebSocketOptions): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Active WebSocket connection.
|
|
160
|
+
*/
|
|
55
161
|
get ws(): WebSocket;
|
|
56
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Check if YAML response contains a value that can be identified using the given JSON Pointer.
|
|
164
|
+
*/
|
|
57
165
|
yamlHas(pointer: string): this;
|
|
166
|
+
/**
|
|
167
|
+
* Check the value extracted from YAML response using the given JSON Pointerr, which defaults to the root value if it
|
|
168
|
+
* is omitted.
|
|
169
|
+
*/
|
|
170
|
+
yamlIs(value: JSONValue, pointer?: string): this;
|
|
58
171
|
get _html(): DOM;
|
|
59
172
|
_prepareTap(tap: Tap.Tap): void;
|
|
60
173
|
_requestOk(skip: SkipFunction, method: string, url: string | URL, options?: UserAgentRequestOptions): Promise<this>;
|
package/lib/user-agent/test.js
CHANGED
|
@@ -5,9 +5,15 @@ import { MockUserAgent } from './mock.js';
|
|
|
5
5
|
import DOM from '@mojojs/dom';
|
|
6
6
|
import yaml from 'js-yaml';
|
|
7
7
|
import StackUtils from 'stack-utils';
|
|
8
|
+
/**
|
|
9
|
+
* Test user agent class.
|
|
10
|
+
*/
|
|
8
11
|
export class TestUserAgent extends MockUserAgent {
|
|
9
12
|
constructor(options = {}) {
|
|
10
13
|
super(options);
|
|
14
|
+
/**
|
|
15
|
+
* Current HTTP response content.
|
|
16
|
+
*/
|
|
11
17
|
this.body = Buffer.from('');
|
|
12
18
|
this._assert = undefined;
|
|
13
19
|
this._dom = undefined;
|
|
@@ -19,85 +25,146 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
19
25
|
if (options.tap !== undefined)
|
|
20
26
|
this._prepareTap(options.tap);
|
|
21
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Delegate assertion to test framework currently in use.
|
|
30
|
+
*/
|
|
22
31
|
assert(name, args, msg, skip) {
|
|
23
32
|
const test = this._assert ?? assert;
|
|
24
33
|
test[name](...args, msg, { stack: this._stack.captureString(10, skip) });
|
|
25
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Check response content for exact match.
|
|
37
|
+
*/
|
|
26
38
|
bodyIs(body) {
|
|
27
39
|
this.assert('equal', [this.body.toString(), body], 'body is equal', this.bodyIs);
|
|
28
40
|
return this;
|
|
29
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Opposite of `bodyIs`.
|
|
44
|
+
*/
|
|
30
45
|
bodyIsnt(body) {
|
|
31
46
|
this.assert('not', [this.body.toString(), body], 'body is not equal', this.bodyIsnt);
|
|
32
47
|
return this;
|
|
33
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Check response content for similar match.
|
|
51
|
+
*/
|
|
34
52
|
bodyLike(regex) {
|
|
35
53
|
this.assert('match', [this.body.toString(), regex], 'body is similar', this.bodyLike);
|
|
36
54
|
return this;
|
|
37
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Opposite of `bodyLike`.
|
|
58
|
+
*/
|
|
38
59
|
bodyUnlike(regex) {
|
|
39
60
|
this.assert('notMatch', [this.body.toString(), regex], 'body is not similar', this.bodyUnlike);
|
|
40
61
|
return this;
|
|
41
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Close WebSocket connection gracefully.
|
|
65
|
+
*/
|
|
42
66
|
async closeOk(code, reason) {
|
|
43
67
|
this.ws.close(code, reason);
|
|
44
68
|
await this._waitFinished();
|
|
45
69
|
this.assert('ok', [true], 'closed WebSocket', this.closeOk);
|
|
46
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Wait for WebSocket connection to be closed gracefully and check status.
|
|
73
|
+
*/
|
|
47
74
|
async closedOk(code) {
|
|
48
75
|
await this._waitFinished();
|
|
49
76
|
const finished = this._finished == null ? null : this._finished[0];
|
|
50
77
|
this.assert('equal', [finished, code], `WebSocket closed with status ${code}`, this.closedOk);
|
|
51
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Perform a `DELETE` request and check for transport errors.
|
|
81
|
+
*/
|
|
52
82
|
async deleteOk(url, options) {
|
|
53
83
|
return await this._requestOk(this.deleteOk, 'DELETE', url, options);
|
|
54
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Checks for existence of the CSS selectors first matching HTML/XML element.
|
|
87
|
+
*/
|
|
55
88
|
elementExists(selector) {
|
|
56
89
|
const elements = this._html.find(selector);
|
|
57
90
|
this.assert('ok', [elements.length > 0], `element for selector "${selector}" exists`, this.elementExists);
|
|
58
91
|
return this;
|
|
59
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Opposite of `elementExists`.
|
|
95
|
+
*/
|
|
60
96
|
elementExistsNot(selector) {
|
|
61
97
|
const elements = this._html.find(selector);
|
|
62
98
|
this.assert('ok', [elements.length === 0], `no element for selector "${selector}"`, this.elementExistsNot);
|
|
63
99
|
return this;
|
|
64
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Perform a `GET` request and check for transport errors.
|
|
103
|
+
*/
|
|
65
104
|
async getOk(url, options) {
|
|
66
105
|
return await this._requestOk(this.getOk, 'GET', url, options);
|
|
67
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Perform a `HEAD` request and check for transport errors.
|
|
109
|
+
*/
|
|
68
110
|
async headOk(url, options) {
|
|
69
111
|
return await this._requestOk(this.headOk, 'HEAD', url, options);
|
|
70
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Check if response header exists.
|
|
115
|
+
*/
|
|
71
116
|
headerExists(name) {
|
|
72
117
|
this.assert('ok', [this.res.get(name) !== undefined], `header "${name}" exists`, this.headerExists);
|
|
73
118
|
return this;
|
|
74
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Opposite of `headerExists`.
|
|
122
|
+
*/
|
|
75
123
|
headerExistsNot(name) {
|
|
76
124
|
this.assert('notOk', [this.res.get(name) !== undefined], `no "${name}" header`, this.headerExistsNot);
|
|
77
125
|
return this;
|
|
78
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Check response header for exact match.
|
|
129
|
+
*/
|
|
79
130
|
headerIs(name, value) {
|
|
80
131
|
this.assert('equal', [this.res.get(name), value], `${name}: ${value}`, this.headerIs);
|
|
81
132
|
return this;
|
|
82
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Opposite of `headerIs`.
|
|
136
|
+
*/
|
|
83
137
|
headerIsnt(name, value) {
|
|
84
138
|
this.assert('not', [this.res.get(name), value], `not ${name}: ${value}`, this.headerIsnt);
|
|
85
139
|
return this;
|
|
86
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Check response header for similar match.
|
|
143
|
+
*/
|
|
87
144
|
headerLike(name, regex) {
|
|
88
145
|
this.assert('match', [this.res.get(name), regex], `${name} is similar`, this.headerLike);
|
|
89
146
|
return this;
|
|
90
147
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
148
|
+
/**
|
|
149
|
+
* Check if JSON response contains a value that can be identified using the given JSON Pointer.
|
|
150
|
+
*/
|
|
96
151
|
jsonHas(pointer) {
|
|
97
152
|
const has = jsonPointer(JSON.parse(this.body.toString()), pointer) !== undefined;
|
|
98
153
|
this.assert('ok', [has], `has value for JSON Pointer "${pointer}" (JSON)`, this.jsonHas);
|
|
99
154
|
return this;
|
|
100
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Check the value extracted from JSON response using the given JSON Pointerr, which defaults to the root value if it
|
|
158
|
+
* is omitted.
|
|
159
|
+
*/
|
|
160
|
+
jsonIs(value, pointer = '') {
|
|
161
|
+
const expected = jsonPointer(JSON.parse(this.body.toString()), pointer);
|
|
162
|
+
this.assert('same', [expected, value], `exact match for JSON Pointer "${pointer}" (JSON)`, this.jsonIs);
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Wait for next WebSocket message to arrive.
|
|
167
|
+
*/
|
|
101
168
|
async messageOk() {
|
|
102
169
|
if (this._messages === undefined)
|
|
103
170
|
throw new Error('No active WebSocket connection');
|
|
@@ -105,48 +172,84 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
105
172
|
this.assert('ok', [true], 'message received', this.messageOk);
|
|
106
173
|
return message;
|
|
107
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Create a new test user agent.
|
|
177
|
+
*/
|
|
108
178
|
static async newTestUserAgent(app, options) {
|
|
109
179
|
app.exceptionFormat = 'txt';
|
|
110
180
|
return await new TestUserAgent(options).start(app);
|
|
111
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Perform a `OPTIONS` request and check for transport errors.
|
|
184
|
+
*/
|
|
112
185
|
async optionsOk(url, options) {
|
|
113
186
|
return await this._requestOk(this.optionsOk, 'OPTIONS', url, options);
|
|
114
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Perform a `PATCH` request and check for transport errors.
|
|
190
|
+
*/
|
|
115
191
|
async patchOk(url, options) {
|
|
116
192
|
return await this._requestOk(this.patchOk, 'PATCH', url, options);
|
|
117
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Perform a `POST` request and check for transport errors.
|
|
196
|
+
*/
|
|
118
197
|
async postOk(url, options) {
|
|
119
198
|
return await this._requestOk(this.postOk, 'POST', url, options);
|
|
120
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Perform a `PUT` request and check for transport errors.
|
|
202
|
+
*/
|
|
121
203
|
async putOk(url, options) {
|
|
122
204
|
return await this._requestOk(this.putOk, 'PUT', url, options);
|
|
123
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* Current HTTP response.
|
|
208
|
+
*/
|
|
124
209
|
get res() {
|
|
125
210
|
const res = this._res;
|
|
126
211
|
if (res === undefined)
|
|
127
212
|
throw new Error('No active HTTP response');
|
|
128
213
|
return res;
|
|
129
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Send message or frame via WebSocket.
|
|
217
|
+
*/
|
|
130
218
|
async sendOk(message) {
|
|
131
219
|
await this.ws.send(message);
|
|
132
220
|
this.assert('ok', [true], 'send message', this.sendOk);
|
|
133
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Check response status for exact match.
|
|
224
|
+
*/
|
|
134
225
|
statusIs(status) {
|
|
135
226
|
this.assert('equal', [this.res.status, status], `response status is ${status}`, this.statusIs);
|
|
136
227
|
return this;
|
|
137
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Checks text content of the CSS selectors first matching HTML/XML element for similar match.
|
|
231
|
+
*/
|
|
138
232
|
textLike(selector, regex) {
|
|
139
233
|
this.assert('match', [this._html.at(selector)?.text() ?? '', regex], `similar match for selector "${selector}"`, this.textLike);
|
|
140
234
|
return this;
|
|
141
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* Check response `Content-Type` header for exact match.
|
|
238
|
+
*/
|
|
142
239
|
typeIs(value) {
|
|
143
240
|
this.assert('equal', [this.res.type, value], `Content-Type: ${value}`, this.typeIs);
|
|
144
241
|
return this;
|
|
145
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Check response `Content-Type` header for similar match.
|
|
245
|
+
*/
|
|
146
246
|
typeLike(regex) {
|
|
147
247
|
this.assert('match', [this.res.type, regex], 'Content-Type is similar', this.typeLike);
|
|
148
248
|
return this;
|
|
149
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Open a WebSocket connection with transparent handshake.
|
|
252
|
+
*/
|
|
150
253
|
async websocketOk(url, options) {
|
|
151
254
|
const ws = (this._ws = await this.websocket(url, options));
|
|
152
255
|
this._res = ws.handshake ?? undefined;
|
|
@@ -155,22 +258,32 @@ export class TestUserAgent extends MockUserAgent {
|
|
|
155
258
|
this._messages = on(this.ws, 'message');
|
|
156
259
|
this.assert('ok', [true], `WebSocket handshake with ${url.toString()}`, this.websocketOk);
|
|
157
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Active WebSocket connection.
|
|
263
|
+
*/
|
|
158
264
|
get ws() {
|
|
159
265
|
const ws = this._ws;
|
|
160
266
|
if (ws === undefined)
|
|
161
267
|
throw new Error('No active WebSocket connection');
|
|
162
268
|
return ws;
|
|
163
269
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return this;
|
|
168
|
-
}
|
|
270
|
+
/**
|
|
271
|
+
* Check if YAML response contains a value that can be identified using the given JSON Pointer.
|
|
272
|
+
*/
|
|
169
273
|
yamlHas(pointer) {
|
|
170
274
|
const has = jsonPointer(yaml.load(this.body.toString()), pointer) !== undefined;
|
|
171
275
|
this.assert('ok', [has], `has value for JSON Pointer "${pointer}" (YAML)`, this.jsonHas);
|
|
172
276
|
return this;
|
|
173
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Check the value extracted from YAML response using the given JSON Pointerr, which defaults to the root value if it
|
|
280
|
+
* is omitted.
|
|
281
|
+
*/
|
|
282
|
+
yamlIs(value, pointer = '') {
|
|
283
|
+
const expected = jsonPointer(yaml.load(this.body.toString()), pointer);
|
|
284
|
+
this.assert('same', [expected, value], `exact match for JSON Pointer "${pointer}" (YAML)`, this.yamlIs);
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
174
287
|
get _html() {
|
|
175
288
|
if (this._dom === undefined)
|
|
176
289
|
this._dom = new DOM((this.body ?? '').toString());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/user-agent/test.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,EAAC,EAAE,EAAC,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AACxC,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,UAAU,MAAM,aAAa,CAAC;AAIrC,MAAM,OAAO,aAAc,SAAQ,aAAa;
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/user-agent/test.ts"],"names":[],"mappings":"AAKA,OAAO,MAAM,MAAM,eAAe,CAAC;AACnC,OAAO,EAAC,EAAE,EAAC,MAAM,QAAQ,CAAC;AAC1B,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,aAAa,EAAC,MAAM,WAAW,CAAC;AACxC,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,UAAU,MAAM,aAAa,CAAC;AAIrC;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAc9C,YAAY,UAAgC,EAAE;QAC5C,KAAK,CAAC,OAAO,CAAC,CAAC;QAdjB;;WAEG;QACH,SAAI,GAAW,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAE/B,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EAAE;gBACzB,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -3,9 +3,21 @@ import type { UserAgentRequestOptions } from '../../types.js';
|
|
|
3
3
|
import type { URL } from 'url';
|
|
4
4
|
import http from 'http';
|
|
5
5
|
import { UserAgentResponse } from '../response.js';
|
|
6
|
+
/**
|
|
7
|
+
* HTTP transport class.
|
|
8
|
+
*/
|
|
6
9
|
export declare class HTTPTransport {
|
|
10
|
+
/**
|
|
11
|
+
* HTTP agent.
|
|
12
|
+
*/
|
|
7
13
|
agent: http.Agent;
|
|
14
|
+
/**
|
|
15
|
+
* Destroy active keep-alive connections.
|
|
16
|
+
*/
|
|
8
17
|
destroy(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Perform HTTP request.
|
|
20
|
+
*/
|
|
9
21
|
request(config: UserAgentRequestOptions): Promise<UserAgentResponse>;
|
|
10
22
|
_prepareOptions(config: UserAgentRequestOptions): http.RequestOptions;
|
|
11
23
|
_sendRequest(url: URL, options: http.RequestOptions, cb: (res: http.IncomingMessage) => void): http.ClientRequest;
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import Stream from 'stream';
|
|
3
3
|
import { UserAgentResponse } from '../response.js';
|
|
4
|
+
/**
|
|
5
|
+
* HTTP transport class.
|
|
6
|
+
*/
|
|
4
7
|
export class HTTPTransport {
|
|
5
8
|
constructor() {
|
|
9
|
+
/**
|
|
10
|
+
* HTTP agent.
|
|
11
|
+
*/
|
|
6
12
|
this.agent = new http.Agent();
|
|
7
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Destroy active keep-alive connections.
|
|
16
|
+
*/
|
|
8
17
|
destroy() {
|
|
9
18
|
this.agent.destroy();
|
|
10
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Perform HTTP request.
|
|
22
|
+
*/
|
|
11
23
|
async request(config) {
|
|
12
24
|
const options = this._prepareOptions(config);
|
|
13
25
|
return await new Promise((resolve, reject) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/user-agent/transport/http.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAEjD,MAAM,OAAO,aAAa;IAA1B;QACE,UAAK,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../src/user-agent/transport/http.ts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,MAAM,OAAO,aAAa;IAA1B;QACE;;WAEG;QACH,UAAK,GAAG,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;IAyC3B,CAAC;IAvCC;;OAEG;IACH,OAAO;QACL,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,MAA+B;QAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAE7C,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAU,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACtG,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC1B,GAAG,CAAC,IAAI,CAAC,OAAO,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