@mswjs/interceptors 0.17.0 → 0.17.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.
|
@@ -11,7 +11,7 @@ export declare class IsomorphicRequest {
|
|
|
11
11
|
readonly method: string;
|
|
12
12
|
readonly headers: Headers;
|
|
13
13
|
readonly credentials: RequestCredentials;
|
|
14
|
-
private readonly
|
|
14
|
+
private readonly _body;
|
|
15
15
|
private _bodyUsed;
|
|
16
16
|
constructor(url: URL);
|
|
17
17
|
constructor(url: URL, init: RequestInit);
|
package/lib/IsomorphicRequest.js
CHANGED
|
@@ -52,7 +52,7 @@ var IsomorphicRequest = /** @class */ (function () {
|
|
|
52
52
|
this.method = input.method;
|
|
53
53
|
this.headers = input.headers;
|
|
54
54
|
this.credentials = input.credentials;
|
|
55
|
-
this.
|
|
55
|
+
this._body = input._body || defaultBody;
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
this.id = uuid_1.uuidv4();
|
|
@@ -60,7 +60,7 @@ var IsomorphicRequest = /** @class */ (function () {
|
|
|
60
60
|
this.method = init.method || 'GET';
|
|
61
61
|
this.headers = new lib_1.Headers(init.headers);
|
|
62
62
|
this.credentials = init.credentials || 'same-origin';
|
|
63
|
-
this.
|
|
63
|
+
this._body = init.body || defaultBody;
|
|
64
64
|
}
|
|
65
65
|
Object.defineProperty(IsomorphicRequest.prototype, "bodyUsed", {
|
|
66
66
|
get: function () {
|
|
@@ -74,7 +74,7 @@ var IsomorphicRequest = /** @class */ (function () {
|
|
|
74
74
|
return __generator(this, function (_a) {
|
|
75
75
|
outvariant_1.invariant(!this.bodyUsed, 'Failed to execute "text" on "IsomorphicRequest": body buffer already read');
|
|
76
76
|
this._bodyUsed = true;
|
|
77
|
-
return [2 /*return*/, bufferUtils_1.decodeBuffer(this.
|
|
77
|
+
return [2 /*return*/, bufferUtils_1.decodeBuffer(this._body)];
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
80
|
};
|
|
@@ -84,7 +84,7 @@ var IsomorphicRequest = /** @class */ (function () {
|
|
|
84
84
|
return __generator(this, function (_a) {
|
|
85
85
|
outvariant_1.invariant(!this.bodyUsed, 'Failed to execute "json" on "IsomorphicRequest": body buffer already read');
|
|
86
86
|
this._bodyUsed = true;
|
|
87
|
-
text = bufferUtils_1.decodeBuffer(this.
|
|
87
|
+
text = bufferUtils_1.decodeBuffer(this._body);
|
|
88
88
|
return [2 /*return*/, JSON.parse(text)];
|
|
89
89
|
});
|
|
90
90
|
});
|
|
@@ -94,7 +94,7 @@ var IsomorphicRequest = /** @class */ (function () {
|
|
|
94
94
|
return __generator(this, function (_a) {
|
|
95
95
|
outvariant_1.invariant(!this.bodyUsed, 'Failed to execute "arrayBuffer" on "IsomorphicRequest": body buffer already read');
|
|
96
96
|
this._bodyUsed = true;
|
|
97
|
-
return [2 /*return*/, this.
|
|
97
|
+
return [2 /*return*/, this._body];
|
|
98
98
|
});
|
|
99
99
|
});
|
|
100
100
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IsomorphicRequest.js","sourceRoot":"","sources":["../src/IsomorphicRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8C;AAC9C,yCAAsC;AACtC,mDAAkD;AAClD,qCAAqC;AASrC;IAaE,2BAAY,KAA8B,EAAE,IAAsB;QAAtB,qBAAA,EAAA,SAAsB;QAChE,IAAM,WAAW,GAAG,IAAI,WAAW,CAAC,CAAC,CAAC,CAAA;QACtC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAA;QAEtB,IAAI,KAAK,YAAY,iBAAiB,EAAE;YACtC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAA;YAClB,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAA;YACpB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;YAC1B,IAAI,CAAC,OAAO,G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,CAAC;IAED,sBAAW,uCAAQ;aAAnB;YACE,OAAO,IAAI,CAAC,SAAS,CAAA;QACvB,CAAC;;;OAAA;IAEY,gCAAI,GAAjB;;;gBACE,sBAAS,CACP,CAAC,IAAI,CAAC,QAAQ,EACd,2EAA2E,CAC5E,CAAA;gBAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;gBACrB,sBAAO,0BAAY,CAAC,IAAI,CAAC,KAAK,CAAC,EAAA;;;KAChC;IAEY,gCAAI,GAAjB;;;;gBACE,sBAAS,CACP,CAAC,IAAI,CAAC,QAAQ,EACd,2EAA2E,CAC5E,CAAA;gBAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;gBACf,IAAI,GAAG,0BAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACrC,sBAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAA;;;KACxB;IAEY,uCAAW,GAAxB;;;gBACE,sBAAS,CACP,CAAC,IAAI,CAAC,QAAQ,EACd,kFAAkF,CACnF,CAAA;gBAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;gBACrB,sBAAO,IAAI,CAAC,KAAK,EAAA;;;KAClB;IAEM,iCAAK,GAAZ;QACE,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACpC,CAAC;IACH,wBAAC;AAAD,CAAC,AAzED,IAyEC;AAzEY,8CAAiB"}
|
package/package.json
CHANGED
|
@@ -82,20 +82,18 @@ it('returns a copy of isomorphic request instance', () => {
|
|
|
82
82
|
|
|
83
83
|
expect(request.id).toBe(derivedRequest.id)
|
|
84
84
|
expect(request.url.href).toBe(derivedRequest.url.href)
|
|
85
|
-
expect(request['
|
|
85
|
+
expect(request['_body']).toEqual(derivedRequest['_body'])
|
|
86
86
|
expect(request.headers).toEqual(derivedRequest.headers)
|
|
87
87
|
expect(request.method).toBe(derivedRequest.method)
|
|
88
88
|
expect(request.credentials).toBe(derivedRequest.credentials)
|
|
89
89
|
expect(request.bodyUsed).toBe(false)
|
|
90
90
|
})
|
|
91
91
|
|
|
92
|
-
it('clones current isomorphic request instance',
|
|
92
|
+
it('clones current isomorphic request instance', () => {
|
|
93
93
|
const request = new IsomorphicRequest(url, {
|
|
94
94
|
body,
|
|
95
95
|
headers: { foo: 'bar' },
|
|
96
96
|
})
|
|
97
|
-
await request.text()
|
|
98
|
-
|
|
99
97
|
const clonedRequest = request.clone()
|
|
100
98
|
|
|
101
99
|
expect(clonedRequest.id).toBe(request.id)
|
|
@@ -103,6 +101,6 @@ it('clones current isomorphic request instance', async () => {
|
|
|
103
101
|
expect(clonedRequest.url.href).toBe(request.url.href)
|
|
104
102
|
expect(clonedRequest.headers).toEqual(request.headers)
|
|
105
103
|
expect(clonedRequest.credentials).toBe(request.credentials)
|
|
106
|
-
expect(clonedRequest['
|
|
104
|
+
expect(clonedRequest['_body']).toEqual(request['_body'])
|
|
107
105
|
expect(clonedRequest.bodyUsed).toBe(false)
|
|
108
106
|
})
|
package/src/IsomorphicRequest.ts
CHANGED
|
@@ -17,7 +17,7 @@ export class IsomorphicRequest {
|
|
|
17
17
|
public readonly headers: Headers
|
|
18
18
|
public readonly credentials: RequestCredentials
|
|
19
19
|
|
|
20
|
-
private readonly
|
|
20
|
+
private readonly _body: ArrayBuffer
|
|
21
21
|
private _bodyUsed: boolean
|
|
22
22
|
|
|
23
23
|
constructor(url: URL)
|
|
@@ -33,7 +33,7 @@ export class IsomorphicRequest {
|
|
|
33
33
|
this.method = input.method
|
|
34
34
|
this.headers = input.headers
|
|
35
35
|
this.credentials = input.credentials
|
|
36
|
-
this.
|
|
36
|
+
this._body = input._body || defaultBody
|
|
37
37
|
return
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -42,7 +42,7 @@ export class IsomorphicRequest {
|
|
|
42
42
|
this.method = init.method || 'GET'
|
|
43
43
|
this.headers = new Headers(init.headers)
|
|
44
44
|
this.credentials = init.credentials || 'same-origin'
|
|
45
|
-
this.
|
|
45
|
+
this._body = init.body || defaultBody
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
public get bodyUsed(): boolean {
|
|
@@ -56,7 +56,7 @@ export class IsomorphicRequest {
|
|
|
56
56
|
)
|
|
57
57
|
|
|
58
58
|
this._bodyUsed = true
|
|
59
|
-
return decodeBuffer(this.
|
|
59
|
+
return decodeBuffer(this._body)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
public async json<T = any>(): Promise<T> {
|
|
@@ -66,7 +66,7 @@ export class IsomorphicRequest {
|
|
|
66
66
|
)
|
|
67
67
|
|
|
68
68
|
this._bodyUsed = true
|
|
69
|
-
const text = decodeBuffer(this.
|
|
69
|
+
const text = decodeBuffer(this._body)
|
|
70
70
|
return JSON.parse(text)
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -77,7 +77,7 @@ export class IsomorphicRequest {
|
|
|
77
77
|
)
|
|
78
78
|
|
|
79
79
|
this._bodyUsed = true
|
|
80
|
-
return this.
|
|
80
|
+
return this._body
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
public clone(): IsomorphicRequest {
|