msw 2.2.1 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/HttpResponse.js +2 -2
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs +2 -2
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/iife/index.js +2 -2
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +3 -3
- package/src/core/HttpResponse.test.ts +26 -0
- package/src/core/HttpResponse.ts +2 -2
package/lib/mockServiceWorker.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "msw",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Seamless REST/GraphQL API mocking library for browser and Node.js.",
|
|
5
5
|
"main": "./lib/core/index.js",
|
|
6
6
|
"module": "./lib/core/index.mjs",
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
"simple-git-hooks": "^2.9.0",
|
|
163
163
|
"ts-node": "^10.9.2",
|
|
164
164
|
"tsup": "^8.0.1",
|
|
165
|
-
"typescript": "^5.
|
|
165
|
+
"typescript": "^5.4.2",
|
|
166
166
|
"undici": "^5.20.0",
|
|
167
167
|
"url-loader": "^4.1.1",
|
|
168
168
|
"vitest": "^0.34.6",
|
|
@@ -171,7 +171,7 @@
|
|
|
171
171
|
"webpack-http-server": "^0.5.0"
|
|
172
172
|
},
|
|
173
173
|
"peerDependencies": {
|
|
174
|
-
"typescript": ">= 4.7.x
|
|
174
|
+
"typescript": ">= 4.7.x"
|
|
175
175
|
},
|
|
176
176
|
"peerDependenciesMeta": {
|
|
177
177
|
"typescript": {
|
|
@@ -27,6 +27,19 @@ describe('HttpResponse.text()', () => {
|
|
|
27
27
|
})
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
+
it('creates a text response with special characters', async () => {
|
|
31
|
+
const response = HttpResponse.text('안녕 세상', { status: 201 })
|
|
32
|
+
|
|
33
|
+
expect(response.status).toBe(201)
|
|
34
|
+
expect(response.statusText).toBe('Created')
|
|
35
|
+
expect(response.body).toBeInstanceOf(ReadableStream)
|
|
36
|
+
expect(await response.text()).toBe('안녕 세상')
|
|
37
|
+
expect(Object.fromEntries(response.headers.entries())).toEqual({
|
|
38
|
+
'content-length': '13',
|
|
39
|
+
'content-type': 'text/plain',
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
30
43
|
it('allows overriding the "Content-Type" response header', async () => {
|
|
31
44
|
const response = HttpResponse.text('hello world', {
|
|
32
45
|
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
|
|
@@ -68,6 +81,19 @@ describe('HttpResponse.json()', () => {
|
|
|
68
81
|
})
|
|
69
82
|
})
|
|
70
83
|
|
|
84
|
+
it('creates a json response given an object with special characters', async () => {
|
|
85
|
+
const response = HttpResponse.json({ firstName: '제로' })
|
|
86
|
+
|
|
87
|
+
expect(response.status).toBe(200)
|
|
88
|
+
expect(response.statusText).toBe('OK')
|
|
89
|
+
expect(response.body).toBeInstanceOf(ReadableStream)
|
|
90
|
+
expect(await response.json()).toEqual({ firstName: '제로' })
|
|
91
|
+
expect(Object.fromEntries(response.headers.entries())).toEqual({
|
|
92
|
+
'content-length': '22',
|
|
93
|
+
'content-type': 'application/json',
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
71
97
|
it('creates a json response given an array', async () => {
|
|
72
98
|
const response = HttpResponse.json([1, 2, 3])
|
|
73
99
|
|
package/src/core/HttpResponse.ts
CHANGED
|
@@ -63,7 +63,7 @@ export class HttpResponse extends Response {
|
|
|
63
63
|
if (!responseInit.headers.has('Content-Length')) {
|
|
64
64
|
responseInit.headers.set(
|
|
65
65
|
'Content-Length',
|
|
66
|
-
body ? body.
|
|
66
|
+
body ? new Blob([body]).size.toString() : '0',
|
|
67
67
|
)
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -95,7 +95,7 @@ export class HttpResponse extends Response {
|
|
|
95
95
|
if (!responseInit.headers.has('Content-Length')) {
|
|
96
96
|
responseInit.headers.set(
|
|
97
97
|
'Content-Length',
|
|
98
|
-
responseText ? responseText.
|
|
98
|
+
responseText ? new Blob([responseText]).size.toString() : '0',
|
|
99
99
|
)
|
|
100
100
|
}
|
|
101
101
|
|