@@ -5,6 +5,7 @@ const fs = require("graceful-fs");
55const webpack = require ( "webpack" ) ;
66const Server = require ( "../../lib/Server" ) ;
77const config = require ( "../fixtures/client-config/webpack.config" ) ;
8+ const compile = require ( "../helpers/compile" ) ;
89const HTMLGeneratorPlugin = require ( "../helpers/html-generator-plugin" ) ;
910const runBrowser = require ( "../helpers/run-browser" ) ;
1011const port = require ( "../ports-map" ) . logging ;
@@ -241,4 +242,124 @@ describe("logging", () => {
241242 } ) ;
242243 }
243244 }
245+
246+ describe ( "plugin mode" , ( ) => {
247+ const pluginCases = [
248+ {
249+ title :
250+ "should work and log messages about hot and live reloading is enabled" ,
251+ devServerOptions : {
252+ hot : true ,
253+ } ,
254+ } ,
255+ {
256+ title : "should work and log message about live reloading is enabled" ,
257+ devServerOptions : {
258+ hot : false ,
259+ } ,
260+ } ,
261+ {
262+ title :
263+ "should work and do not log messages about hot and live reloading is enabled" ,
264+ devServerOptions : {
265+ liveReload : false ,
266+ hot : false ,
267+ } ,
268+ } ,
269+ {
270+ title : "should work and log warnings by default" ,
271+ webpackOptions : {
272+ plugins : [
273+ {
274+ apply ( compiler ) {
275+ compiler . hooks . thisCompilation . tap (
276+ "warnings-webpack-plugin" ,
277+ ( compilation ) => {
278+ compilation . warnings . push (
279+ new Error ( "Warning from compilation" ) ,
280+ ) ;
281+ } ,
282+ ) ;
283+ } ,
284+ } ,
285+ new HTMLGeneratorPlugin ( ) ,
286+ ] ,
287+ } ,
288+ } ,
289+ {
290+ title : "should work and log errors by default" ,
291+ webpackOptions : {
292+ plugins : [
293+ {
294+ apply ( compiler ) {
295+ compiler . hooks . thisCompilation . tap (
296+ "warnings-webpack-plugin" ,
297+ ( compilation ) => {
298+ compilation . errors . push (
299+ new Error ( "Error from compilation" ) ,
300+ ) ;
301+ } ,
302+ ) ;
303+ } ,
304+ } ,
305+ new HTMLGeneratorPlugin ( ) ,
306+ ] ,
307+ } ,
308+ } ,
309+ {
310+ title : 'should work when the "client.logging" is "none"' ,
311+ devServerOptions : {
312+ client : {
313+ logging : "none" ,
314+ } ,
315+ } ,
316+ } ,
317+ ] ;
318+
319+ for ( const testCase of pluginCases ) {
320+ it ( `${ testCase . title } ` , async ( ) => {
321+ const compiler = webpack ( { ...config , ...testCase . webpackOptions } ) ;
322+ const devServerOptions = {
323+ port,
324+ ...testCase . devServerOptions ,
325+ } ;
326+ const server = new Server ( devServerOptions ) ;
327+
328+ server . apply ( compiler ) ;
329+
330+ await compile ( compiler , port ) ;
331+
332+ const { page, browser } = await runBrowser ( ) ;
333+
334+ try {
335+ const consoleMessages = [ ] ;
336+
337+ page . on ( "console" , ( message ) => {
338+ consoleMessages . push ( message ) ;
339+ } ) ;
340+
341+ await page . goto ( `http://127.0.0.1:${ port } /` , {
342+ waitUntil : "networkidle0" ,
343+ } ) ;
344+
345+ expect (
346+ consoleMessages . map ( ( message ) =>
347+ message
348+ . text ( )
349+ . replaceAll ( "\\" , "/" )
350+ . replaceAll (
351+ new RegExp ( process . cwd ( ) . replaceAll ( "\\" , "/" ) , "g" ) ,
352+ "<cwd>" ,
353+ ) ,
354+ ) ,
355+ ) . toMatchSnapshot ( ) ;
356+ } finally {
357+ await browser . close ( ) ;
358+ await new Promise ( ( resolve ) => {
359+ compiler . close ( resolve ) ;
360+ } ) ;
361+ }
362+ } ) ;
363+ }
364+ } ) ;
244365} ) ;
0 commit comments