22
33const os = require ( "node:os" ) ;
44const path = require ( "node:path" ) ;
5+ const { describe, it } = require ( "node:test" ) ;
6+ const { expect } = require ( "expect" ) ;
7+ const { spyOn } = require ( "jest-mock" ) ;
58const webpack = require ( "webpack" ) ;
69const WebSocket = require ( "ws" ) ;
710const Server = require ( "../../lib/Server" ) ;
@@ -13,7 +16,7 @@ const port = require("../ports-map")["api-plugin"];
1316const [ portA , portB ] = require ( "../ports-map" ) [ "api-plugin-multi" ] ;
1417
1518describe ( "API (plugin)" , ( ) => {
16- it ( "should work with plugin API" , async ( ) => {
19+ it ( "should work with plugin API" , async ( t ) => {
1720 const compiler = webpack ( config ) ;
1821 const server = new Server ( { port } ) ;
1922
@@ -38,10 +41,8 @@ describe("API (plugin)", () => {
3841 waitUntil : "networkidle0" ,
3942 } ) ;
4043
41- expect ( consoleMessages . map ( ( message ) => message . text ( ) ) ) . toMatchSnapshot (
42- "console messages" ,
43- ) ;
44- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
44+ t . assert . snapshot ( consoleMessages . map ( ( message ) => message . text ( ) ) ) ;
45+ t . assert . snapshot ( pageErrors ) ;
4546
4647 await browser . close ( ) ;
4748 await new Promise ( ( resolve ) => {
@@ -52,8 +53,8 @@ describe("API (plugin)", () => {
5253 it ( "should not start the server multiple times on recompilation" , async ( ) => {
5354 const compiler = webpack ( config ) ;
5455 const server = new Server ( { port } ) ;
55- const setupSpy = jest . spyOn ( server , "setup" ) ;
56- const listenSpy = jest . spyOn ( server , "listen" ) ;
56+ const setupSpy = spyOn ( server , "setup" ) ;
57+ const listenSpy = spyOn ( server , "listen" ) ;
5758
5859 server . apply ( compiler ) ;
5960
@@ -84,7 +85,7 @@ describe("API (plugin)", () => {
8485 it ( "should stop the server cleanly via compiler.close()" , async ( ) => {
8586 const compiler = webpack ( config ) ;
8687 const server = new Server ( { port } ) ;
87- const stopSpy = jest . spyOn ( server , "stop" ) ;
88+ const stopSpy = spyOn ( server , "stop" ) ;
8889
8990 server . apply ( compiler ) ;
9091
@@ -110,8 +111,8 @@ describe("API (plugin)", () => {
110111 } ,
111112 } ) ;
112113 const server = new Server ( { port } ) ;
113- const setupSpy = jest . spyOn ( server , "setup" ) ;
114- const listenSpy = jest . spyOn ( server , "listen" ) ;
114+ const setupSpy = spyOn ( server , "setup" ) ;
115+ const listenSpy = spyOn ( server , "listen" ) ;
115116
116117 server . apply ( compiler ) ;
117118
@@ -239,7 +240,7 @@ describe("API (plugin)", () => {
239240 } ) ;
240241
241242 describe ( "plugin in webpack config" , ( ) => {
242- it ( "should work when added to webpack config plugins array" , async ( ) => {
243+ it ( "should work when added to webpack config plugins array" , async ( t ) => {
243244 const server = new Server ( { port } ) ;
244245 const compiler = webpack ( {
245246 ...config ,
@@ -266,10 +267,8 @@ describe("API (plugin)", () => {
266267 waitUntil : "networkidle0" ,
267268 } ) ;
268269
269- expect (
270- consoleMessages . map ( ( message ) => message . text ( ) ) ,
271- ) . toMatchSnapshot ( "console messages" ) ;
272- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
270+ t . assert . snapshot ( consoleMessages . map ( ( message ) => message . text ( ) ) ) ;
271+ t . assert . snapshot ( pageErrors ) ;
273272 } finally {
274273 await browser . close ( ) ;
275274 await new Promise ( ( resolve ) => {
@@ -278,7 +277,7 @@ describe("API (plugin)", () => {
278277 }
279278 } ) ;
280279
281- it ( "should work with output.clean: true" , async ( ) => {
280+ it ( "should work with output.clean: true" , async ( t ) => {
282281 const server = new Server ( { port } ) ;
283282 const compiler = webpack ( {
284283 ...config ,
@@ -310,10 +309,8 @@ describe("API (plugin)", () => {
310309 } ) ;
311310
312311 expect ( response . status ( ) ) . toBe ( 200 ) ;
313- expect (
314- consoleMessages . map ( ( message ) => message . text ( ) ) ,
315- ) . toMatchSnapshot ( "console messages" ) ;
316- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
312+ t . assert . snapshot ( consoleMessages . map ( ( message ) => message . text ( ) ) ) ;
313+ t . assert . snapshot ( pageErrors ) ;
317314 } finally {
318315 await browser . close ( ) ;
319316 await new Promise ( ( resolve ) => {
@@ -324,7 +321,7 @@ describe("API (plugin)", () => {
324321 } ) ;
325322
326323 describe ( "MultiCompiler" , ( ) => {
327- it ( "should work with plugin API" , async ( ) => {
324+ it ( "should work with plugin API" , async ( t ) => {
328325 const compiler = webpack ( multiCompilerConfig ) ;
329326 const server = new Server ( { port } ) ;
330327
@@ -354,10 +351,8 @@ describe("API (plugin)", () => {
354351 ) ;
355352
356353 expect ( response . status ( ) ) . toBe ( 200 ) ;
357- expect (
358- consoleMessages . map ( ( message ) => message . text ( ) ) ,
359- ) . toMatchSnapshot ( "console messages" ) ;
360- expect ( pageErrors ) . toMatchSnapshot ( "page errors" ) ;
354+ t . assert . snapshot ( consoleMessages . map ( ( message ) => message . text ( ) ) ) ;
355+ t . assert . snapshot ( pageErrors ) ;
361356 } finally {
362357 await browser . close ( ) ;
363358 await new Promise ( ( resolve ) => {
@@ -369,8 +364,8 @@ describe("API (plugin)", () => {
369364 it ( "should call setup and listen once across all child compilers" , async ( ) => {
370365 const compiler = webpack ( multiCompilerConfig ) ;
371366 const server = new Server ( { port } ) ;
372- const setupSpy = jest . spyOn ( server , "setup" ) ;
373- const listenSpy = jest . spyOn ( server , "listen" ) ;
367+ const setupSpy = spyOn ( server , "setup" ) ;
368+ const listenSpy = spyOn ( server , "listen" ) ;
374369
375370 server . apply ( compiler ) ;
376371
@@ -389,7 +384,7 @@ describe("API (plugin)", () => {
389384 it ( "should stop the server only once when all child compilers shut down" , async ( ) => {
390385 const compiler = webpack ( multiCompilerConfig ) ;
391386 const server = new Server ( { port } ) ;
392- const stopSpy = jest . spyOn ( server , "stop" ) ;
387+ const stopSpy = spyOn ( server , "stop" ) ;
393388
394389 server . apply ( compiler ) ;
395390
0 commit comments