@eggjs/supertest 8.2.0 → 8.3.0-beta.10

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.
Files changed (46) hide show
  1. package/README.md +51 -63
  2. package/dist/agent.d.ts +33 -0
  3. package/dist/agent.js +74 -0
  4. package/dist/error/AssertError.d.ts +8 -0
  5. package/dist/error/AssertError.js +15 -0
  6. package/dist/index.d.ts +17 -0
  7. package/dist/index.js +24 -0
  8. package/dist/request.d.ts +25 -0
  9. package/dist/request.js +51 -0
  10. package/dist/test.d.ts +100 -0
  11. package/dist/test.js +237 -0
  12. package/dist/types.d.ts +14 -0
  13. package/package.json +29 -54
  14. package/dist/commonjs/agent.d.ts +0 -28
  15. package/dist/commonjs/agent.js +0 -94
  16. package/dist/commonjs/error/AssertError.d.ts +0 -5
  17. package/dist/commonjs/error/AssertError.js +0 -16
  18. package/dist/commonjs/index.d.ts +0 -14
  19. package/dist/commonjs/index.js +0 -47
  20. package/dist/commonjs/package.json +0 -3
  21. package/dist/commonjs/request.d.ts +0 -21
  22. package/dist/commonjs/request.js +0 -63
  23. package/dist/commonjs/test.d.ts +0 -96
  24. package/dist/commonjs/test.js +0 -326
  25. package/dist/commonjs/types.d.ts +0 -10
  26. package/dist/commonjs/types.js +0 -3
  27. package/dist/esm/agent.d.ts +0 -28
  28. package/dist/esm/agent.js +0 -87
  29. package/dist/esm/error/AssertError.d.ts +0 -5
  30. package/dist/esm/error/AssertError.js +0 -12
  31. package/dist/esm/index.d.ts +0 -14
  32. package/dist/esm/index.js +0 -30
  33. package/dist/esm/package.json +0 -3
  34. package/dist/esm/request.d.ts +0 -21
  35. package/dist/esm/request.js +0 -56
  36. package/dist/esm/test.d.ts +0 -96
  37. package/dist/esm/test.js +0 -322
  38. package/dist/esm/types.d.ts +0 -10
  39. package/dist/esm/types.js +0 -2
  40. package/dist/package.json +0 -4
  41. package/src/agent.ts +0 -96
  42. package/src/error/AssertError.ts +0 -12
  43. package/src/index.ts +0 -39
  44. package/src/request.ts +0 -62
  45. package/src/test.ts +0 -372
  46. package/src/types.ts +0 -17
