22
33const webpack = require ( "webpack" ) ;
44const Server = require ( "../../lib/Server" ) ;
5- const config = require ( "../fixtures/simple-config-other /webpack.config" ) ;
5+ const config = require ( "../fixtures/provide-plugin-ws-config /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,10 @@ describe("client option", () => {
6076
6177 expect ( response . status ( ) ) . toMatchSnapshot ( "response status" ) ;
6278
79+ expect ( webSocketRequests . map ( ( request ) => request . url ) ) . toMatchSnapshot (
80+ "webSockets" ,
81+ ) ;
82+
6383 expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
6484 "console messages" ,
6585 ) ;
@@ -110,7 +130,7 @@ describe("client option", () => {
110130 await server . stop ( ) ;
111131 } ) ;
112132
113- it ( "responds with a 200 status code for /foo/test/bar path" , async ( ) => {
133+ it ( "responds with a websocket with the /foo/test/bar path" , async ( ) => {
114134 page
115135 . on ( "console" , ( message ) => {
116136 consoleMessages . push ( message ) ;
@@ -119,14 +139,28 @@ describe("client option", () => {
119139 pageErrors . push ( error ) ;
120140 } ) ;
121141
122- const response = await page . goto (
123- `http://localhost:${ port } /foo/test/bar` ,
124- {
125- waitUntil : "networkidle0" ,
126- } ,
127- ) ;
142+ const webSocketRequests = [ ] ;
143+ const session = await page . target ( ) . createCDPSession ( ) ;
128144
129- expect ( response . status ( ) ) . toMatchSnapshot ( "response status" ) ;
145+ session . on ( "Network.webSocketCreated" , ( test ) => {
146+ webSocketRequests . push ( test ) ;
147+ } ) ;
148+
149+ await session . send ( "Target.setAutoAttach" , {
150+ autoAttach : true ,
151+ flatten : true ,
152+ waitForDebuggerOnStart : true ,
153+ } ) ;
154+
155+ sessionSubscribe ( session ) ;
156+
157+ await page . goto ( `http://localhost:${ port } /` , {
158+ waitUntil : "networkidle0" ,
159+ } ) ;
160+
161+ expect ( webSocketRequests . map ( ( request ) => request . url ) ) . toMatchSnapshot (
162+ "webSockets" ,
163+ ) ;
130164
131165 expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
132166 "console messages" ,
@@ -177,10 +211,27 @@ describe("client option", () => {
177211 pageErrors . push ( error ) ;
178212 } ) ;
179213
214+ const webSocketRequests = [ ] ;
215+ const session = await page . target ( ) . createCDPSession ( ) ;
216+
217+ session . on ( "Network.webSocketCreated" , ( test ) => {
218+ webSocketRequests . push ( test ) ;
219+ } ) ;
220+
221+ await session . send ( "Target.setAutoAttach" , {
222+ autoAttach : true ,
223+ flatten : true ,
224+ waitForDebuggerOnStart : true ,
225+ } ) ;
226+
227+ sessionSubscribe ( session ) ;
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