@leyyo/http-mock 1.1.1 → 1.2.1
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/README.md +23 -6
- package/dist/application/index.types.d.ts +58 -0
- package/dist/{request/index-types.js → application/index.types.js} +1 -1
- package/dist/application/index.types.js.map +1 -0
- package/dist/application/mock-application.d.ts +47 -56
- package/dist/application/mock-application.js +162 -87
- package/dist/application/mock-application.js.map +1 -1
- package/dist/http-mock.d.ts +2 -10
- package/dist/http-mock.js +19 -9
- package/dist/http-mock.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/index.types.d.ts +10 -0
- package/dist/index.types.js +3 -0
- package/dist/index.types.js.map +1 -0
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +6 -0
- package/dist/internal.js.map +1 -0
- package/dist/request/index.d.ts +2 -2
- package/dist/request/index.js +2 -2
- package/dist/request/index.types.d.ts +25 -0
- package/dist/request/index.types.js +3 -0
- package/dist/request/index.types.js.map +1 -0
- package/dist/request/mock.request.d.ts +123 -0
- package/dist/request/mock.request.js +261 -0
- package/dist/request/mock.request.js.map +1 -0
- package/dist/response/index-types.d.ts +19 -15
- package/dist/response/mock-response.d.ts +72 -78
- package/dist/response/mock-response.js +174 -154
- package/dist/response/mock-response.js.map +1 -1
- package/dist/shared/http-event.d.ts +36 -0
- package/dist/shared/http-event.js +94 -0
- package/dist/shared/http-event.js.map +1 -0
- package/dist/shared/http-method.d.ts +11 -0
- package/dist/shared/http-method.js +20 -0
- package/dist/shared/http-method.js.map +1 -0
- package/dist/shared/http-protocol.d.ts +10 -0
- package/dist/shared/http-protocol.js +12 -0
- package/dist/shared/http-protocol.js.map +1 -0
- package/dist/shared/index.d.ts +4 -0
- package/dist/shared/index.js +21 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/index.types.d.ts +27 -0
- package/dist/shared/index.types.js +3 -0
- package/dist/shared/index.types.js.map +1 -0
- package/package.json +29 -33
- package/dist/internal-component.d.ts +0 -3
- package/dist/internal-component.js +0 -8
- package/dist/internal-component.js.map +0 -1
- package/dist/request/index-types.d.ts +0 -20
- package/dist/request/index-types.js.map +0 -1
- package/dist/request/mock-request.d.ts +0 -121
- package/dist/request/mock-request.js +0 -229
- package/dist/request/mock-request.js.map +0 -1
- package/dist/server.d.ts +0 -0
- package/dist/server.js +0 -2
- package/dist/server.js.map +0 -1
|
@@ -1,119 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { OutgoingHttpHeader, OutgoingHttpHeaders } from "http";
|
|
7
|
-
|
|
8
|
-
import { MockResponseLike, MockResponseResolve, ResponseData, ResponseErrorCallback } from "./index-types";
|
|
9
|
-
export declare class MockResponse<D = ResponseData, L extends RecLike = RecLike> implements MockResponseLike<D, L>, RecLike {
|
|
1
|
+
import type { Application, CookieOptions, Errback, Request, Response } from "express";
|
|
2
|
+
import type { Socket } from "net";
|
|
3
|
+
import type { MockResponseLike, MockResponseResolve, ResponseData, ResponseErrorCallback, ResponseLocal } from "./index-types";
|
|
4
|
+
import type { Dict, KeyValue, OneOrMore } from "@leyyo/common";
|
|
5
|
+
import { HttpEvent, type HttpStatus } from "../shared";
|
|
6
|
+
import type { OutgoingHttpHeader, OutgoingHttpHeaders } from "node:http";
|
|
7
|
+
export declare class MockResponse<R extends ResponseData, L extends ResponseLocal = ResponseLocal> extends HttpEvent<Response> implements MockResponseLike<R, L> {
|
|
10
8
|
private _headersSent;
|
|
11
|
-
readonly isFake: boolean;
|
|
12
|
-
[key: string]: unknown;
|
|
13
9
|
private readonly _resolver;
|
|
14
|
-
readonly app: Application;
|
|
15
|
-
readonly locals: L;
|
|
16
|
-
sendDate: boolean;
|
|
17
|
-
statusMessage: string;
|
|
18
10
|
private _headers;
|
|
19
11
|
private _cookies;
|
|
20
12
|
private _clearedCookies;
|
|
21
13
|
private _data;
|
|
22
14
|
private _status;
|
|
23
|
-
|
|
24
|
-
|
|
15
|
+
readonly locals: L;
|
|
16
|
+
readonly isFake: boolean;
|
|
17
|
+
[another: string]: unknown;
|
|
18
|
+
static setFirstOrigin(origin: Response): void;
|
|
19
|
+
static get firstOrigin(): Response;
|
|
20
|
+
constructor(resolver: MockResponseResolve<R>, origin?: Response);
|
|
21
|
+
private _send;
|
|
22
|
+
private _setHeader;
|
|
23
|
+
private _setCookie;
|
|
24
|
+
private _cancelCookieClear;
|
|
25
|
+
private _clear;
|
|
25
26
|
destroyed: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
readonly req: Request;
|
|
29
|
-
useChunkedEncodingByDefault: boolean;
|
|
27
|
+
closed: boolean;
|
|
28
|
+
errored: Error;
|
|
30
29
|
readonly writable: boolean;
|
|
30
|
+
readonly writableAborted: boolean;
|
|
31
31
|
readonly writableCorked: number;
|
|
32
32
|
readonly writableEnded: boolean;
|
|
33
33
|
readonly writableFinished: boolean;
|
|
34
34
|
readonly writableHighWaterMark: number;
|
|
35
35
|
readonly writableLength: number;
|
|
36
36
|
readonly writableObjectMode: boolean;
|
|
37
|
-
shouldKeepAlive: boolean;
|
|
38
|
-
readonly socket: Socket | null;
|
|
39
|
-
statusCode: number;
|
|
40
|
-
writeHead: ((statusCode: number, statusMessage?: string, headers?: (OutgoingHttpHeaders | OutgoingHttpHeader[])) => this) & ((statusCode: number, headers?: (OutgoingHttpHeaders | OutgoingHttpHeader[])) => this);
|
|
41
|
-
closed: boolean;
|
|
42
|
-
errored: Error;
|
|
43
37
|
writableNeedDrain: boolean;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
private _clear;
|
|
50
|
-
_construct(callback?: ResponseErrorCallback): void;
|
|
51
|
-
_destroy(error: Error | null, callback: ResponseErrorCallback): void;
|
|
52
|
-
_final(callback: ResponseErrorCallback): void;
|
|
53
|
-
_write(chunk: unknown, encoding: BufferEncoding, callback: ResponseErrorCallback): void;
|
|
54
|
-
_writev(chunks: Array<{
|
|
38
|
+
_construct(_c?: ResponseErrorCallback): void;
|
|
39
|
+
_destroy(_e: Error | null, _c: ResponseErrorCallback): void;
|
|
40
|
+
_final(_c: ResponseErrorCallback): void;
|
|
41
|
+
_write(_c: unknown, _e: BufferEncoding, _r: ResponseErrorCallback): void;
|
|
42
|
+
_writev(_c: Array<{
|
|
55
43
|
chunk: unknown;
|
|
56
44
|
encoding: BufferEncoding;
|
|
57
|
-
}>,
|
|
58
|
-
addTrailers(headers: OutgoingHttpHeaders | Array<[string, string]>): void;
|
|
59
|
-
assignSocket(socket: Socket): void;
|
|
60
|
-
get headersSent(): boolean;
|
|
45
|
+
}>, _b: ResponseErrorCallback): void;
|
|
61
46
|
cork(): void;
|
|
62
|
-
destroy(
|
|
63
|
-
|
|
47
|
+
destroy(_e: Error | undefined): this;
|
|
48
|
+
pipe<T extends NodeJS.WritableStream>(_d: T, _o: {
|
|
49
|
+
end?: boolean | undefined;
|
|
50
|
+
} | undefined): T;
|
|
51
|
+
setDefaultEncoding(_e: BufferEncoding): this;
|
|
52
|
+
uncork(): void;
|
|
53
|
+
end(): this;
|
|
54
|
+
write(_b: Uint8Array | string, _c?: ResponseErrorCallback | BufferEncoding, _d?: ResponseErrorCallback): boolean;
|
|
55
|
+
compose<T>(_s: ComposeFnParam | Iterable<T> | AsyncIterable<T> | T, _o: {
|
|
56
|
+
signal: AbortSignal;
|
|
57
|
+
} | undefined): T;
|
|
58
|
+
sendDate: boolean;
|
|
59
|
+
statusMessage: string;
|
|
60
|
+
chunkedEncoding: boolean;
|
|
61
|
+
shouldKeepAlive: boolean;
|
|
62
|
+
finished: boolean;
|
|
63
|
+
get connection(): Socket;
|
|
64
|
+
useChunkedEncodingByDefault: boolean;
|
|
65
|
+
readonly socket: Socket | null;
|
|
66
|
+
statusCode: number;
|
|
67
|
+
writeHead: ((statusCode: number, statusMessage?: string, headers?: (OutgoingHttpHeaders | OutgoingHttpHeader[])) => this) & ((statusCode: number, headers?: (OutgoingHttpHeaders | OutgoingHttpHeader[])) => this);
|
|
68
|
+
strictContentLength: boolean;
|
|
69
|
+
addTrailers(_h: OutgoingHttpHeaders | Array<[string, string]>): void;
|
|
70
|
+
assignSocket(_s: Socket): void;
|
|
71
|
+
detachSocket(_s: Socket): void;
|
|
64
72
|
flushHeaders(): void;
|
|
65
73
|
getHeader(name: string): number | string | string[] | undefined;
|
|
66
74
|
getHeaderNames(): string[];
|
|
67
75
|
getHeaders(): OutgoingHttpHeaders;
|
|
68
76
|
hasHeader(name: string): boolean;
|
|
69
|
-
json(data: D): this;
|
|
70
|
-
jsonp(data: D): this;
|
|
71
|
-
pipe<T>(destination: T, options: {
|
|
72
|
-
end?: boolean | undefined;
|
|
73
|
-
} | undefined): T;
|
|
74
77
|
removeHeader(name: string): void;
|
|
75
|
-
send(body?: unknown): this;
|
|
76
|
-
setDefaultEncoding(encoding: BufferEncoding): this;
|
|
77
78
|
setHeader(name: string, value: number | string | ReadonlyArray<string>): this;
|
|
78
|
-
setTimeout(
|
|
79
|
-
|
|
80
|
-
writeContinue(callback: (() => void) | undefined): void;
|
|
79
|
+
setTimeout(_m: number, _c: (() => void) | undefined): this;
|
|
80
|
+
writeContinue(_c: (() => void) | undefined): void;
|
|
81
81
|
writeProcessing(): void;
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
appendHeader(name: string, value: string | readonly string[]): this;
|
|
83
|
+
setHeaders(headers: Headers | Map<string, number | string | readonly string[]>): this;
|
|
84
|
+
writeEarlyHints(_h: Record<string, string | string[]>, _c: (() => void) | undefined): void;
|
|
85
|
+
readonly app: Application;
|
|
86
|
+
charset: string;
|
|
87
|
+
readonly req: Request;
|
|
88
|
+
get headersSent(): boolean;
|
|
89
|
+
json(data: R): this;
|
|
90
|
+
jsonp(data: R): this;
|
|
91
|
+
send(body?: unknown): this;
|
|
84
92
|
attachment(filename?: string): this;
|
|
85
93
|
clearCookie(name: string, options?: CookieOptions): this;
|
|
94
|
+
append(key: string, value?: OneOrMore<string>): this;
|
|
86
95
|
contentType(type: string): this;
|
|
87
96
|
cookie(key: string, value: unknown, option?: CookieOptions): this;
|
|
88
|
-
download(path: string,
|
|
89
|
-
emit(eventName: string | symbol, ...args: unknown[]): boolean;
|
|
90
|
-
end(): this;
|
|
91
|
-
eventNames(): Array<string | symbol>;
|
|
97
|
+
download(path: string, _fn?: Errback | string, _err?: unknown, _errBack?: Errback): void;
|
|
92
98
|
format(obj: unknown): this;
|
|
93
99
|
get(field: string): string;
|
|
94
|
-
getMaxListeners(): number;
|
|
95
100
|
header(field: unknown, value?: OneOrMore<string>): this;
|
|
96
101
|
links(map: unknown): this;
|
|
97
|
-
listenerCount(eventName: string | symbol): number;
|
|
98
|
-
listeners(eventName: string | symbol): Array<FuncLike>;
|
|
99
102
|
location(url: string): this;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
prependListener(eventName: string | symbol, listener: FuncLike): this;
|
|
104
|
-
prependOnceListener(eventName: string | symbol, listener: FuncLike): this;
|
|
105
|
-
rawListeners(eventName: string | symbol): Function[];
|
|
106
|
-
redirect(url: Key, status?: Key): void;
|
|
107
|
-
removeAllListeners(event?: string | symbol): this;
|
|
108
|
-
removeListener(eventName: string | symbol, listener: FuncLike): this;
|
|
109
|
-
render(view: string, options?: RecLike | ((err: Error, html: string) => void), callback?: (err: Error, html: string) => void): void;
|
|
110
|
-
sendFile(path: string, fn?: unknown, err?: Errback): void;
|
|
103
|
+
redirect(url: KeyValue, status?: KeyValue): void;
|
|
104
|
+
render(_v: string, _o?: Dict | ((err: Error, html: string) => void), _c?: (err: Error, html: string) => void): void;
|
|
105
|
+
sendFile(path: string, _fn?: unknown, _err?: Errback): void;
|
|
111
106
|
sendStatus(status: number): this;
|
|
112
|
-
sendfile(path: string, options?: unknown, fn?: Errback): void;
|
|
113
107
|
set(field: unknown, value?: string | string[]): this;
|
|
114
|
-
|
|
115
|
-
status(status: number): this;
|
|
108
|
+
status(status: HttpStatus): this;
|
|
116
109
|
type(type: string): this;
|
|
117
110
|
vary(field: string): this;
|
|
118
|
-
write(buffer: Uint8Array | string, cb?: ResponseErrorCallback | BufferEncoding, cb2?: ResponseErrorCallback): boolean;
|
|
119
111
|
}
|
|
112
|
+
type ComposeFnParam = (source: any) => void;
|
|
113
|
+
export {};
|
|
@@ -1,43 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
14
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
36
|
exports.MockResponse = void 0;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
37
|
+
const mime = __importStar(require("mime-types"));
|
|
38
|
+
const common_1 = require("@leyyo/common");
|
|
39
|
+
const shared_1 = require("../shared");
|
|
40
|
+
let _firstOrigin;
|
|
41
|
+
class MockResponse extends shared_1.HttpEvent {
|
|
42
|
+
// endregion property
|
|
43
|
+
// region static
|
|
44
|
+
// noinspection JSUnusedGlobalSymbols
|
|
45
|
+
static setFirstOrigin(origin) {
|
|
46
|
+
if (!_firstOrigin && origin) {
|
|
47
|
+
_firstOrigin = origin;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
static get firstOrigin() {
|
|
51
|
+
return _firstOrigin;
|
|
52
|
+
}
|
|
53
|
+
// endregion static
|
|
54
|
+
// region constructor
|
|
23
55
|
constructor(resolver, origin) {
|
|
56
|
+
var _a;
|
|
57
|
+
super(origin);
|
|
24
58
|
if (typeof resolver != "function") {
|
|
25
|
-
resolver = (
|
|
26
|
-
(0, core_1.emptyFn)();
|
|
59
|
+
resolver = (() => {
|
|
27
60
|
});
|
|
28
61
|
}
|
|
29
62
|
this._resolver = resolver;
|
|
30
63
|
this.isFake = true;
|
|
31
|
-
if (!(origin === null || origin === void 0 ? void 0 : origin.app)) {
|
|
32
|
-
this.app = new application_1.MockApplication();
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.app = origin.app;
|
|
36
|
-
}
|
|
37
|
-
this.locals = (core_1.leyyo.is.object(origin.locals) ? Object.assign({}, origin.locals) : {});
|
|
38
64
|
this._headersSent = false;
|
|
65
|
+
this.locals = ((_a = origin === null || origin === void 0 ? void 0 : origin.locals) !== null && _a !== void 0 ? _a : {});
|
|
39
66
|
this._clear();
|
|
40
67
|
}
|
|
68
|
+
// endregion constructor
|
|
41
69
|
// region private
|
|
42
70
|
_send(data) {
|
|
43
71
|
if (!this._headersSent) {
|
|
@@ -52,7 +80,6 @@ let MockResponse = class MockResponse {
|
|
|
52
80
|
cookies: this._cookies,
|
|
53
81
|
clearedCookies: this._clearedCookies,
|
|
54
82
|
data: this._data,
|
|
55
|
-
locals: this.locals,
|
|
56
83
|
});
|
|
57
84
|
}
|
|
58
85
|
return this;
|
|
@@ -80,38 +107,61 @@ let MockResponse = class MockResponse {
|
|
|
80
107
|
this._data = undefined;
|
|
81
108
|
this._status = 200;
|
|
82
109
|
}
|
|
83
|
-
_construct(
|
|
84
|
-
(
|
|
110
|
+
_construct(_c) {
|
|
111
|
+
logger.warn('Should not be called', { fn: '_construct' });
|
|
85
112
|
}
|
|
86
|
-
_destroy(
|
|
87
|
-
(
|
|
113
|
+
_destroy(_e, _c) {
|
|
114
|
+
logger.warn('Should not be called', { fn: '_destroy' });
|
|
88
115
|
}
|
|
89
|
-
_final(
|
|
90
|
-
(
|
|
116
|
+
_final(_c) {
|
|
117
|
+
logger.warn('Should not be called', { fn: '_final' });
|
|
91
118
|
}
|
|
92
|
-
_write(
|
|
93
|
-
(
|
|
119
|
+
_write(_c, _e, _r) {
|
|
120
|
+
logger.warn('Should not be called', { fn: '_write' });
|
|
94
121
|
}
|
|
95
|
-
_writev(
|
|
96
|
-
(
|
|
122
|
+
_writev(_c, _b) {
|
|
123
|
+
logger.warn('Should not be called', { fn: '_writev' });
|
|
97
124
|
}
|
|
98
|
-
|
|
99
|
-
(
|
|
125
|
+
cork() {
|
|
126
|
+
logger.warn('Should not be called', { fn: 'cork' });
|
|
100
127
|
}
|
|
101
|
-
|
|
102
|
-
(
|
|
128
|
+
destroy(_e) {
|
|
129
|
+
logger.warn('Should not be called', { fn: 'destroy' });
|
|
130
|
+
return this;
|
|
103
131
|
}
|
|
104
|
-
|
|
105
|
-
|
|
132
|
+
pipe(_d, _o) {
|
|
133
|
+
logger.warn('Should not be called', { fn: 'pipe' });
|
|
134
|
+
return undefined;
|
|
106
135
|
}
|
|
107
|
-
|
|
108
|
-
(
|
|
136
|
+
setDefaultEncoding(_e) {
|
|
137
|
+
logger.warn('Should not be called', { fn: 'setDefaultEncoding' });
|
|
138
|
+
return this;
|
|
109
139
|
}
|
|
110
|
-
|
|
140
|
+
uncork() {
|
|
141
|
+
logger.warn('Should not be called', { fn: 'uncork' });
|
|
142
|
+
}
|
|
143
|
+
end() {
|
|
144
|
+
this._clear();
|
|
145
|
+
this._send();
|
|
111
146
|
return this;
|
|
112
147
|
}
|
|
113
|
-
|
|
114
|
-
(
|
|
148
|
+
write(_b, _c, _d) {
|
|
149
|
+
logger.warn('Should not be called', { fn: 'write' });
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
compose(_s, _o) {
|
|
153
|
+
logger.warn('Should not be called', { fn: 'compose' });
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
get connection() { return this.socket; }
|
|
157
|
+
addTrailers(_h) {
|
|
158
|
+
logger.warn('Should not be called', { fn: 'addTrailers' });
|
|
159
|
+
}
|
|
160
|
+
assignSocket(_s) {
|
|
161
|
+
logger.warn('Should not be called', { fn: 'assignSocket' });
|
|
162
|
+
}
|
|
163
|
+
detachSocket(_s) {
|
|
164
|
+
logger.warn('Should not be called', { fn: 'detachSocket' });
|
|
115
165
|
}
|
|
116
166
|
flushHeaders() {
|
|
117
167
|
this._headers = {};
|
|
@@ -120,57 +170,81 @@ let MockResponse = class MockResponse {
|
|
|
120
170
|
return this.get(name);
|
|
121
171
|
}
|
|
122
172
|
getHeaderNames() {
|
|
123
|
-
return
|
|
173
|
+
return Object.keys(this._headers);
|
|
124
174
|
}
|
|
125
175
|
getHeaders() {
|
|
126
|
-
return
|
|
176
|
+
return this._headers;
|
|
127
177
|
}
|
|
128
178
|
hasHeader(name) {
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
json(data) {
|
|
132
|
-
this._setHeader('Content-Type', 'application/json');
|
|
133
|
-
this._send(data);
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
jsonp(data) {
|
|
137
|
-
this._setHeader('Content-Type', 'application/json');
|
|
138
|
-
this._send(data);
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
pipe(destination, options) {
|
|
142
|
-
return destination;
|
|
179
|
+
return this._headers[name] !== undefined;
|
|
143
180
|
}
|
|
144
181
|
removeHeader(name) {
|
|
145
|
-
(
|
|
182
|
+
if (this._headers[name] !== undefined) {
|
|
183
|
+
delete this._headers[name];
|
|
184
|
+
}
|
|
146
185
|
}
|
|
147
|
-
|
|
148
|
-
this.
|
|
186
|
+
setHeader(name, value) {
|
|
187
|
+
this._headers[name] = value;
|
|
149
188
|
return this;
|
|
150
189
|
}
|
|
151
|
-
|
|
190
|
+
setTimeout(_m, _c) {
|
|
191
|
+
logger.warn('Should not be called', { fn: 'setTimeout' });
|
|
152
192
|
return this;
|
|
153
193
|
}
|
|
154
|
-
|
|
194
|
+
writeContinue(_c) {
|
|
195
|
+
logger.warn('Should not be called', { fn: 'writeContinue' });
|
|
196
|
+
}
|
|
197
|
+
writeProcessing() {
|
|
198
|
+
logger.warn('Should not be called', { fn: 'writeProcessing' });
|
|
199
|
+
}
|
|
200
|
+
appendHeader(name, value) {
|
|
201
|
+
if (this._headers[name] === undefined) {
|
|
202
|
+
this._headers[name] = [];
|
|
203
|
+
}
|
|
204
|
+
else if (!Array.isArray(this._headers[name])) {
|
|
205
|
+
this._headers[name] = [this._headers[name]];
|
|
206
|
+
}
|
|
207
|
+
if (Array.isArray(value)) {
|
|
208
|
+
this._headers[name].push(...value);
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
this._headers[name].push(value);
|
|
212
|
+
}
|
|
155
213
|
return this;
|
|
156
214
|
}
|
|
157
|
-
|
|
215
|
+
setHeaders(headers) {
|
|
216
|
+
this._headers = {};
|
|
217
|
+
if (headers instanceof Map) {
|
|
218
|
+
for (const [k, v] of headers.entries()) {
|
|
219
|
+
this._headers[k] = v;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
for (const [k, v] of Object.entries(headers)) {
|
|
224
|
+
this._headers[k] = v;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
158
227
|
return this;
|
|
159
228
|
}
|
|
160
|
-
|
|
161
|
-
(
|
|
229
|
+
writeEarlyHints(_h, _c) {
|
|
230
|
+
logger.warn('Should not be called', { fn: 'writeEarlyHints' });
|
|
162
231
|
}
|
|
163
|
-
|
|
164
|
-
|
|
232
|
+
get headersSent() {
|
|
233
|
+
return this._headersSent;
|
|
165
234
|
}
|
|
166
|
-
|
|
167
|
-
(
|
|
235
|
+
json(data) {
|
|
236
|
+
this._setHeader('Content-Type', 'application/json');
|
|
237
|
+
this._send(data);
|
|
238
|
+
return this;
|
|
168
239
|
}
|
|
169
|
-
|
|
170
|
-
|
|
240
|
+
jsonp(data) {
|
|
241
|
+
this._setHeader('Content-Type', 'application/json');
|
|
242
|
+
this._send(data);
|
|
243
|
+
return this;
|
|
171
244
|
}
|
|
172
|
-
|
|
173
|
-
|
|
245
|
+
send(body) {
|
|
246
|
+
this._send(body);
|
|
247
|
+
return this;
|
|
174
248
|
}
|
|
175
249
|
attachment(filename) {
|
|
176
250
|
filename = filename ? `; filename="${filename}"` : '';
|
|
@@ -180,6 +254,9 @@ let MockResponse = class MockResponse {
|
|
|
180
254
|
this._clearedCookies[name] = options;
|
|
181
255
|
return this;
|
|
182
256
|
}
|
|
257
|
+
append(key, value) {
|
|
258
|
+
return this._setHeader(key, value);
|
|
259
|
+
}
|
|
183
260
|
contentType(type) {
|
|
184
261
|
return this.type(type);
|
|
185
262
|
}
|
|
@@ -188,7 +265,7 @@ let MockResponse = class MockResponse {
|
|
|
188
265
|
this._cancelCookieClear(key);
|
|
189
266
|
return this._setCookie(key, value, option);
|
|
190
267
|
}
|
|
191
|
-
if (
|
|
268
|
+
if (key) {
|
|
192
269
|
for (const [k, v] of Object.entries(key)) {
|
|
193
270
|
this._cancelCookieClear(k);
|
|
194
271
|
this._setCookie(k, v, value !== null && value !== void 0 ? value : option);
|
|
@@ -196,35 +273,21 @@ let MockResponse = class MockResponse {
|
|
|
196
273
|
}
|
|
197
274
|
return this;
|
|
198
275
|
}
|
|
199
|
-
download(path,
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
emit(eventName, ...args) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
end() {
|
|
206
|
-
this._clear();
|
|
207
|
-
this._send();
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
eventNames() {
|
|
211
|
-
return [];
|
|
276
|
+
download(path, _fn, _err, _errBack) {
|
|
277
|
+
logger.warn('unsupported.feature', { fn: 'download', path });
|
|
212
278
|
}
|
|
213
279
|
format(obj) {
|
|
214
|
-
|
|
280
|
+
logger.warn('unsupported.feature', { fn: 'format', obj });
|
|
215
281
|
return this;
|
|
216
282
|
}
|
|
217
283
|
get(field) {
|
|
218
284
|
return (typeof field === 'string') ? this._headers[field] : undefined;
|
|
219
285
|
}
|
|
220
|
-
getMaxListeners() {
|
|
221
|
-
return 0;
|
|
222
|
-
}
|
|
223
286
|
header(field, value) {
|
|
224
287
|
return this._setHeader(field, value);
|
|
225
288
|
}
|
|
226
289
|
links(map) {
|
|
227
|
-
if (
|
|
290
|
+
if (map) {
|
|
228
291
|
const values = [];
|
|
229
292
|
for (const [k, v] of Object.entries(map)) {
|
|
230
293
|
values.push(`<${v}>; rel="${k}"`);
|
|
@@ -235,71 +298,35 @@ let MockResponse = class MockResponse {
|
|
|
235
298
|
}
|
|
236
299
|
return this;
|
|
237
300
|
}
|
|
238
|
-
listenerCount(eventName) {
|
|
239
|
-
return 0;
|
|
240
|
-
}
|
|
241
|
-
listeners(eventName) {
|
|
242
|
-
return [];
|
|
243
|
-
}
|
|
244
301
|
location(url) {
|
|
245
|
-
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
off(eventName, listener) {
|
|
249
|
-
return this;
|
|
250
|
-
}
|
|
251
|
-
on(eventName, listener) {
|
|
252
|
-
return this;
|
|
253
|
-
}
|
|
254
|
-
once(eventName, listener) {
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
prependListener(eventName, listener) {
|
|
258
|
-
return this;
|
|
259
|
-
}
|
|
260
|
-
prependOnceListener(eventName, listener) {
|
|
302
|
+
logger.warn('unsupported.feature', { fn: 'location', url });
|
|
261
303
|
return this;
|
|
262
304
|
}
|
|
263
|
-
rawListeners(eventName) {
|
|
264
|
-
return [];
|
|
265
|
-
}
|
|
266
305
|
redirect(url, status) {
|
|
267
|
-
|
|
306
|
+
logger.warn('unsupported.feature', { fn: 'redirect', url, status });
|
|
268
307
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
removeListener(eventName, listener) {
|
|
273
|
-
return this;
|
|
308
|
+
render(_v, _o, _c) {
|
|
309
|
+
logger.warn('unsupported.feature', { fn: 'render' });
|
|
274
310
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
sendFile(path, fn, err) {
|
|
279
|
-
LOG.warn('unsupported.feature', { fn: 'sendFile', path });
|
|
311
|
+
sendFile(path, _fn, _err) {
|
|
312
|
+
logger.warn('unsupported.feature', { fn: 'sendFile', path });
|
|
280
313
|
}
|
|
281
314
|
sendStatus(status) {
|
|
282
315
|
this._status = status;
|
|
283
316
|
this._send();
|
|
284
317
|
return this;
|
|
285
318
|
}
|
|
286
|
-
sendfile(path, options, fn) {
|
|
287
|
-
LOG.warn('unsupported.feature', { fn: 'render' });
|
|
288
|
-
}
|
|
289
319
|
set(field, value) {
|
|
290
320
|
if (typeof field === 'string') {
|
|
291
321
|
return this._setHeader(field, value);
|
|
292
322
|
}
|
|
293
|
-
if (
|
|
323
|
+
if (field) {
|
|
294
324
|
for (const [k, v] of Object.entries(field)) {
|
|
295
325
|
this._setHeader(k, v);
|
|
296
326
|
}
|
|
297
327
|
}
|
|
298
328
|
return this;
|
|
299
329
|
}
|
|
300
|
-
setMaxListeners(n) {
|
|
301
|
-
return this;
|
|
302
|
-
}
|
|
303
330
|
status(status) {
|
|
304
331
|
this._status = status;
|
|
305
332
|
return this;
|
|
@@ -310,7 +337,7 @@ let MockResponse = class MockResponse {
|
|
|
310
337
|
this.header('Content-Type', type);
|
|
311
338
|
}
|
|
312
339
|
else {
|
|
313
|
-
this.header('Content-Type',
|
|
340
|
+
this.header('Content-Type', mime.lookup(type));
|
|
314
341
|
}
|
|
315
342
|
}
|
|
316
343
|
return this;
|
|
@@ -319,14 +346,7 @@ let MockResponse = class MockResponse {
|
|
|
319
346
|
this.header('Vary', field);
|
|
320
347
|
return this;
|
|
321
348
|
}
|
|
322
|
-
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
MockResponse = __decorate([
|
|
327
|
-
(0, fqn_1.Fqn)(...internal_component_1.FQN_NAME),
|
|
328
|
-
__metadata("design:paramtypes", [Function, Object])
|
|
329
|
-
], MockResponse);
|
|
349
|
+
}
|
|
330
350
|
exports.MockResponse = MockResponse;
|
|
331
|
-
const
|
|
351
|
+
const logger = common_1.$log.create(MockResponse);
|
|
332
352
|
//# sourceMappingURL=mock-response.js.map
|