File tree Expand file tree Collapse file tree 4 files changed +41
-0
lines changed Expand file tree Collapse file tree 4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ const SyncHook = require ( 'tapable' ) . SyncHook ;
2+
3+ module . exports = {
4+ devServerRunning : new SyncHook ( ) ,
5+ } ;
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ const clientConfig = require('./webpack-client-config');
1010const serverConfig = require ( './webpack-server-config' ) ;
1111const transformConfig = require ( './transform-config' ) ;
1212const { error, isDir, warn } = require ( '../../util' ) ;
13+ const { devServerRunning } = require ( './hooks' ) ;
1314
1415async function devBuild ( env ) {
1516 let userPort = parseInt ( process . env . PORT || env . port , 10 ) || 8080 ;
@@ -68,6 +69,7 @@ async function devBuild(env) {
6869 }
6970
7071 showStats ( stats , false ) ;
72+ devServerRunning . call ( ) ;
7173 } ) ;
7274
7375 compiler . hooks . failed . tap ( 'CliDevPlugin' , rej ) ;
Original file line number Diff line number Diff line change 1+ const { create, watch } = require ( './lib/cli' ) ;
2+ const { hooks } = require ( './lib/utils' ) ;
3+
4+ describe ( 'preact' , ( ) => {
5+ let intervalId ;
6+
7+ afterEach ( ( ) => {
8+ clearInterval ( intervalId ) ;
9+ intervalId = null ;
10+ } ) ;
11+
12+ it ( 'should emit a devServerRunning event after the server starts' , ( done ) => {
13+ let hookCalled ;
14+ hooks . devServerRunning . tap ( 'TestPlugin' , ( ) => {
15+ hookCalled = true ;
16+ } ) ;
17+
18+ create ( 'default' ) . then ( ( app ) => {
19+ watch ( app , 8083 ) . then ( ( server ) => {
20+ // We need to wait not only for the server to start but also for the
21+ // stats to be printed to stdout.
22+ intervalId = setInterval ( ( ) => {
23+ if ( hookCalled ) {
24+ expect ( hookCalled ) . toBe ( true ) ;
25+ server . close ( ) ;
26+ done ( ) ;
27+ }
28+ } , 1000 ) ;
29+ } ) ;
30+ } ) ;
31+ } ) ;
32+ } ) ;
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const minimatch = require('minimatch');
55const pRetry = require ( 'p-retry' ) ;
66const { promisify } = require ( 'util' ) ;
77const glob = promisify ( require ( 'glob' ) . glob ) ;
8+ const hooks = require ( '../../lib/lib/webpack/hooks' ) ;
89
910const PER = 0.05 ; // % diff
1011const LOG = ! ! process . env . WITH_LOG ;
@@ -68,4 +69,5 @@ module.exports = {
6869 sleep,
6970 hasKey,
7071 isWithin,
72+ hooks,
7173} ;
You can’t perform that action at this time.
0 commit comments