package/dist/test.js ADDED
@@ -0,0 +1,237 @@
1
+ import { AssertError } from "./error/AssertError.js";
2
+ import { STATUS_CODES } from "node:http";
3
+ import { inspect } from "node:util";
4
+ import { Server } from "node:tls";
5
+ import { deepStrictEqual } from "node:assert";
6
+ import { Request } from "superagent";
7
+
8
+ //#region src/test.ts
9
+ var Test = class extends Request {
10
+ app;
11
+ _server;
12
+ _asserts = [];
13
+ /**
14
+ * Initialize a new `Test` with the given `app`,
15
+ * request `method` and `path`.
16
+ */
17
+ constructor(app, method, path) {
18
+ super(method.toUpperCase(), path);
19
+ this.redirects(0);
20
+ this.buffer();
21
+ this.app = app;
22
+ this.url = typeof app === "string" ? app + path : this.serverAddress(app, path);
23
+ }
24
+ /**
25
+ * Returns a URL, extracted from a server.
26
+ *
27
+ * @return {String} URL address
28
+ * @private
29
+ */
30
+ serverAddress(app, path) {
31
+ if (!app.address()) this._server = app.listen(0);
32
+ const port = app.address().port;
33
+ return `${app instanceof Server || this._server instanceof Server ? "https" : "http"}://127.0.0.1:${port}${path}`;
34
+ }
35
+ /**
36
+ * Expectations:
37
+ *
38
+ * ```js
39
+ * .expect(200)
40
+ * .expect(200, fn)
41
+ * .expect(200, body)
42
+ * .expect('Some body')
43
+ * .expect('Some body', fn)
44
+ * .expect(['json array body', { key: 'val' }])
45
+ * .expect('Content-Type', 'application/json')
46
+ * .expect('Content-Type', 'application/json', fn)
47
+ * .expect(fn)
48
+ * .expect([200, 404])
49
+ * ```
50
+ *
51
+ * @return {Test} The current Test instance for chaining.
52
+ */
53
+ expect(a, b, c) {
54
+ if (typeof a === "function") {
55
+ this._asserts.push(wrapAssertFn(a));
56
+ return this;
57
+ }
58
+ if (typeof b === "function") this.end(b);
59
+ if (typeof c === "function") this.end(c);
60
+ if (typeof a === "number") {
61
+ this._asserts.push(wrapAssertFn(this._assertStatus.bind(this, a)));
62
+ if (typeof b !== "function" && arguments.length > 1) this._asserts.push(wrapAssertFn(this._assertBody.bind(this, b)));
63
+ return this;
64
+ }
65
+ if (Array.isArray(a) && a.length > 0 && a.every((val) => typeof val === "number")) {
66
+ this._asserts.push(wrapAssertFn(this._assertStatusArray.bind(this, a)));
67
+ return this;
68
+ }
69
+ if (typeof b === "string" || typeof b === "number" || b instanceof RegExp) {
70
+ this._asserts.push(wrapAssertFn(this._assertHeader.bind(this, {
71
+ name: String(a),
72
+ value: b
73
+ })));
74
+ return this;
75
+ }
76
+ this._asserts.push(wrapAssertFn(this._assertBody.bind(this, a)));
77
+ return this;
78
+ }
79
+ /**
80
+ * UnExpectations:
81
+ *
82
+ * .unexpectHeader('Content-Type')
83
+ * .unexpectHeader('Content-Type', fn)
84
+ */
85
+ unexpectHeader(name, fn) {
86
+ if (typeof fn === "function") this.end(fn);
87
+ if (typeof name === "string") this._asserts.push(this._unexpectHeader.bind(this, name));
88
+ return this;
89
+ }
90
+ /**
91
+ * Expectations:
92
+ *
93
+ * .expectHeader('Content-Type')
94
+ * .expectHeader('Content-Type', fn)
95
+ */
96
+ expectHeader(name, fn) {
97
+ if (typeof fn === "function") this.end(fn);
98
+ if (typeof name === "string") this._asserts.push(this._expectHeader.bind(this, name));
99
+ return this;
100
+ }
101
+ _unexpectHeader(name, res) {
102
+ const actual = res.headers[name.toLowerCase()];
103
+ if (actual) return new AssertError("unexpected \"" + name + "\" header field, got \"" + actual + "\"", name, actual);
104
+ }
105
+ _expectHeader(name, res) {
106
+ const actual = res.headers[name.toLowerCase()];
107
+ if (!actual) return new AssertError("expected \"" + name + "\" header field", name, actual);
108
+ }
109
+ /**
110
+ * Defer invoking superagent's `.end()` until
111
+ * the server is listening.
112
+ */
113
+ end(fn) {
114
+ const server = this._server;
115
+ super.end((err, res) => {
116
+ const localAssert = () => {
117
+ this.assert(err, res, fn);
118
+ };
119
+ if (server && "_handle" in server && server._handle) return server.close(localAssert);
120
+ localAssert();
121
+ });
122
+ return this;
123
+ }
124
+ /**
125
+ * Perform assertions and invoke `fn(err, res)`.
126
+ */
127
+ assert(resError, res, fn) {
128
+ let errorObj;
129
+ const sysErrors = {
130
+ ECONNREFUSED: "Connection refused",
131
+ ECONNRESET: "Connection reset by peer",
132
+ EPIPE: "Broken pipe",
133
+ ETIMEDOUT: "Operation timed out"
134
+ };
135
+ if (!res && resError) if (resError instanceof Error && resError.syscall === "connect" && resError.code && sysErrors[resError.code]) errorObj = /* @__PURE__ */ new Error(resError.code + ": " + sysErrors[resError.code]);
136
+ else errorObj = resError;
137
+ for (let i = 0; i < this._asserts.length && !errorObj; i += 1) errorObj = this._assertFunction(this._asserts[i], res);
138
+ if (!errorObj && resError instanceof Error && (!res || resError.status !== res.status)) errorObj = resError;
139
+ if (!fn) {
140
+ console.warn("[@eggjs/supertest] no callback function provided, fn: %s", typeof fn);
141
+ return;
142
+ }
143
+ fn.call(this, errorObj || null, res);
144
+ }
145
+ /**
146
+ * Perform assertions on a response body and return an Error upon failure.
147
+ */
148
+ _assertBody(body, res) {
149
+ const isRegexp = body instanceof RegExp;
150
+ if (typeof body === "object" && !isRegexp) try {
151
+ deepStrictEqual(body, res.body);
152
+ } catch (err) {
153
+ const a = inspect(body);
154
+ const b = inspect(res.body);
155
+ return new AssertError("expected " + a + " response body, got " + b, body, res.body, { cause: err });
156
+ }
157
+ else if (body !== res.text) {
158
+ const a = inspect(body);
159
+ const b = inspect(res.text);
160
+ if (isRegexp) {
161
+ if (!body.test(res.text)) return new AssertError("expected body " + b + " to match " + body, body, res.body);
162
+ } else return new AssertError("expected " + a + " response body, got " + b, body, res.body);
163
+ }
164
+ }
165
+ /**
166
+ * Perform assertions on a response header and return an Error upon failure.
167
+ */
168
+ _assertHeader(header, res) {
169
+ const field = header.name;
170
+ const actual = res.header[field.toLowerCase()];
171
+ const fieldExpected = header.value;
172
+ if (typeof actual === "undefined") return new AssertError("expected \"" + field + "\" header field", header, actual);
173
+ if (Array.isArray(actual) && actual.toString() === fieldExpected || fieldExpected === actual) return;
174
+ if (fieldExpected instanceof RegExp) {
175
+ if (!fieldExpected.test(actual)) return new AssertError("expected \"" + field + "\" matching " + fieldExpected + ", got \"" + actual + "\"", header, actual);
176
+ } else return new AssertError("expected \"" + field + "\" of \"" + fieldExpected + "\", got \"" + actual + "\"", header, actual);
177
+ }
178
+ /**
179
+ * Perform assertions on the response status and return an Error upon failure.
180
+ */
181
+ _assertStatus(status, res) {
182
+ if (res.status !== status) {
183
+ const a = STATUS_CODES[status];
184
+ const b = STATUS_CODES[res.status];
185
+ return new AssertError("expected " + status + " \"" + a + "\", got " + res.status + " \"" + b + "\"", status, res.status);
186
+ }
187
+ }
188
+ /**
189
+ * Perform assertions on the response status and return an Error upon failure.
190
+ */
191
+ _assertStatusArray(statusArray, res) {
192
+ if (!statusArray.includes(res.status)) {
193
+ const b = STATUS_CODES[res.status];
194
+ const expectedList = statusArray.join(", ");
195
+ return new AssertError("expected one of \"" + expectedList + "\", got " + res.status + " \"" + b + "\"", statusArray, res.status);
196
+ }
197
+ }
198
+ /**
199
+ * Performs an assertion by calling a function and return an Error upon failure.
200
+ */
201
+ _assertFunction(fn, res) {
202
+ let err;
203
+ try {
204
+ err = fn(res);
205
+ } catch (e) {
206
+ err = e;
207
+ }
208
+ if (err instanceof Error) return err;
209
+ }
210
+ };
211
+ /**
212
+ * Wraps an assert function into another.
213
+ * The wrapper function edit the stack trace of any assertion error, prepending a more useful stack to it.
214
+ *
215
+ * @param {Function} assertFn
216
+ * @return {Function} wrapped assert function
217
+ */
218
+ function wrapAssertFn(assertFn) {
219
+ const savedStack = (/* @__PURE__ */ new Error()).stack.split("\n").slice(3);
220
+ return (res) => {
221
+ let badStack;
222
+ let err;
223
+ try {
224
+ err = assertFn(res);
225
+ } catch (e) {
226
+ err = e;
227
+ }
228
+ if (err instanceof Error && err.stack) {
229
+ badStack = err.stack.replace(err.message, "").split("\n").slice(1);
230
+ err.stack = [err.toString()].concat(savedStack).concat("----").concat(badStack).join("\n");
231
+ }
232
+ return err;
233
+ };
234
+ }
235
+
236
+ //#endregion
237
+ export { Test };
@@ -0,0 +1,14 @@
1
+ import { RequestListener } from "node:http";
2
+ import { Http2ServerRequest, Http2ServerResponse } from "node:http2";
3
+ import { AgentOptions } from "superagent";
4
+ import { Server } from "node:net";
5
+
6
+ //#region src/types.d.ts
7
+ type H2RequestListener = (request: Http2ServerRequest, response: Http2ServerResponse) => void;
8
+ type H1RequestListener = RequestListener;
9
+ type App = Server | H1RequestListener | H2RequestListener | string;
10
+ interface AgentOptions$1 extends AgentOptions {
11
+ http2?: boolean;
12
+ }
13
+ //#endregion
14
+ export { AgentOptions$1 as AgentOptions, App };
package/package.json CHANGED
@@ -1,10 +1,21 @@
1
1
  {
2
2
  "name": "@eggjs/supertest",
3
3
  "description": "SuperAgent driven library for testing HTTP servers",
4
- "version": "8.2.0",
4
+ "version": "8.3.0-beta.10",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
+ "type": "module",
9
+ "exports": {
10
+ ".": "./dist/index.js",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "main": "./dist/index.js",
17
+ "module": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
8
19
  "author": "TJ Holowaychuk",
9
20
  "keywords": [
10
21
  "bdd",
@@ -18,69 +29,33 @@
18
29
  "license": "MIT",
19
30
  "repository": {
20
31
  "type": "git",
21
- "url": "https://github.com/eggjs/supertest.git"
32
+ "url": "git://github.com/eggjs/egg.git",
33
+ "directory": "packages/supertest"
22
34
  },
35
+ "homepage": "https://github.com/eggjs/egg/tree/next/packages/supertest",
23
36
  "engines": {
24
- "node": ">= 18.19.0"
37
+ "node": ">= 20.19.0"
25
38
  },
26
39
  "dependencies": {
27
40
  "@types/superagent": "^8.1.9",
28
- "superagent": "^9.0.1"
41
+ "superagent": "^10.0.0"
29
42
  },
30
43
  "devDependencies": {
31
- "@arethetypeswrong/cli": "^0.17.3",
32
- "@eggjs/bin": "7",
33
- "@eggjs/tsconfig": "1",
34
44
  "@types/body-parser": "^1.19.5",
35
45
  "@types/cookie-parser": "^1.4.8",
36
46
  "@types/express": "^5.0.0",
37
- "@types/mocha": "10",
38
- "@types/node": "22",
39
- "body-parser": "^1.20.3",
47
+ "@types/node": "24.5.2",
48
+ "body-parser": "^2.0.0",
40
49
  "cookie-parser": "^1.4.6",
41
- "eslint": "8",
42
- "eslint-config-egg": "14",
43
- "express": "^4.18.2",
44
- "nock": "^13.3.0",
45
- "nyc": "^15.1.0",
46
- "should": "^13.2.3",
47
- "tshy": "3",
48
- "tshy-after": "1",
49
- "typescript": "5"
50
+ "express": "^4.21.2",
51
+ "tsdown": "^0.15.4",
52
+ "typescript": "5.9.2",
53
+ "@eggjs/bin": "7.4.0-beta.10"
50
54
  },
51
55
  "scripts": {
52
- "lint": "eslint --cache src test --ext .ts",
53
- "pretest": "npm run lint -- --fix && npm run prepublishOnly",
54
- "test": "egg-bin test",
55
- "preci": "npm run lint && npm run prepublishOnly && attw --pack",
56
- "ci": "egg-bin cov",
57
- "prepublishOnly": "tshy && tshy-after"
58
- },
59
- "type": "module",
60
- "tshy": {
61
- "exports": {
62
- ".": "./src/index.ts",
63
- "./package.json": "./package.json"
64
- }
65
- },
66
- "exports": {
67
- ".": {
68
- "import": {
69
- "types": "./dist/esm/index.d.ts",
70
- "default": "./dist/esm/index.js"
71
- },
72
- "require": {
73
- "types": "./dist/commonjs/index.d.ts",
74
- "default": "./dist/commonjs/index.js"
75
- }
76
- },
77
- "./package.json": "./package.json"
78
- },
79
- "files": [
80
- "dist",
81
- "src"
82
- ],
83
- "types": "./dist/commonjs/index.d.ts",
84
- "main": "./dist/commonjs/index.js",
85
- "module": "./dist/esm/index.js"
86
- }
56
+ "build": "tsdown",
57
+ "test": "vitest run",
58
+ "typecheck": "tsc --noEmit",
59
+ "lint": "oxlint --type-aware"
60
+ }
61
+ }
@@ -1,28 +0,0 @@
1
- import type { Server } from 'node:net';
2
- import { agent as Agent } from 'superagent';
3
- import { Test } from './test.js';
4
- import type { AgentOptions, App } from './types.js';
5
- /**
6
- * Initialize a new `TestAgent`.
7
- *
8
- * @param {Function|Server} app
9
- * @param {Object} options
10
- */
11
- export declare class TestAgent extends Agent {
12
- #private;
13
- app: Server | string;
14
- _host: string;
15
- constructor(appOrListener: App, options?: AgentOptions);
16
- host(host: string): this;
17
- protected _testRequest(method: string, url: string): Test;
18
- delete(url: string): Test;
19
- del(url: string): Test;
20
- get(url: string): Test;
21
- head(url: string): Test;
22
- put(url: string): Test;
23
- post(url: string): Test;
24
- patch(url: string): Test;
25
- options(url: string): Test;
26
- trace(url: string): Test;
27
- }
28
- export declare const proxyAgent: typeof TestAgent;
@@ -1,94 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.proxyAgent = exports.TestAgent = void 0;
7
- const node_http_1 = __importDefault(require("node:http"));
8
- const node_http2_1 = __importDefault(require("node:http2"));
9
- const superagent_1 = require("superagent");
10
- const test_js_1 = require("./test.js");
11
- /**
12
- * Initialize a new `TestAgent`.
13
- *
14
- * @param {Function|Server} app
15
- * @param {Object} options
16
- */
17
- class TestAgent extends superagent_1.agent {
18
- app;
19
- _host;
20
- #http2 = false;
21
- constructor(appOrListener, options = {}) {
22
- super(options);
23
- if (typeof appOrListener === 'function') {
24
- if (options.http2) {
25
- this.#http2 = true;
26
- this.app = node_http2_1.default.createServer(appOrListener); // eslint-disable-line no-param-reassign
27
- }
28
- else {
29
- this.app = node_http_1.default.createServer(appOrListener); // eslint-disable-line no-param-reassign
30
- }
31
- }
32
- else {
33
- this.app = appOrListener;
34
- }
35
- }
36
- // set a host name
37
- host(host) {
38
- this._host = host;
39
- return this;
40
- }
41
- // TestAgent.prototype.del = TestAgent.prototype.delete;
42
- _testRequest(method, url) {
43
- const req = new test_js_1.Test(this.app, method.toUpperCase(), url);
44
- if (this.#http2) {
45
- req.http2();
46
- }
47
- if (this._host) {
48
- req.set('host', this._host);
49
- }
50
- const that = this;
51
- // access not internal methods
52
- req.on('response', that._saveCookies.bind(this));
53
- req.on('redirect', that._saveCookies.bind(this));
54
- req.on('redirect', that._attachCookies.bind(this, req));
55
- that._setDefaults(req);
56
- that._attachCookies(req);
57
- return req;
58
- }
59
- delete(url) {
60
- return this._testRequest('delete', url);
61
- }
62
- del(url) {
63
- return this._testRequest('delete', url);
64
- }
65
- get(url) {
66
- return this._testRequest('get', url);
67
- }
68
- head(url) {
69
- return this._testRequest('head', url);
70
- }
71
- put(url) {
72
- return this._testRequest('put', url);
73
- }
74
- post(url) {
75
- return this._testRequest('post', url);
76
- }
77
- patch(url) {
78
- return this._testRequest('patch', url);
79
- }
80
- options(url) {
81
- return this._testRequest('options', url);
82
- }
83
- trace(url) {
84
- return this._testRequest('trace', url);
85
- }
86
- }
87
- exports.TestAgent = TestAgent;
88
- // allow keep use by `agent()`
89
- exports.proxyAgent = new Proxy(TestAgent, {
90
- apply(target, _, argumentsList) {
91
- return new target(argumentsList[0], argumentsList[1]);
92
- },
93
- });
94
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvYWdlbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUEsMERBQTZCO0FBQzdCLDREQUErQjtBQUUvQiwyQ0FBNEM7QUFDNUMsdUNBQWlDO0FBR2pDOzs7OztHQUtHO0FBRUgsTUFBYSxTQUFVLFNBQVEsa0JBQUs7SUFDbEMsR0FBRyxDQUFrQjtJQUNyQixLQUFLLENBQVM7SUFDZCxNQUFNLEdBQUcsS0FBSyxDQUFDO0lBRWYsWUFBWSxhQUFrQixFQUFFLFVBQXdCLEVBQUU7UUFDeEQsS0FBSyxDQUFDLE9BQU8sQ0FBQy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0QsR0FBRyxDQUFDLEdBQVc7UUFDYixPQUFPLElBQUksQ0FBQyxZQUFZLENBQUMsS0FBSyxFQUFFLEdBQUcsQ0FBQyxDQUFDO0lBQ3ZDLENBQUM7SUFDRCxJQUFJLENBQUMsR0FBVztRQUNkLE9BQU8sSUFBSSxDQUFDLFlBQVksQ0FBQyxNQUFNLEVBQUUsR0FBRyxDQUFDLENBQUM7SUFDeEMsQ0FBQztJQUNELEtBQUssQ0FBQyxHQUFXO1FBQ2YsT0FBTyxJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxHQUFHLENBQUMsQ0FBQztJQUN6QyxDQUFDO0lBQ0QsT0FBTyxDQUFDLEdBQVc7UUFDakIsT0FBTyxJQUFJLENBQUMsWUFBWSxDQUFDLFNBQVMsRUFBRSxHQUFHLENBQUMsQ0FBQztJQUMzQyxDQUFDO0lBQ0QsS0FBSyxDQUFDLEdBQVc7UUFDZixPQUFPLElBQUksQ0FBQyxZQUFZLENBQUMsT0FBTyxFQUFFLEdBQUcsQ0FBQyxDQUFDO0lBQ3pDLENBQUM7Q0FDRjtBQTFFRCw4QkEwRUM7QUFFRCw4QkFBOEI7QUFDakIsUUFBQSxVQUFVLEdBQUcsSUFBSSxLQUFLLENBQUMsU0FBUyxFQUFFO0lBQzdDLEtBQUssQ0FBQyxNQUFNLEVBQUUsQ0FBQyxFQUFFLGFBQWE7UUFDNUIsT0FBTyxJQUFJLE1BQU0sQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDLEVBQUUsYUFBYSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDeEQsQ0FBQztDQUNGLENBQUMsQ0FBQyJ9
@@ -1,5 +0,0 @@
1
- export declare class AssertError extends Error {
2
- expected: any;
3
- actual: any;
4
- constructor(message: string, expected: any, actual: any, options?: ErrorOptions);
5
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssertError = void 0;
4
- class AssertError extends Error {
5
- expected;
6
- actual;
7
- constructor(message, expected, actual, options) {
8
- super(message, options);
9
- this.name = this.constructor.name;
10
- this.expected = expected;
11
- this.actual = actual;
12
- Error.captureStackTrace(this, this.constructor);
13
- }
14
- }
15
- exports.AssertError = AssertError;
16
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQXNzZXJ0RXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvZXJyb3IvQXNzZXJ0RXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsTUFBYSxXQUFZLFNBQVEsS0FBSztJQUNwQyxRQUFRLENBQU07SUFDZCxNQUFNLENBQU07SUFFWixZQUFZLE9BQWUsRUFBRSxRQUFhLEVBQUUsTUFBVyxFQUFFLE9BQXNCO1FBQzdFLEtBQUssQ0FBQyxPQUFPLEVBQUUsT0FBTyxDQUFDLENBQUM7UUFDeEIsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQztRQUNsQyxJQUFJLENBQUMsUUFBUSxHQUFHLFFBQVEsQ0FBQztRQUN6QixJQUFJLENBQUMsTUFBTSxHQUFHLE1BQU0sQ0FBQztRQUNyQixLQUFLLENBQUMsaUJBQWlCLENBQUMsSUFBSSxFQUFFLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQztJQUNsRCxDQUFDO0NBQ0Y7QUFYRCxrQ0FXQyJ9
@@ -1,14 +0,0 @@
1
- import { Request, RequestOptions } from './request.js';
2
- import { TestAgent, proxyAgent } from './agent.js';
3
- import type { App, AgentOptions } from './types.js';
4
- /**
5
- * Test against the given `app`,
6
- * returning a new `Test`.
7
- */
8
- export declare function request(app: App, options?: RequestOptions): Request;
9
- export { Request, RequestOptions, TestAgent, proxyAgent as agent, };
10
- export * from './test.js';
11
- declare const _default: ((app: App, options?: RequestOptions) => Request) & {
12
- agent: (app: App, options?: AgentOptions) => TestAgent;
13
- };
14
- export default _default;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.agent = exports.TestAgent = exports.Request = void 0;
18
- exports.request = request;
19
- const request_js_1 = require("./request.js");
20
- Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return request_js_1.Request; } });
21
- const agent_js_1 = require("./agent.js");
22
- Object.defineProperty(exports, "TestAgent", { enumerable: true, get: function () { return agent_js_1.TestAgent; } });
23
- Object.defineProperty(exports, "agent", { enumerable: true, get: function () { return agent_js_1.proxyAgent; } });
24
- /**
25
- * Test against the given `app`,
26
- * returning a new `Test`.
27
- */
28
- function request(app, options = {}) {
29
- return new request_js_1.Request(app, options);
30
- }
31
- __exportStar(require("./test.js"), exports);
32
- // import request from '@eggjs/supertest';
33
- // request()
34
- exports.default = new Proxy(request, {
35
- apply(target, _, argumentsList) {
36
- return target(argumentsList[0], argumentsList[1]);
37
- },
38
- get(target, property, receiver) {
39
- // import request from '@eggjs/supertest';
40
- // request.agent()
41
- if (property === 'agent') {
42
- return agent_js_1.proxyAgent;
43
- }
44
- return Reflect.get(target, property, receiver);
45
- },
46
- });
47
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoia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-1,21 +0,0 @@
1
- import type { Server } from 'node:net';
2
- import type { App } from './types.js';
3
- import { Test } from './test.js';
4
- export interface RequestOptions {
5
- http2?: boolean;
6
- }
7
- export declare class Request {
8
- #private;
9
- app: string | Server;
10
- constructor(appOrListener: App, options?: RequestOptions);
11
- protected _testRequest(method: string, url: string): Test;
12
- delete(url: string): Test;
13
- del(url: string): Test;
14
- get(url: string): Test;
15
- head(url: string): Test;
16
- put(url: string): Test;
17
- post(url: string): Test;
18
- patch(url: string): Test;
19
- options(url: string): Test;
20
- trace(url: string): Test;
21
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Request = void 0;
7
- const node_http_1 = __importDefault(require("node:http"));
8
- const node_http2_1 = __importDefault(require("node:http2"));
9
- const test_js_1 = require("./test.js");
10
- class Request {
11
- app;
12
- #http2 = false;
13
- constructor(appOrListener, options = {}) {
14
- if (typeof appOrListener === 'function') {
15
- if (options.http2) {
16
- this.#http2 = true;
17
- this.app = node_http2_1.default.createServer(appOrListener); // eslint-disable-line no-param-reassign
18
- }
19
- else {
20
- this.app = node_http_1.default.createServer(appOrListener); // eslint-disable-line no-param-reassign
21
- }
22
- }
23
- else {
24
- this.app = appOrListener;
25
- }
26
- }
27
- _testRequest(method, url) {
28
- const req = new test_js_1.Test(this.app, method.toUpperCase(), url);
29
- if (this.#http2) {
30
- req.http2();
31
- }
32
- return req;
33
- }
34
- delete(url) {
35
- return this._testRequest('delete', url);
36
- }
37
- del(url) {
38
- return this._testRequest('delete', url);
39
- }
40
- get(url) {
41
- return this._testRequest('get', url);
42
- }
43
- head(url) {
44
- return this._testRequest('head', url);
45
- }
46
- put(url) {
47
- return this._testRequest('put', url);
48
- }
49
- post(url) {
50
- return this._testRequest('post', url);
51
- }
52
- patch(url) {
53
- return this._testRequest('patch', url);
54
- }
55
- options(url) {
56
- return this._testRequest('options', url);
57
- }
58
- trace(url) {
59
- return this._testRequest('trace', url);
60
- }
61
- }
62
- exports.Request = Request;
63
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVxdWVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9yZXF1ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7OztBQUFBLDBEQUE2QjtBQUM3Qiw0REFBK0I7QUFHL0IsdUNBQWlDO0FBTWpDLE1BQWEsT0FBTztJQUNsQixHQUFHLENBQWtCO0lBQ3JCLE1BQU0sR0FBRyxLQUFLLENBQUM7SUFFZixZQUFZLGFBQWtCLEVBQUUsVUFBMEIsRUFBRTtRQUMxRCxJQUFJLE9BQU8sYUFBYSxLQUFLLFVBQVUsRUFBRSxDQUFDO1lBQ3hDLElBQUksT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFDO2dCQUNsQixJQUFJLENBQUMsTUFBTSxHQUFHLElBQUksQ0FBQztnQkFDbkIsSUFBSSxDQUFDLEdBQUcsR0FBRyxvQkFBSyxDQUFDLFlBQVksQ0FBQyxhQUFrQyxDQUFDLENBQUMsQ0FBQyx3Q0FBd0M7WUFDN0csQ0FBQztpQkFBTSxDQUFDO2dCQUNOLElBQUksQ0FBQyxHQUFHLEdBQUcsbUJBQUksQ0FBQyxZQUFZLENBQUMsYUFBa0MsQ0FBQyxDQUFDLENBQUMsd0NBQXdDO1lBQzVHLENBQUM7UUFDSCxDQUFDO2FBQU0sQ0FBQztZQUNOLElBQUksQ0FBQyxHQUFHLEdBQUcsYUFBYSxDQUFDO1FBQzNCLENBQUM7SUFDSCxDQUFDO0lBRVMsWUFBWSxDQUFDLE1BQWMsRUFBRSxHQUFXO1FBQ2hELE1BQU0sR0FBRyxHQUFHLElBQUksY0FBSSxDQUFDLElBQUksQ0FBQyxHQUFHLEVBQUUsTUFBTS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