@msw/playwright 0.6.1 → 0.6.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/README.md +1 -1
- package/build/index.js +5 -4
- package/package.json +1 -1
- package/src/fixture.ts +33 -34
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ interface Fixtures {
|
|
|
41
41
|
|
|
42
42
|
const test = testBase.extend<Fixtures>({
|
|
43
43
|
// Initial list of the network handlers.
|
|
44
|
-
handlers: [
|
|
44
|
+
handlers: [handlers, { option: true }],
|
|
45
45
|
|
|
46
46
|
// A fixture you use to control the network in your tests.
|
|
47
47
|
network: [
|
package/build/index.js
CHANGED
|
@@ -24,7 +24,8 @@ var SetupPlaywrightApi = class extends SetupApi {
|
|
|
24
24
|
this.options = options;
|
|
25
25
|
}
|
|
26
26
|
async enable() {
|
|
27
|
-
|
|
27
|
+
const { context } = this.options;
|
|
28
|
+
await context.route(INTERNAL_MATCH_ALL_REG_EXP, async (route, request) => {
|
|
28
29
|
const fetchRequest = new Request(request.url(), {
|
|
29
30
|
method: request.method(),
|
|
30
31
|
headers: new Headers(await request.allHeaders()),
|
|
@@ -36,7 +37,7 @@ var SetupPlaywrightApi = class extends SetupApi {
|
|
|
36
37
|
* requests through the matching logic below.
|
|
37
38
|
* @see https://github.com/mswjs/playwright/issues/13
|
|
38
39
|
*/
|
|
39
|
-
if (this.options.skipAssetRequests && isCommonAssetRequest(fetchRequest)) return route.
|
|
40
|
+
if (this.options.skipAssetRequests && isCommonAssetRequest(fetchRequest)) return route.fallback();
|
|
40
41
|
const handlers = this.handlersController.currentHandlers().filter((handler) => {
|
|
41
42
|
return handler instanceof RequestHandler;
|
|
42
43
|
});
|
|
@@ -57,9 +58,9 @@ var SetupPlaywrightApi = class extends SetupApi {
|
|
|
57
58
|
body: response.body ? Buffer.from(await response.arrayBuffer()) : void 0
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
|
-
return route.
|
|
61
|
+
return route.fallback();
|
|
61
62
|
});
|
|
62
|
-
await
|
|
63
|
+
await context.routeWebSocket(INTERNAL_MATCH_ALL_REG_EXP, async (route) => {
|
|
63
64
|
const allWebSocketHandlers = this.handlersController.currentHandlers().filter((handler) => {
|
|
64
65
|
return handler instanceof WebSocketHandler;
|
|
65
66
|
});
|
package/package.json
CHANGED
package/src/fixture.ts
CHANGED
|
@@ -77,8 +77,10 @@ class SetupPlaywrightApi extends SetupApi<LifeCycleEventsMap> {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
public async enable(): Promise<void> {
|
|
80
|
+
const { context } = this.options
|
|
81
|
+
|
|
80
82
|
// Handle HTTP requests.
|
|
81
|
-
await
|
|
83
|
+
await context.route(
|
|
82
84
|
INTERNAL_MATCH_ALL_REG_EXP,
|
|
83
85
|
async (route: Route, request: PlaywrightRequest) => {
|
|
84
86
|
const fetchRequest = new Request(request.url(), {
|
|
@@ -97,7 +99,7 @@ class SetupPlaywrightApi extends SetupApi<LifeCycleEventsMap> {
|
|
|
97
99
|
this.options.skipAssetRequests &&
|
|
98
100
|
isCommonAssetRequest(fetchRequest)
|
|
99
101
|
) {
|
|
100
|
-
return route.
|
|
102
|
+
return route.fallback()
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
const handlers = this.handlersController
|
|
@@ -144,46 +146,43 @@ class SetupPlaywrightApi extends SetupApi<LifeCycleEventsMap> {
|
|
|
144
146
|
})
|
|
145
147
|
}
|
|
146
148
|
|
|
147
|
-
return route.
|
|
149
|
+
return route.fallback()
|
|
148
150
|
},
|
|
149
151
|
)
|
|
150
152
|
|
|
151
153
|
// Handle WebSocket connections.
|
|
152
|
-
await
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return handler instanceof WebSocketHandler
|
|
159
|
-
})
|
|
154
|
+
await context.routeWebSocket(INTERNAL_MATCH_ALL_REG_EXP, async (route) => {
|
|
155
|
+
const allWebSocketHandlers = this.handlersController
|
|
156
|
+
.currentHandlers()
|
|
157
|
+
.filter((handler) => {
|
|
158
|
+
return handler instanceof WebSocketHandler
|
|
159
|
+
})
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
161
|
+
if (allWebSocketHandlers.length === 0) {
|
|
162
|
+
route.connectToServer()
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
165
|
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
const client = new PlaywrightWebSocketClientConnection(route)
|
|
167
|
+
const server = new PlaywrightWebSocketServerConnection(route)
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
const pages = this.options.context.pages()
|
|
170
|
+
const lastPage = pages[pages.length - 1]
|
|
171
|
+
const baseUrl = lastPage ? this.getPageUrl(lastPage) : undefined
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
)
|
|
173
|
+
for (const handler of allWebSocketHandlers) {
|
|
174
|
+
await handler.run(
|
|
175
|
+
{
|
|
176
|
+
client,
|
|
177
|
+
server,
|
|
178
|
+
info: { protocols: [] },
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
baseUrl,
|
|
182
|
+
},
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
})
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
public async disable(): Promise<void> {
|