@@ -4,6 +4,7 @@ const webpack = require("webpack");
44const Server = require ( "../../lib/Server" ) ;
55const config = require ( "../fixtures/simple-config-other/webpack.config" ) ;
66const runBrowser = require ( "../helpers/run-browser" ) ;
7+ const sessionSubscribe = require ( "../helpers/session-subscribe" ) ;
78const port = require ( "../ports-map" ) [ "client-option" ] ;
89
910describe ( "client option" , ( ) => {
@@ -42,7 +43,7 @@ describe("client option", () => {
4243 await server . stop ( ) ;
4344 } ) ;
4445
45- it ( "responds with a 200 status code for /ws path" , async ( ) => {
46+ it ( "responds with a 200 status code for / path" , async ( ) => {
4647 page
4748 . on ( "console" , ( message ) => {
4849 consoleMessages . push ( message ) ;
@@ -51,7 +52,22 @@ describe("client option", () => {
5152 pageErrors . push ( error ) ;
5253 } ) ;
5354
54- const response = await page . goto ( `http://localhost:${ port } /ws` , {
55+ const webSocketRequests = [ ] ;
56+ const session = await page . target ( ) . createCDPSession ( ) ;
57+
58+ session . on ( "Network.webSocketCreated" , ( test ) => {
59+ webSocketRequests . push ( test ) ;
60+ } ) ;
61+
62+ await session . send ( "Target.setAutoAttach" , {
63+ autoAttach : true ,
64+ flatten : true ,
65+ waitForDebuggerOnStart : true ,
66+ } ) ;
67+
68+ sessionSubscribe ( session ) ;
69+
70+ const response = await page . goto ( `http://localhost:${ port } /` , {
5571 waitUntil : "networkidle0" ,
5672 } ) ;
5773
@@ -60,6 +76,8 @@ describe("client option", () => {
6076
6177 expect ( response . status ( ) ) . toMatchSnapshot ( "response status" ) ;
6278
79+ expect ( webSocketRequests ) . toMatchSnapshot ( "webSockets" ) ;
80+
6381 expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
6482 "console messages" ,
6583 ) ;
@@ -119,14 +137,26 @@ describe("client option", () => {
119137 pageErrors . push ( error ) ;
120138 } ) ;
121139
122- const response = await page . goto (
123- `http://localhost:${ port } /foo/test/bar` ,
124- {
125- waitUntil : "networkidle0" ,
126- } ,
127- ) ;
140+ const webSocketRequests = [ ] ;
141+ const session = await page . target ( ) . createCDPSession ( ) ;
128142
129- expect ( response . status ( ) ) . toMatchSnapshot ( "response status" ) ;
143+ session . on ( "Network.webSocketCreated" , ( test ) => {
144+ webSocketRequests . push ( test ) ;
145+ } ) ;
146+
147+ await session . send ( "Target.setAutoAttach" , {
148+ autoAttach : true ,
149+ flatten : true ,
150+ waitForDebuggerOnStart : true ,
151+ } ) ;
152+
153+ sessionSubscribe ( session ) ;
154+
155+ await page . goto ( `http://localhost:${ port } /` , {
156+ waitUntil : "networkidle0" ,
157+ } ) ;
158+
159+ expect ( webSocketRequests ) . toMatchSnapshot ( "webSockets" ) ;
130160
131161 expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
132162 "console messages" ,
@@ -177,10 +207,31 @@ describe("client option", () => {
177207 pageErrors . push ( error ) ;
178208 } ) ;
179209
210+ const webSocketRequests = [ ] ;
211+ const session = await page . target ( ) . createCDPSession ( ) ;
212+
213+ session . on ( "Network.webSocketCreated" , ( test ) => {
214+ webSocketRequests . push ( test ) ;
215+ } ) ;
216+
217+ await session . send ( "Target.setAutoAttach" , {
218+ autoAttach : true ,
219+ flatten : true ,
220+ waitForDebuggerOnStart : true ,
221+ } ) ;
222+
223+ sessionSubscribe ( session ) ;
224+
225+ await page . goto ( `http://localhost:${ port } /` , {
226+ waitUntil : "networkidle0" ,
227+ } ) ;
228+
180229 const response = await page . goto ( `http://localhost:${ port } /main.js` , {
181230 waitUntil : "networkidle0" ,
182231 } ) ;
183232
233+ expect ( webSocketRequests ) . toMatchSnapshot ( "webSockets" ) ;
234+
184235 expect ( response . status ( ) ) . toMatchSnapshot ( "response status" ) ;
185236
186237 expect ( await response . text ( ) ) . not . toMatch ( / c l i e n t \/ i n d e x \. j s / ) ;
0 commit comments