@eggjs/supertest
Advanced tools
+31
-26
@@ -1,28 +0,33 @@ | ||
| import type { Server } from 'node:net'; | ||
| import { agent as Agent } from 'superagent'; | ||
| import { Test } from './test.ts'; | ||
| import type { AgentOptions, App } from './types.ts'; | ||
| import { Test } from "./test.js"; | ||
| import { AgentOptions as AgentOptions$1, App } from "./types.js"; | ||
| import { agent } from "superagent"; | ||
| import { Server } from "node:net"; | ||
| //#region src/agent.d.ts | ||
| /** | ||
| * Initialize a new `TestAgent`. | ||
| * | ||
| * @param {Function|Server} app | ||
| * @param {Object} options | ||
| */ | ||
| export declare class TestAgent extends Agent { | ||
| #private; | ||
| app: Server | string; | ||
| _host: string; | ||
| constructor(appOrListener: App, options?: AgentOptions); | ||
| host(host: string): this; | ||
| protected _testRequest(method: string, url: string): Test; | ||
| delete(url: string): Test; | ||
| del(url: string): Test; | ||
| get(url: string): Test; | ||
| head(url: string): Test; | ||
| put(url: string): Test; | ||
| post(url: string): Test; | ||
| patch(url: string): Test; | ||
| options(url: string): Test; | ||
| trace(url: string): Test; | ||
| * Initialize a new `TestAgent`. | ||
| * | ||
| * @param {Function|Server} app | ||
| * @param {Object} options | ||
| */ | ||
| declare class TestAgent extends agent { | ||
| #private; | ||
| app: Server | string; | ||
| _host: string; | ||
| constructor(appOrListener: App, options?: AgentOptions$1); | ||
| host(host: string): this; | ||
| protected _testRequest(method: string, url: string): Test; | ||
| delete(url: string): Test; | ||
| del(url: string): Test; | ||
| get(url: string): Test; | ||
| head(url: string): Test; | ||
| put(url: string): Test; | ||
| post(url: string): Test; | ||
| patch(url: string): Test; | ||
| options(url: string): Test; | ||
| trace(url: string): Test; | ||
| } | ||
| export declare const proxyAgent: typeof TestAgent & ((app: App, options?: AgentOptions) => TestAgent); | ||
| declare const proxyAgent: typeof TestAgent & ((app: App, options?: AgentOptions$1) => TestAgent); | ||
| //#endregion | ||
| export { TestAgent, proxyAgent }; |
+72
-85
@@ -1,87 +0,74 @@ | ||
| import http from 'node:http'; | ||
| import http2 from 'node:http2'; | ||
| import { agent as Agent } from 'superagent'; | ||
| import { Test } from "./test.js"; | ||
| import http from "node:http"; | ||
| import http2 from "node:http2"; | ||
| import { agent } from "superagent"; | ||
| //#region src/agent.ts | ||
| /** | ||
| * Initialize a new `TestAgent`. | ||
| * | ||
| * @param {Function|Server} app | ||
| * @param {Object} options | ||
| */ | ||
| export class TestAgent extends Agent { | ||
| app; | ||
| _host; | ||
| #http2 = false; | ||
| constructor(appOrListener, options = {}) { | ||
| super(options); | ||
| if (typeof appOrListener === 'function') { | ||
| if (options.http2) { | ||
| this.#http2 = true; | ||
| this.app = http2.createServer(appOrListener); // eslint-disable-line no-param-reassign | ||
| } | ||
| else { | ||
| this.app = http.createServer(appOrListener); // eslint-disable-line no-param-reassign | ||
| } | ||
| } | ||
| else { | ||
| this.app = appOrListener; | ||
| } | ||
| } | ||
| // set a host name | ||
| host(host) { | ||
| this._host = host; | ||
| return this; | ||
| } | ||
| // TestAgent.prototype.del = TestAgent.prototype.delete; | ||
| _testRequest(method, url) { | ||
| const req = new Test(this.app, method.toUpperCase(), url); | ||
| if (this.#http2) { | ||
| req.http2(); | ||
| } | ||
| if (this._host) { | ||
| req.set('host', this._host); | ||
| } | ||
| const that = this; | ||
| // access not internal methods | ||
| req.on('response', that._saveCookies.bind(this)); | ||
| req.on('redirect', that._saveCookies.bind(this)); | ||
| req.on('redirect', that._attachCookies.bind(this, req)); | ||
| that._setDefaults(req); | ||
| that._attachCookies(req); | ||
| return req; | ||
| } | ||
| delete(url) { | ||
| return this._testRequest('delete', url); | ||
| } | ||
| del(url) { | ||
| return this._testRequest('delete', url); | ||
| } | ||
| get(url) { | ||
| return this._testRequest('get', url); | ||
| } | ||
| head(url) { | ||
| return this._testRequest('head', url); | ||
| } | ||
| put(url) { | ||
| return this._testRequest('put', url); | ||
| } | ||
| post(url) { | ||
| return this._testRequest('post', url); | ||
| } | ||
| patch(url) { | ||
| return this._testRequest('patch', url); | ||
| } | ||
| options(url) { | ||
| return this._testRequest('options', url); | ||
| } | ||
| trace(url) { | ||
| return this._testRequest('trace', url); | ||
| } | ||
| } | ||
| // allow keep use by `agent()` | ||
| export const proxyAgent = new Proxy(TestAgent, { | ||
| apply(target, _, argumentsList) { | ||
| return new target(argumentsList[0], argumentsList[1]); | ||
| }, | ||
| }); | ||
| //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWdlbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYWdlbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxJQUFJLE1BQU0sV0FBVyxDQUFDO0FBQzdCLE9BQU8sS0FBSyxNQUFNLFlBQVksQ0FBQztBQUcvQixPQUFPLEVBQUUsS0FBSyxJQUFJLEtBQUssRUFBRSxNQUFNLFlBQVksQ0FBQztBQUU1QyxPQUFPLEVBQUUsSUFBSSxFQUFFLE1BQU0sV0FBVyxDQUFDO0FBR2pDOzs7OztHQUtHO0FBRUgsTUFBTSxPQUFPLFNBQVUsU0FBUSxLQUFLO0lBQ2xDLEdBQUcsQ0FBa0I7SUFDckIsS0FBSyxDQUFTO0lBQ2QsTUFBTSxHQUFHLEtBQUssQ0FBQztJQUVmLFlBQVksYUFBa0IsRUFBRSxVQUF3QixFQUFFO1FBQ3hELEtBQUssQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUNmLElBQUksT0FBTyxhQUFhLEtBQUssVUFBVSxFQUFFLENBQUM7WUFDeEMsSUFBSSxPQUFPLENBQUMsS0FBSyxFQUFFLENBQUM7Z0JBQ2xCLElBQUksQ0FBQyxNQUFNLEdBQUcsSUFBSSxDQUFDO2dCQUNuQixJQUFJLENBQUMsR0FBRyxHQUFHLEtBQUssQ0FBQyxZQUFZLENBQUMsYUFBa0MsQ0FBQyxDQUFDLENBQUMsd0NBQXdDO1lBQzdHLENBQUM7aUJBQU0sQ0FBQztnQkFDTixJQUFJLENBQUMsR0FBRyx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FDO0lBQ3pDLENBQUM7SUFDRCxPQUFPLENBQUMsR0FBVztRQUNqQixPQUFPLElBQUksQ0FBQyxZQUFZLENBQUMsU0FBUyxFQUFFLEdBQUcsQ0FBQyxDQUFDO0lBQzNDLENBQUM7SUFDRCxLQUFLLENBQUMsR0FBVztRQUNmLE9BQU8sSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPLEVBQUUsR0FBRyxDQUFDLENBQUM7SUFDekMsQ0FBQztDQUNGO0FBRUQsOEJBQThCO0FBQzlCLE1BQU0sQ0FBQyxNQUFNLFVBQVUsR0FBeUUsSUFBSSxLQUFLLENBQUMsU0FBUyxFQUFFO0lBQ25ILEtBQUssQ0FBQyxNQUFNLEVBQUUsQ0FBQyxFQUFFLGFBQWE7UUFDNUIsT0FBTyxJQUFJLE1BQU0sQ0FBQyxhQUFhLENBQUMsQ0FBQyxDQUFDLEVBQUUsYUFBYSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFDeEQsQ0FBQztDQUNGLENBQVEsQ0FBQyJ9 | ||
| * Initialize a new `TestAgent`. | ||
| * | ||
| * @param {Function|Server} app | ||
| * @param {Object} options | ||
| */ | ||
| var TestAgent = class extends agent { | ||
| app; | ||
| _host; | ||
| #http2 = false; | ||
| constructor(appOrListener, options = {}) { | ||
| super(options); | ||
| if (typeof appOrListener === "function") if (options.http2) { | ||
| this.#http2 = true; | ||
| this.app = http2.createServer(appOrListener); | ||
| } else this.app = http.createServer(appOrListener); | ||
| else this.app = appOrListener; | ||
| } | ||
| host(host) { | ||
| this._host = host; | ||
| return this; | ||
| } | ||
| _testRequest(method, url) { | ||
| const req = new Test(this.app, method.toUpperCase(), url); | ||
| if (this.#http2) req.http2(); | ||
| if (this._host) req.set("host", this._host); | ||
| const that = this; | ||
| req.on("response", that._saveCookies.bind(this)); | ||
| req.on("redirect", that._saveCookies.bind(this)); | ||
| req.on("redirect", that._attachCookies.bind(this, req)); | ||
| that._setDefaults(req); | ||
| that._attachCookies(req); | ||
| return req; | ||
| } | ||
| delete(url) { | ||
| return this._testRequest("delete", url); | ||
| } | ||
| del(url) { | ||
| return this._testRequest("delete", url); | ||
| } | ||
| get(url) { | ||
| return this._testRequest("get", url); | ||
| } | ||
| head(url) { | ||
| return this._testRequest("head", url); | ||
| } | ||
| put(url) { | ||
| return this._testRequest("put", url); | ||
| } | ||
| post(url) { | ||
| return this._testRequest("post", url); | ||
| } | ||
| patch(url) { | ||
| return this._testRequest("patch", url); | ||
| } | ||
| options(url) { | ||
| return this._testRequest("options", url); | ||
| } | ||
| trace(url) { | ||
| return this._testRequest("trace", url); | ||
| } | ||
| }; | ||
| const proxyAgent = new Proxy(TestAgent, { apply(target, _, argumentsList) { | ||
| return new target(argumentsList[0], argumentsList[1]); | ||
| } }); | ||
| //#endregion | ||
| export { TestAgent, proxyAgent }; |
@@ -1,5 +0,8 @@ | ||
| export declare class AssertError extends Error { | ||
| expected: any; | ||
| actual: any; | ||
| constructor(message: string, expected: any, actual: any, options?: ErrorOptions); | ||
| //#region src/error/AssertError.d.ts | ||
| declare class AssertError extends Error { | ||
| expected: any; | ||
| actual: any; | ||
| constructor(message: string, expected: any, actual: any, options?: ErrorOptions); | ||
| } | ||
| //#endregion | ||
| export { AssertError }; |
@@ -1,12 +0,15 @@ | ||
| export class AssertError extends Error { | ||
| expected; | ||
| actual; | ||
| constructor(message, expected, actual, options) { | ||
| super(message, options); | ||
| this.name = this.constructor.name; | ||
| this.expected = expected; | ||
| this.actual = actual; | ||
| Error.captureStackTrace(this, this.constructor); | ||
| } | ||
| } | ||
| //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQXNzZXJ0RXJyb3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvZXJyb3IvQXNzZXJ0RXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxPQUFPLFdBQVksU0FBUSxLQUFLO0lBQ3BDLFFBQVEsQ0FBTTtJQUNkLE1BQU0sQ0FBTTtJQUVaLFlBQVksT0FBZSxFQUFFLFFBQWEsRUFBRSxNQUFXLEVBQUUsT0FBc0I7UUFDN0UsS0FBSyxDQUFDLE9BQU8sRUFBRSxPQUFPLENBQUMsQ0FBQztRQUN4QixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQyxXQUFXLENBQUMsSUFBSSxDQUFDO1FBQ2xDLElBQUksQ0FBQyxRQUFRLEdBQUcsUUFBUSxDQUFDO1FBQ3pCLElBQUksQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFDO1FBQ3JCLEtBQUssQ0FBQyxpQkFBaUIsQ0FBQyxJQUFJLEVBQUUsSUFBSSxDQUFDLFdBQVcsQ0FBQyxDQUFDO0lBQ2xELENBQUM7Q0FDRiJ9 | ||
| //#region src/error/AssertError.ts | ||
| var AssertError = class extends Error { | ||
| expected; | ||
| actual; | ||
| constructor(message, expected, actual, options) { | ||
| super(message, options); | ||
| this.name = this.constructor.name; | ||
| this.expected = expected; | ||
| this.actual = actual; | ||
| Error.captureStackTrace(this, this.constructor); | ||
| } | ||
| }; | ||
| //#endregion | ||
| export { AssertError }; |
+14
-11
@@ -1,14 +0,17 @@ | ||
| import { TestAgent, proxyAgent } from './agent.ts'; | ||
| import { Request, type RequestOptions } from './request.ts'; | ||
| import type { App, AgentOptions } from './types.ts'; | ||
| import { AssertFunction, CallbackFunction, ExpectHeader, ResponseError, Test, TestApplication } from "./test.js"; | ||
| import { AgentOptions, App } from "./types.js"; | ||
| import { TestAgent, proxyAgent } from "./agent.js"; | ||
| import { Request, RequestOptions } from "./request.js"; | ||
| //#region src/index.d.ts | ||
| /** | ||
| * Test against the given `app`, | ||
| * returning a new `Test`. | ||
| */ | ||
| export declare function request(app: App, options?: RequestOptions): Request; | ||
| export { Request, type RequestOptions, TestAgent, proxyAgent as agent, }; | ||
| export * from './test.ts'; | ||
| * Test against the given `app`, | ||
| * returning a new `Test`. | ||
| */ | ||
| declare function request(app: App, options?: RequestOptions): Request; | ||
| declare const _default: ((app: App, options?: RequestOptions) => Request) & { | ||
| agent: (app: App, options?: AgentOptions) => TestAgent; | ||
| agent: (app: App, options?: AgentOptions) => TestAgent; | ||
| }; | ||
| export default _default; | ||
| //#endregion | ||
| export { AssertFunction, CallbackFunction, ExpectHeader, Request, type RequestOptions, ResponseError, Test, TestAgent, TestApplication, proxyAgent as agent, _default as default, request }; |
+19
-25
@@ -0,30 +1,24 @@ | ||
| import { Test } from "./test.js"; | ||
| import { TestAgent, proxyAgent } from "./agent.js"; | ||
| import { Request } from "./request.js"; | ||
| //#region src/index.ts | ||
| /** | ||
| * Test against the given `app`, | ||
| * returning a new `Test`. | ||
| */ | ||
| export function request(app, options = {}) { | ||
| return new Request(app, options); | ||
| * Test against the given `app`, | ||
| * returning a new `Test`. | ||
| */ | ||
| function request(app, options = {}) { | ||
| return new Request(app, options); | ||
| } | ||
| export { Request, TestAgent, | ||
| // import { agent } from '@eggjs/supertest'; | ||
| // agent() | ||
| proxyAgent as agent, }; | ||
| export * from "./test.js"; | ||
| // import request from '@eggjs/supertest'; | ||
| // request() | ||
| export default new Proxy(request, { | ||
| apply(target, _, argumentsList) { | ||
| return target(argumentsList[0], argumentsList[1]); | ||
| }, | ||
| get(target, property, receiver) { | ||
| // import request from '@eggjs/supertest'; | ||
| // request.agent() | ||
| if (property === 'agent') { | ||
| return proxyAgent; | ||
| } | ||
| return Reflect.get(target, property, receiver); | ||
| }, | ||
| var src_default = new Proxy(request, { | ||
| apply(target, _, argumentsList) { | ||
| return target(argumentsList[0], argumentsList[1]); | ||
| }, | ||
| get(target, property, receiver) { | ||
| if (property === "agent") return proxyAgent; | ||
| return Reflect.get(target, property, receiver); | ||
| } | ||
| }); | ||
| //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZ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estAgent, proxyAgent as agent, src_default as default, request }; |
+23
-19
@@ -1,21 +0,25 @@ | ||
| import type { Server } from 'node:net'; | ||
| import { Test } from './test.ts'; | ||
| import type { App } from './types.ts'; | ||
| export interface RequestOptions { | ||
| http2?: boolean; | ||
| import { Test } from "./test.js"; | ||
| import { App } from "./types.js"; | ||
| import { Server } from "node:net"; | ||
| //#region src/request.d.ts | ||
| interface RequestOptions { | ||
| http2?: boolean; | ||
| } | ||
| export declare class Request { | ||
| #private; | ||
| app: string | Server; | ||
| constructor(appOrListener: App, options?: RequestOptions); | ||
| protected _testRequest(method: string, url: string): Test; | ||
| delete(url: string): Test; | ||
| del(url: string): Test; | ||
| get(url: string): Test; | ||
| head(url: string): Test; | ||
| put(url: string): Test; | ||
| post(url: string): Test; | ||
| patch(url: string): Test; | ||
| options(url: string): Test; | ||
| trace(url: string): Test; | ||
| declare class Request { | ||
| #private; | ||
| app: string | Server; | ||
| constructor(appOrListener: App, options?: RequestOptions); | ||
| protected _testRequest(method: string, url: string): Test; | ||
| delete(url: string): Test; | ||
| del(url: string): Test; | ||
| get(url: string): Test; | ||
| head(url: string): Test; | ||
| put(url: string): Test; | ||
| post(url: string): Test; | ||
| patch(url: string): Test; | ||
| options(url: string): Test; | ||
| trace(url: string): Test; | ||
| } | ||
| //#endregion | ||
| export { Request, RequestOptions }; |
+50
-55
@@ -1,56 +0,51 @@ | ||
| import http from 'node:http'; | ||
| import http2 from 'node:http2'; | ||
| import { Test } from "./test.js"; | ||
| export class Request { | ||
| app; | ||
| #http2 = false; | ||
| constructor(appOrListener, options = {}) { | ||
| if (typeof appOrListener === 'function') { | ||
| if (options.http2) { | ||
| this.#http2 = true; | ||
| this.app = http2.createServer(appOrListener); // eslint-disable-line no-param-reassign | ||
| } | ||
| else { | ||
| this.app = http.createServer(appOrListener); // eslint-disable-line no-param-reassign | ||
| } | ||
| } | ||
| else { | ||
| this.app = appOrListener; | ||
| } | ||
| } | ||
| _testRequest(method, url) { | ||
| const req = new Test(this.app, method.toUpperCase(), url); | ||
| if (this.#http2) { | ||
| req.http2(); | ||
| } | ||
| return req; | ||
| } | ||
| delete(url) { | ||
| return this._testRequest('delete', url); | ||
| } | ||
| del(url) { | ||
| return this._testRequest('delete', url); | ||
| } | ||
| get(url) { | ||
| return this._testRequest('get', url); | ||
| } | ||
| head(url) { | ||
| return this._testRequest('head', url); | ||
| } | ||
| put(url) { | ||
| return this._testRequest('put', url); | ||
| } | ||
| post(url) { | ||
| return this._testRequest('post', url); | ||
| } | ||
| patch(url) { | ||
| return this._testRequest('patch', url); | ||
| } | ||
| options(url) { | ||
| return this._testRequest('options', url); | ||
| } | ||
| trace(url) { | ||
| return this._testRequest('trace', url); | ||
| } | ||
| } | ||
| //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVxdWVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9yZXF1ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sSUFBSSxNQUFNLFdBQVcsQ0FBQztBQUM3QixPQUFPLEtBQUssTUFBTSxZQUFZLENBQUM7QUFHL0IsT0FBTyxFQUFFLElBQUksRUFBRSxNQUFNLFdBQVcsQ0FBQztBQU9qQyxNQUFNLE9BQU8sT0FBTztJQUNsQixHQUFHLENBQWtCO0lBQ3JCLE1BQU0sR0FBRyxLQUFLLENBQUM7SUFFZixZQUFZLGFBQWtCLEVBQUUsVUFBMEIsRUFBRTtRQUMxRCxJQUFJLE9BQU8sYUFBYSxLQUFLLFVBQVUsRUFBRSxDQUFDO1lBQ3hDLElBQUksT0FBTyxDQUFDLEtBQUssRUFBRSxDQUFDO2dCQUNsQixJQUFJLENBQUMsTUFBTSxHQUFHLElBQUksQ0FBQztnQkFDbkIsSUFBSSxDQUFDLEdBQUcsR0FBRyxLQUFLLENBQUMsWUFBWSxDQUFDLGFBQWtDLENBQUMsQ0FBQyxDQUFDL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dBQVc7UUFDYixPQUFPLElBQUksQ0FBQyxZQUFZLENBQUMsS0FBSyxFQUFFLEdBQUcsQ0FBQyxDQUFDO0lBQ3ZDLENBQUM7SUFDRCxJQUFJLENBQUMsR0FBVztRQUNkLE9BQU8sSUFBSSxDQUFDLFlBQVksQ0FBQyxNQUFNLEVBQUUsR0FBRyxDQUFDLENBQUM7SUFDeEMsQ0FBQztJQUNELEtBQUssQ0FBQyxHQUFXO1FBQ2YsT0FBTyxJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxHQUFHLENBQUMsQ0FBQztJQUN6QyxDQUFDO0lBQ0QsT0FBTyxDQUFDLEdBQVc7UUFDakIsT0FBTyxJQUFJLENBQUMsWUFBWSxDQUFDLFNBQVMsRUFBRSxHQUFHLENBQUMsQ0FBQztJQUMzQyxDQUFDO0lBQ0QsS0FBSyxDQUFDLEdBQVc7UUFDZixPQUFPLElBQUksQ0FBQyxZQUFZLENBQUMsT0FBTyxFQUFFLEdBQUcsQ0FBQyxDQUFDO0lBQ3pDLENBQUM7Q0FDRiJ9 | ||
| import http from "node:http"; | ||
| import http2 from "node:http2"; | ||
| //#region src/request.ts | ||
| var Request = class { | ||
| app; | ||
| #http2 = false; | ||
| constructor(appOrListener, options = {}) { | ||
| if (typeof appOrListener === "function") if (options.http2) { | ||
| this.#http2 = true; | ||
| this.app = http2.createServer(appOrListener); | ||
| } else this.app = http.createServer(appOrListener); | ||
| else this.app = appOrListener; | ||
| } | ||
| _testRequest(method, url) { | ||
| const req = new Test(this.app, method.toUpperCase(), url); | ||
| if (this.#http2) req.http2(); | ||
| return req; | ||
| } | ||
| delete(url) { | ||
| return this._testRequest("delete", url); | ||
| } | ||
| del(url) { | ||
| return this._testRequest("delete", url); | ||
| } | ||
| get(url) { | ||
| return this._testRequest("get", url); | ||
| } | ||
| head(url) { | ||
| return this._testRequest("head", url); | ||
| } | ||
| put(url) { | ||
| return this._testRequest("put", url); | ||
| } | ||
| post(url) { | ||
| return this._testRequest("post", url); | ||
| } | ||
| patch(url) { | ||
| return this._testRequest("patch", url); | ||
| } | ||
| options(url) { | ||
| return this._testRequest("options", url); | ||
| } | ||
| trace(url) { | ||
| return this._testRequest("trace", url); | ||
| } | ||
| }; | ||
| //#endregion | ||
| export { Request }; |
+97
-93
@@ -1,96 +0,100 @@ | ||
| import type { Server } from 'node:net'; | ||
| import { Request, type Response } from 'superagent'; | ||
| import { AssertError } from './error/AssertError.ts'; | ||
| export type TestApplication = Server | string; | ||
| export type AssertFunction = (res: Response) => AssertError | void; | ||
| export type CallbackFunction = (err: AssertError | Error | null, res: Response) => void; | ||
| export type ResponseError = Error & { | ||
| syscall?: string; | ||
| code?: string; | ||
| status?: number; | ||
| import { AssertError } from "./error/AssertError.js"; | ||
| import { Request, Response } from "superagent"; | ||
| import { Server } from "node:net"; | ||
| //#region src/test.d.ts | ||
| type TestApplication = Server | string; | ||
| type AssertFunction = (res: Response) => AssertError | void; | ||
| type CallbackFunction = (err: AssertError | Error | null, res: Response) => void; | ||
| type ResponseError = Error & { | ||
| syscall?: string; | ||
| code?: string; | ||
| status?: number; | ||
| }; | ||
| export interface ExpectHeader { | ||
| name: string; | ||
| value: string | number | RegExp; | ||
| interface ExpectHeader { | ||
| name: string; | ||
| value: string | number | RegExp; | ||
| } | ||
| export declare class Test extends Request { | ||
| app: TestApplication; | ||
| _server: Server; | ||
| _asserts: AssertFunction[]; | ||
| /** | ||
| * Initialize a new `Test` with the given `app`, | ||
| * request `method` and `path`. | ||
| */ | ||
| constructor(app: TestApplication, method: string, path: string); | ||
| /** | ||
| * Returns a URL, extracted from a server. | ||
| * | ||
| * @return {String} URL address | ||
| * @private | ||
| */ | ||
| protected serverAddress(app: Server, path: string): string; | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * ```js | ||
| * .expect(200) | ||
| * .expect(200, fn) | ||
| * .expect(200, body) | ||
| * .expect('Some body') | ||
| * .expect('Some body', fn) | ||
| * .expect(['json array body', { key: 'val' }]) | ||
| * .expect('Content-Type', 'application/json') | ||
| * .expect('Content-Type', 'application/json', fn) | ||
| * .expect(fn) | ||
| * .expect([200, 404]) | ||
| * ``` | ||
| * | ||
| * @return {Test} The current Test instance for chaining. | ||
| */ | ||
| expect(a: number | string | RegExp | object | AssertFunction, b?: string | number | RegExp | CallbackFunction, c?: CallbackFunction): Test; | ||
| /** | ||
| * UnExpectations: | ||
| * | ||
| * .unexpectHeader('Content-Type') | ||
| * .unexpectHeader('Content-Type', fn) | ||
| */ | ||
| unexpectHeader(name: string, fn?: CallbackFunction): this; | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * .expectHeader('Content-Type') | ||
| * .expectHeader('Content-Type', fn) | ||
| */ | ||
| expectHeader(name: string, fn?: CallbackFunction): this; | ||
| _unexpectHeader(name: string, res: Response): AssertError | void; | ||
| _expectHeader(name: string, res: Response): AssertError | void; | ||
| /** | ||
| * Defer invoking superagent's `.end()` until | ||
| * the server is listening. | ||
| */ | ||
| end(fn: CallbackFunction): this; | ||
| /** | ||
| * Perform assertions and invoke `fn(err, res)`. | ||
| */ | ||
| assert(resError: ResponseError | null, res: Response, fn: CallbackFunction): void; | ||
| /** | ||
| * Perform assertions on a response body and return an Error upon failure. | ||
| */ | ||
| _assertBody(body: RegExp | string | number | object | null | undefined, res: Response): AssertError | void; | ||
| /** | ||
| * Perform assertions on a response header and return an Error upon failure. | ||
| */ | ||
| _assertHeader(header: ExpectHeader, res: Response): AssertError | void; | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatus(status: number, res: Response): AssertError | void; | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatusArray(statusArray: number[], res: Response): AssertError | void; | ||
| /** | ||
| * Performs an assertion by calling a function and return an Error upon failure. | ||
| */ | ||
| _assertFunction(fn: AssertFunction, res: Response): Error | undefined; | ||
| declare class Test extends Request { | ||
| app: TestApplication; | ||
| _server: Server; | ||
| _asserts: AssertFunction[]; | ||
| /** | ||
| * Initialize a new `Test` with the given `app`, | ||
| * request `method` and `path`. | ||
| */ | ||
| constructor(app: TestApplication, method: string, path: string); | ||
| /** | ||
| * Returns a URL, extracted from a server. | ||
| * | ||
| * @return {String} URL address | ||
| * @private | ||
| */ | ||
| protected serverAddress(app: Server, path: string): string; | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * ```js | ||
| * .expect(200) | ||
| * .expect(200, fn) | ||
| * .expect(200, body) | ||
| * .expect('Some body') | ||
| * .expect('Some body', fn) | ||
| * .expect(['json array body', { key: 'val' }]) | ||
| * .expect('Content-Type', 'application/json') | ||
| * .expect('Content-Type', 'application/json', fn) | ||
| * .expect(fn) | ||
| * .expect([200, 404]) | ||
| * ``` | ||
| * | ||
| * @return {Test} The current Test instance for chaining. | ||
| */ | ||
| expect(a: number | string | RegExp | object | AssertFunction, b?: string | number | RegExp | CallbackFunction, c?: CallbackFunction): Test; | ||
| /** | ||
| * UnExpectations: | ||
| * | ||
| * .unexpectHeader('Content-Type') | ||
| * .unexpectHeader('Content-Type', fn) | ||
| */ | ||
| unexpectHeader(name: string, fn?: CallbackFunction): this; | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * .expectHeader('Content-Type') | ||
| * .expectHeader('Content-Type', fn) | ||
| */ | ||
| expectHeader(name: string, fn?: CallbackFunction): this; | ||
| _unexpectHeader(name: string, res: Response): AssertError | void; | ||
| _expectHeader(name: string, res: Response): AssertError | void; | ||
| /** | ||
| * Defer invoking superagent's `.end()` until | ||
| * the server is listening. | ||
| */ | ||
| end(fn: CallbackFunction): this; | ||
| /** | ||
| * Perform assertions and invoke `fn(err, res)`. | ||
| */ | ||
| assert(resError: ResponseError | null, res: Response, fn: CallbackFunction): void; | ||
| /** | ||
| * Perform assertions on a response body and return an Error upon failure. | ||
| */ | ||
| _assertBody(body: RegExp | string | number | object | null | undefined, res: Response): AssertError | void; | ||
| /** | ||
| * Perform assertions on a response header and return an Error upon failure. | ||
| */ | ||
| _assertHeader(header: ExpectHeader, res: Response): AssertError | void; | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatus(status: number, res: Response): AssertError | void; | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatusArray(statusArray: number[], res: Response): AssertError | void; | ||
| /** | ||
| * Performs an assertion by calling a function and return an Error upon failure. | ||
| */ | ||
| _assertFunction(fn: AssertFunction, res: Response): Error | undefined; | ||
| } | ||
| //#endregion | ||
| export { AssertFunction, CallbackFunction, ExpectHeader, ResponseError, Test, TestApplication }; |
+232
-311
@@ -1,315 +0,236 @@ | ||
| import { deepStrictEqual } from 'node:assert'; | ||
| import { STATUS_CODES } from 'node:http'; | ||
| import { Server as HttpsServer } from 'node:tls'; | ||
| import { inspect } from 'node:util'; | ||
| import { Request } from 'superagent'; | ||
| import { AssertError } from "./error/AssertError.js"; | ||
| export class Test extends Request { | ||
| app; | ||
| _server; | ||
| _asserts = []; | ||
| /** | ||
| * Initialize a new `Test` with the given `app`, | ||
| * request `method` and `path`. | ||
| */ | ||
| constructor(app, method, path) { | ||
| super(method.toUpperCase(), path); | ||
| this.redirects(0); | ||
| this.buffer(); | ||
| this.app = app; | ||
| this.url = typeof app === 'string' ? app + path : this.serverAddress(app, path); | ||
| } | ||
| /** | ||
| * Returns a URL, extracted from a server. | ||
| * | ||
| * @return {String} URL address | ||
| * @private | ||
| */ | ||
| serverAddress(app, path) { | ||
| const addr = app.address(); | ||
| if (!addr) { | ||
| this._server = app.listen(0); | ||
| } | ||
| const port = app.address().port; | ||
| const protocol = app instanceof HttpsServer || this._server instanceof HttpsServer ? 'https' : 'http'; | ||
| return `${protocol}://127.0.0.1:${port}${path}`; | ||
| } | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * ```js | ||
| * .expect(200) | ||
| * .expect(200, fn) | ||
| * .expect(200, body) | ||
| * .expect('Some body') | ||
| * .expect('Some body', fn) | ||
| * .expect(['json array body', { key: 'val' }]) | ||
| * .expect('Content-Type', 'application/json') | ||
| * .expect('Content-Type', 'application/json', fn) | ||
| * .expect(fn) | ||
| * .expect([200, 404]) | ||
| * ``` | ||
| * | ||
| * @return {Test} The current Test instance for chaining. | ||
| */ | ||
| expect(a, b, c) { | ||
| // callback | ||
| if (typeof a === 'function') { | ||
| // .expect(fn) | ||
| this._asserts.push(wrapAssertFn(a)); | ||
| return this; | ||
| } | ||
| if (typeof b === 'function') { | ||
| // .expect('Some body', fn) | ||
| this.end(b); | ||
| } | ||
| if (typeof c === 'function') { | ||
| // .expect('Content-Type', 'application/json', fn) | ||
| this.end(c); | ||
| } | ||
| // status | ||
| if (typeof a === 'number') { | ||
| this._asserts.push(wrapAssertFn(this._assertStatus.bind(this, a))); | ||
| // body | ||
| if (typeof b !== 'function' && arguments.length > 1) { | ||
| // .expect(200, 'body') | ||
| // .expect(200, null) | ||
| // .expect(200, 9999999) | ||
| this._asserts.push(wrapAssertFn(this._assertBody.bind(this, b))); | ||
| } | ||
| return this; | ||
| } | ||
| // multiple statuses | ||
| if (Array.isArray(a) && a.length > 0 && a.every((val) => typeof val === 'number')) { | ||
| // .expect([200, 300]) | ||
| this._asserts.push(wrapAssertFn(this._assertStatusArray.bind(this, a))); | ||
| return this; | ||
| } | ||
| // header field | ||
| if (typeof b === 'string' || typeof b === 'number' || b instanceof RegExp) { | ||
| // .expect('Content-Type', 'application/json') | ||
| // .expect('Content-Type', /json/) | ||
| this._asserts.push(wrapAssertFn(this._assertHeader.bind(this, { name: String(a), value: b }))); | ||
| return this; | ||
| } | ||
| // body | ||
| // .expect('body') | ||
| // .expect(['json array body', { key: 'val' }]) | ||
| // .expect(/foo/) | ||
| this._asserts.push(wrapAssertFn(this._assertBody.bind(this, a))); | ||
| return this; | ||
| } | ||
| /** | ||
| * UnExpectations: | ||
| * | ||
| * .unexpectHeader('Content-Type') | ||
| * .unexpectHeader('Content-Type', fn) | ||
| */ | ||
| unexpectHeader(name, fn) { | ||
| if (typeof fn === 'function') { | ||
| this.end(fn); | ||
| } | ||
| // header | ||
| if (typeof name === 'string') { | ||
| this._asserts.push(this._unexpectHeader.bind(this, name)); | ||
| } | ||
| return this; | ||
| } | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * .expectHeader('Content-Type') | ||
| * .expectHeader('Content-Type', fn) | ||
| */ | ||
| expectHeader(name, fn) { | ||
| if (typeof fn === 'function') { | ||
| this.end(fn); | ||
| } | ||
| // header | ||
| if (typeof name === 'string') { | ||
| this._asserts.push(this._expectHeader.bind(this, name)); | ||
| } | ||
| return this; | ||
| } | ||
| _unexpectHeader(name, res) { | ||
| const actual = res.headers[name.toLowerCase()]; | ||
| if (actual) { | ||
| return new AssertError('unexpected "' + name + '" header field, got "' + actual + '"', name, actual); | ||
| } | ||
| } | ||
| _expectHeader(name, res) { | ||
| const actual = res.headers[name.toLowerCase()]; | ||
| if (!actual) { | ||
| return new AssertError('expected "' + name + '" header field', name, actual); | ||
| } | ||
| } | ||
| /** | ||
| * Defer invoking superagent's `.end()` until | ||
| * the server is listening. | ||
| */ | ||
| end(fn) { | ||
| const server = this._server; | ||
| super.end((err, res) => { | ||
| const localAssert = () => { | ||
| this.assert(err, res, fn); | ||
| }; | ||
| if (server && '_handle' in server && server._handle) { | ||
| return server.close(localAssert); | ||
| } | ||
| localAssert(); | ||
| }); | ||
| return this; | ||
| } | ||
| /** | ||
| * Perform assertions and invoke `fn(err, res)`. | ||
| */ | ||
| assert(resError, res, fn) { | ||
| let errorObj; | ||
| // check for unexpected network errors or server not running/reachable errors | ||
| // when there is no response and superagent sends back a System Error | ||
| // do not check further for other asserts, if any, in such case | ||
| // https://nodejs.org/api/errors.html#errors_common_system_errors | ||
| const sysErrors = { | ||
| ECONNREFUSED: 'Connection refused', | ||
| ECONNRESET: 'Connection reset by peer', | ||
| EPIPE: 'Broken pipe', | ||
| ETIMEDOUT: 'Operation timed out', | ||
| }; | ||
| if (!res && resError) { | ||
| if (resError instanceof Error && resError.syscall === 'connect' && resError.code && sysErrors[resError.code]) { | ||
| errorObj = new Error(resError.code + ': ' + sysErrors[resError.code]); | ||
| } | ||
| else { | ||
| errorObj = resError; | ||
| } | ||
| } | ||
| // asserts | ||
| for (let i = 0; i < this._asserts.length && !errorObj; i += 1) { | ||
| errorObj = this._assertFunction(this._asserts[i], res); | ||
| } | ||
| // set unexpected superagent error if no other error has occurred. | ||
| if (!errorObj && resError instanceof Error && (!res || resError.status !== res.status)) { | ||
| errorObj = resError; | ||
| } | ||
| if (!fn) { | ||
| console.warn('[@eggjs/supertest] no callback function provided, fn: %s', typeof fn); | ||
| return; | ||
| } | ||
| fn.call(this, errorObj || null, res); | ||
| } | ||
| /** | ||
| * Perform assertions on a response body and return an Error upon failure. | ||
| */ | ||
| _assertBody(body, res) { | ||
| const isRegexp = body instanceof RegExp; | ||
| // parsed | ||
| if (typeof body === 'object' && !isRegexp) { | ||
| try { | ||
| deepStrictEqual(body, res.body); | ||
| } | ||
| catch (err) { | ||
| const a = inspect(body); | ||
| const b = inspect(res.body); | ||
| return new AssertError('expected ' + a + ' response body, got ' + b, body, res.body, { cause: err }); | ||
| } | ||
| } | ||
| else if (body !== res.text) { | ||
| // string | ||
| const a = inspect(body); | ||
| const b = inspect(res.text); | ||
| // regexp | ||
| if (isRegexp) { | ||
| if (!body.test(res.text)) { | ||
| return new AssertError('expected body ' + b + ' to match ' + body, body, res.body); | ||
| } | ||
| } | ||
| else { | ||
| return new AssertError('expected ' + a + ' response body, got ' + b, body, res.body); | ||
| } | ||
| } | ||
| } | ||
| /** | ||
| * Perform assertions on a response header and return an Error upon failure. | ||
| */ | ||
| _assertHeader(header, res) { | ||
| const field = header.name; | ||
| const actual = res.header[field.toLowerCase()]; | ||
| const fieldExpected = header.value; | ||
| if (typeof actual === 'undefined') { | ||
| return new AssertError('expected "' + field + '" header field', header, actual); | ||
| } | ||
| // This check handles header values that may be a String or single element Array | ||
| if ((Array.isArray(actual) && actual.toString() === fieldExpected) || fieldExpected === actual) { | ||
| return; | ||
| } | ||
| if (fieldExpected instanceof RegExp) { | ||
| if (!fieldExpected.test(actual)) { | ||
| return new AssertError('expected "' + field + '" matching ' + fieldExpected + ', got "' + actual + '"', header, actual); | ||
| } | ||
| } | ||
| else { | ||
| return new AssertError('expected "' + field + '" of "' + fieldExpected + '", got "' + actual + '"', header, actual); | ||
| } | ||
| } | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatus(status, res) { | ||
| if (res.status !== status) { | ||
| const a = STATUS_CODES[status]; | ||
| const b = STATUS_CODES[res.status]; | ||
| return new AssertError('expected ' + status + ' "' + a + '", got ' + res.status + ' "' + b + '"', status, res.status); | ||
| } | ||
| } | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatusArray(statusArray, res) { | ||
| if (!statusArray.includes(res.status)) { | ||
| const b = STATUS_CODES[res.status]; | ||
| const expectedList = statusArray.join(', '); | ||
| return new AssertError('expected one of "' + expectedList + '", got ' + res.status + ' "' + b + '"', statusArray, res.status); | ||
| } | ||
| } | ||
| /** | ||
| * Performs an assertion by calling a function and return an Error upon failure. | ||
| */ | ||
| _assertFunction(fn, res) { | ||
| let err; | ||
| try { | ||
| err = fn(res); | ||
| } | ||
| catch (e) { | ||
| err = e; | ||
| } | ||
| if (err instanceof Error) { | ||
| return err; | ||
| } | ||
| } | ||
| } | ||
| import { STATUS_CODES } from "node:http"; | ||
| import { Request } from "superagent"; | ||
| import { deepStrictEqual } from "node:assert"; | ||
| import { Server } from "node:tls"; | ||
| import { inspect } from "node:util"; | ||
| //#region src/test.ts | ||
| var Test = class extends Request { | ||
| app; | ||
| _server; | ||
| _asserts = []; | ||
| /** | ||
| * Initialize a new `Test` with the given `app`, | ||
| * request `method` and `path`. | ||
| */ | ||
| constructor(app, method, path) { | ||
| super(method.toUpperCase(), path); | ||
| this.redirects(0); | ||
| this.buffer(); | ||
| this.app = app; | ||
| this.url = typeof app === "string" ? app + path : this.serverAddress(app, path); | ||
| } | ||
| /** | ||
| * Returns a URL, extracted from a server. | ||
| * | ||
| * @return {String} URL address | ||
| * @private | ||
| */ | ||
| serverAddress(app, path) { | ||
| if (!app.address()) this._server = app.listen(0); | ||
| const port = app.address().port; | ||
| return `${app instanceof Server || this._server instanceof Server ? "https" : "http"}://127.0.0.1:${port}${path}`; | ||
| } | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * ```js | ||
| * .expect(200) | ||
| * .expect(200, fn) | ||
| * .expect(200, body) | ||
| * .expect('Some body') | ||
| * .expect('Some body', fn) | ||
| * .expect(['json array body', { key: 'val' }]) | ||
| * .expect('Content-Type', 'application/json') | ||
| * .expect('Content-Type', 'application/json', fn) | ||
| * .expect(fn) | ||
| * .expect([200, 404]) | ||
| * ``` | ||
| * | ||
| * @return {Test} The current Test instance for chaining. | ||
| */ | ||
| expect(a, b, c) { | ||
| if (typeof a === "function") { | ||
| this._asserts.push(wrapAssertFn(a)); | ||
| return this; | ||
| } | ||
| if (typeof b === "function") this.end(b); | ||
| if (typeof c === "function") this.end(c); | ||
| if (typeof a === "number") { | ||
| this._asserts.push(wrapAssertFn(this._assertStatus.bind(this, a))); | ||
| if (typeof b !== "function" && arguments.length > 1) this._asserts.push(wrapAssertFn(this._assertBody.bind(this, b))); | ||
| return this; | ||
| } | ||
| if (Array.isArray(a) && a.length > 0 && a.every((val) => typeof val === "number")) { | ||
| this._asserts.push(wrapAssertFn(this._assertStatusArray.bind(this, a))); | ||
| return this; | ||
| } | ||
| if (typeof b === "string" || typeof b === "number" || b instanceof RegExp) { | ||
| this._asserts.push(wrapAssertFn(this._assertHeader.bind(this, { | ||
| name: String(a), | ||
| value: b | ||
| }))); | ||
| return this; | ||
| } | ||
| this._asserts.push(wrapAssertFn(this._assertBody.bind(this, a))); | ||
| return this; | ||
| } | ||
| /** | ||
| * UnExpectations: | ||
| * | ||
| * .unexpectHeader('Content-Type') | ||
| * .unexpectHeader('Content-Type', fn) | ||
| */ | ||
| unexpectHeader(name, fn) { | ||
| if (typeof fn === "function") this.end(fn); | ||
| if (typeof name === "string") this._asserts.push(this._unexpectHeader.bind(this, name)); | ||
| return this; | ||
| } | ||
| /** | ||
| * Expectations: | ||
| * | ||
| * .expectHeader('Content-Type') | ||
| * .expectHeader('Content-Type', fn) | ||
| */ | ||
| expectHeader(name, fn) { | ||
| if (typeof fn === "function") this.end(fn); | ||
| if (typeof name === "string") this._asserts.push(this._expectHeader.bind(this, name)); | ||
| return this; | ||
| } | ||
| _unexpectHeader(name, res) { | ||
| const actual = res.headers[name.toLowerCase()]; | ||
| if (actual) return new AssertError("unexpected \"" + name + "\" header field, got \"" + actual + "\"", name, actual); | ||
| } | ||
| _expectHeader(name, res) { | ||
| const actual = res.headers[name.toLowerCase()]; | ||
| if (!actual) return new AssertError("expected \"" + name + "\" header field", name, actual); | ||
| } | ||
| /** | ||
| * Defer invoking superagent's `.end()` until | ||
| * the server is listening. | ||
| */ | ||
| end(fn) { | ||
| const server = this._server; | ||
| super.end((err, res) => { | ||
| const localAssert = () => { | ||
| this.assert(err, res, fn); | ||
| }; | ||
| if (server && "_handle" in server && server._handle) return server.close(localAssert); | ||
| localAssert(); | ||
| }); | ||
| return this; | ||
| } | ||
| /** | ||
| * Perform assertions and invoke `fn(err, res)`. | ||
| */ | ||
| assert(resError, res, fn) { | ||
| let errorObj; | ||
| const sysErrors = { | ||
| ECONNREFUSED: "Connection refused", | ||
| ECONNRESET: "Connection reset by peer", | ||
| EPIPE: "Broken pipe", | ||
| ETIMEDOUT: "Operation timed out" | ||
| }; | ||
| if (!res && resError) if (resError instanceof Error && resError.syscall === "connect" && resError.code && sysErrors[resError.code]) errorObj = /* @__PURE__ */ new Error(resError.code + ": " + sysErrors[resError.code]); | ||
| else errorObj = resError; | ||
| for (let i = 0; i < this._asserts.length && !errorObj; i += 1) errorObj = this._assertFunction(this._asserts[i], res); | ||
| if (!errorObj && resError instanceof Error && (!res || resError.status !== res.status)) errorObj = resError; | ||
| if (!fn) { | ||
| console.warn("[@eggjs/supertest] no callback function provided, fn: %s", typeof fn); | ||
| return; | ||
| } | ||
| fn.call(this, errorObj || null, res); | ||
| } | ||
| /** | ||
| * Perform assertions on a response body and return an Error upon failure. | ||
| */ | ||
| _assertBody(body, res) { | ||
| const isRegexp = body instanceof RegExp; | ||
| if (typeof body === "object" && !isRegexp) try { | ||
| deepStrictEqual(body, res.body); | ||
| } catch (err) { | ||
| const a = inspect(body); | ||
| const b = inspect(res.body); | ||
| return new AssertError("expected " + a + " response body, got " + b, body, res.body, { cause: err }); | ||
| } | ||
| else if (body !== res.text) { | ||
| const a = inspect(body); | ||
| const b = inspect(res.text); | ||
| if (isRegexp) { | ||
| if (!body.test(res.text)) return new AssertError("expected body " + b + " to match " + body, body, res.body); | ||
| } else return new AssertError("expected " + a + " response body, got " + b, body, res.body); | ||
| } | ||
| } | ||
| /** | ||
| * Perform assertions on a response header and return an Error upon failure. | ||
| */ | ||
| _assertHeader(header, res) { | ||
| const field = header.name; | ||
| const actual = res.header[field.toLowerCase()]; | ||
| const fieldExpected = header.value; | ||
| if (typeof actual === "undefined") return new AssertError("expected \"" + field + "\" header field", header, actual); | ||
| if (Array.isArray(actual) && actual.toString() === fieldExpected || fieldExpected === actual) return; | ||
| if (fieldExpected instanceof RegExp) { | ||
| if (!fieldExpected.test(actual)) return new AssertError("expected \"" + field + "\" matching " + fieldExpected + ", got \"" + actual + "\"", header, actual); | ||
| } else return new AssertError("expected \"" + field + "\" of \"" + fieldExpected + "\", got \"" + actual + "\"", header, actual); | ||
| } | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatus(status, res) { | ||
| if (res.status !== status) { | ||
| const a = STATUS_CODES[status]; | ||
| const b = STATUS_CODES[res.status]; | ||
| return new AssertError("expected " + status + " \"" + a + "\", got " + res.status + " \"" + b + "\"", status, res.status); | ||
| } | ||
| } | ||
| /** | ||
| * Perform assertions on the response status and return an Error upon failure. | ||
| */ | ||
| _assertStatusArray(statusArray, res) { | ||
| if (!statusArray.includes(res.status)) { | ||
| const b = STATUS_CODES[res.status]; | ||
| return new AssertError("expected one of \"" + statusArray.join(", ") + "\", got " + res.status + " \"" + b + "\"", statusArray, res.status); | ||
| } | ||
| } | ||
| /** | ||
| * Performs an assertion by calling a function and return an Error upon failure. | ||
| */ | ||
| _assertFunction(fn, res) { | ||
| let err; | ||
| try { | ||
| err = fn(res); | ||
| } catch (e) { | ||
| err = e; | ||
| } | ||
| if (err instanceof Error) return err; | ||
| } | ||
| }; | ||
| /** | ||
| * Wraps an assert function into another. | ||
| * The wrapper function edit the stack trace of any assertion error, prepending a more useful stack to it. | ||
| * | ||
| * @param {Function} assertFn | ||
| * @return {Function} wrapped assert function | ||
| */ | ||
| * Wraps an assert function into another. | ||
| * The wrapper function edit the stack trace of any assertion error, prepending a more useful stack to it. | ||
| * | ||
| * @param {Function} assertFn | ||
| * @return {Function} wrapped assert function | ||
| */ | ||
| function wrapAssertFn(assertFn) { | ||
| const savedStack = new Error().stack.split('\n').slice(3); | ||
| return (res) => { | ||
| let badStack; | ||
| let err; | ||
| try { | ||
| err = assertFn(res); | ||
| } | ||
| catch (e) { | ||
| err = e; | ||
| } | ||
| if (err instanceof Error && err.stack) { | ||
| badStack = err.stack.replace(err.message, '').split('\n').slice(1); | ||
| err.stack = [err.toString()].concat(savedStack).concat('----').concat(badStack).join('\n'); | ||
| } | ||
| return err; | ||
| }; | ||
| const savedStack = (/* @__PURE__ */ new Error()).stack.split("\n").slice(3); | ||
| return (res) => { | ||
| let badStack; | ||
| let err; | ||
| try { | ||
| err = assertFn(res); | ||
| } catch (e) { | ||
| err = e; | ||
| } | ||
| if (err instanceof Error && err.stack) { | ||
| badStack = err.stack.replace(err.message, "").split("\n").slice(1); | ||
| err.stack = [err.toString()].concat(savedStack).concat("----").concat(badStack).join("\n"); | ||
| } | ||
| return err; | ||
| }; | ||
| } | ||
| //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNv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sVUFBVSxHQUFHLElBQUksS0FBSyxFQUFFLENBQUMsS0FBTSxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFFM0QsT0FBTyxDQUFDLEdBQWEsRUFBRSxFQUFFO1FBQ3ZCLElBQUksUUFBUSxDQUFDO1FBQ2IsSUFBSSxHQUFHLENBQUM7UUFDUixJQUFJLENBQUM7WUFDSCxHQUFHLEdBQUcsUUFBUSxDQUFDLEdBQUcsQ0FBQyxDQUFDO1FBQ3RCLENBQUM7UUFBQyxPQUFPLENBQU0sRUFBRSxDQUFDO1lBQ2hCLEdBQUcsR0FBRyxDQUFDLENBQUM7UUFDVixDQUFDO1FBQ0QsSUFBSSxHQUFHLFlBQVksS0FBSyxJQUFJLEdBQUcsQ0FBQyxLQUFLLEVBQUUsQ0FBQztZQUN0QyxRQUFRLEdBQUcsR0FBRyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLE9BQU8sRUFBRSxFQUFFLENBQUMsQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUMsS0FBSyxDQUFDLENBQUMsQ0FBQyxDQUFDO1lBQ25FLEdBQUcsQ0FBQyxLQUFLLEdBQUcsQ0FBQyxHQUFHLENBQUMsUUFBUSxFQUFFLENBQUMsQ0FBQyxNQUFNLENBQUMsVUFBVSxDQUFDLENBQUMsTUFBTSxDQUFDLE1BQU0sQ0FBQyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDN0YsQ0FBQztRQUNELE9BQU8sR0FBRyxDQUFDO0lBQ2IsQ0FBQyxDQUFDO0FBQ0osQ0FBQyJ9 | ||
| //#endregion | ||
| export { Test }; |
+13
-9
@@ -1,10 +0,14 @@ | ||
| import type { RequestListener } from 'node:http'; | ||
| import type { Http2ServerRequest, Http2ServerResponse } from 'node:http2'; | ||
| import type { Server } from 'node:net'; | ||
| import type { AgentOptions as SAgentOptions } from 'superagent'; | ||
| export type H2RequestListener = (request: Http2ServerRequest, response: Http2ServerResponse) => void; | ||
| export type H1RequestListener = RequestListener; | ||
| export type App = Server | H1RequestListener | H2RequestListener | string; | ||
| export interface AgentOptions extends SAgentOptions { | ||
| http2?: boolean; | ||
| import { RequestListener } from "node:http"; | ||
| import { Http2ServerRequest, Http2ServerResponse } from "node:http2"; | ||
| import { AgentOptions } from "superagent"; | ||
| import { Server } from "node:net"; | ||
| //#region src/types.d.ts | ||
| type H2RequestListener = (request: Http2ServerRequest, response: Http2ServerResponse) => void; | ||
| type H1RequestListener = RequestListener; | ||
| type App = Server | H1RequestListener | H2RequestListener | string; | ||
| interface AgentOptions$1 extends AgentOptions { | ||
| http2?: boolean; | ||
| } | ||
| //#endregion | ||
| export { AgentOptions$1 as AgentOptions, App }; |
+20
-24
| { | ||
| "name": "@eggjs/supertest", | ||
| "version": "9.0.0-beta.36", | ||
| "description": "SuperAgent driven library for testing HTTP servers", | ||
| "version": "9.0.0-beta.35", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "type": "module", | ||
| "exports": { | ||
| ".": "./dist/index.js", | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "author": "TJ Holowaychuk", | ||
| "keywords": [ | ||
@@ -29,3 +14,5 @@ "bdd", | ||
| ], | ||
| "homepage": "https://github.com/eggjs/egg/tree/next/packages/supertest", | ||
| "license": "MIT", | ||
| "author": "TJ Holowaychuk", | ||
| "repository": { | ||
@@ -36,6 +23,16 @@ "type": "git", | ||
| }, | ||
| "homepage": "https://github.com/eggjs/egg/tree/next/packages/supertest", | ||
| "engines": { | ||
| "node": ">=22.18.0" | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "type": "module", | ||
| "main": "./dist/index.js", | ||
| "module": "./dist/index.js", | ||
| "types": "./dist/index.d.ts", | ||
| "exports": { | ||
| ".": "./dist/index.js", | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
@@ -52,11 +49,10 @@ "@types/superagent": "^8.1.9", | ||
| "express": "^4.21.2", | ||
| "tsdown": "^0.17.0", | ||
| "typescript": "^5.9.3" | ||
| }, | ||
| "engines": { | ||
| "node": ">=22.18.0" | ||
| }, | ||
| "scripts": { | ||
| "build": "tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json", | ||
| "test": "vitest run", | ||
| "typecheck": "tsc --noEmit", | ||
| "lint": "oxlint --type-aware" | ||
| "typecheck": "tsgo --noEmit" | ||
| } | ||
| } |
| export {}; | ||
| //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiJ9 |
7
-12.5%29789
-45.21%14
-6.67%570
-14.93%