File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 3
3
const { relative, sep } = require ( 'path' ) ;
4
4
const webpack = require ( 'webpack' ) ;
5
5
const request = require ( 'supertest' ) ;
6
+ // Mock opn before loading Server
7
+ jest . mock ( 'opn' ) ;
8
+ // eslint-disable-next-line import/newline-after-import
9
+ const opn = require ( 'opn' ) ;
10
+ opn . mockImplementation ( ( ) => {
11
+ return {
12
+ catch : jest . fn ( ) ,
13
+ } ;
14
+ } ) ;
6
15
const Server = require ( '../lib/Server' ) ;
7
16
const config = require ( './fixtures/simple-config/webpack.config' ) ;
8
17
const helper = require ( './helper' ) ;
@@ -189,6 +198,26 @@ describe('Server', () => {
189
198
server . listen ( 8080 , 'localhost' ) ;
190
199
} ) ;
191
200
} ) ;
201
+
202
+ it ( 'should open' , ( ) => {
203
+ return new Promise ( ( res ) => {
204
+ const compiler = webpack ( config ) ;
205
+ const server = new Server ( compiler , {
206
+ open : true ,
207
+ } ) ;
208
+
209
+ compiler . hooks . done . tap ( 'webpack-dev-server' , ( ) => {
210
+ expect ( opn . mock . calls [ 0 ] ) . toEqual ( [ 'http://localhost:8080/' , { } ] ) ;
211
+ expect ( opn . mock . invocationCallOrder [ 0 ] ) . toEqual ( 1 ) ;
212
+ server . close ( ( ) => {
213
+ res ( ) ;
214
+ } ) ;
215
+ } ) ;
216
+
217
+ compiler . run ( ( ) => { } ) ;
218
+ server . listen ( 8080 , 'localhost' ) ;
219
+ } ) ;
220
+ } ) ;
192
221
} ) ;
193
222
194
223
describe ( 'host' , ( ) => {
You can’t perform that action at this time.
0 commit comments