diff --git a/lib/Server.js b/lib/Server.js index d111dbadd6..db025d6f65 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -662,7 +662,7 @@ class Server { ); } - if (this.options.open) { + if (this.options.open || this.options.openPage) { runOpen(localUrlForTerminal, this.options, this.logger); } } diff --git a/test/server/open-option.test.js b/test/server/open-option.test.js index 1538b24f66..b993f2cf26 100644 --- a/test/server/open-option.test.js +++ b/test/server/open-option.test.js @@ -42,6 +42,32 @@ describe('open option', () => { server.listen(port, 'localhost'); }); + it('should work with unspecified open option', (done) => { + const compiler = webpack(config); + const server = new Server(compiler, { + openPage: 'index.html', + port, + static: false, + }); + + compiler.hooks.done.tap('webpack-dev-server', () => { + server.close(() => { + expect(open.mock.calls[1]).toMatchInlineSnapshot(` + Array [ + "http://localhost:8117/index.html", + Object { + "wait": false, + }, + ] + `); + done(); + }); + }); + + compiler.run(() => {}); + server.listen(port, 'localhost'); + }); + it('should work with "0.0.0.0" host', (done) => { const compiler = webpack(config); const server = new Server(compiler, { diff --git a/test/server/utils/runOpen.test.js b/test/server/utils/runOpen.test.js index 9b102956c7..9e3ea64299 100644 --- a/test/server/utils/runOpen.test.js +++ b/test/server/utils/runOpen.test.js @@ -119,6 +119,24 @@ describe('runOpen util', () => { `); })); + it('on specify URL with openPage option only ', () => + runOpen('https://example.com', { openPage: '/index.html' }, console).then( + () => { + expect(open).toBeCalledWith('https://example.com/index.html', { + wait: false, + }); + + expect(open.mock.calls[0]).toMatchInlineSnapshot(` + Array [ + "https://example.com/index.html", + Object { + "wait": false, + }, + ] + `); + } + )); + it('on specify absolute https URL with page in Google Chrome ', () => runOpen( 'https://example.com',