Skip to content

Commit

Permalink
fix: allow to open browser with --open-page (#3032)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Feb 20, 2021
1 parent 500283e commit 581ee07
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Server.js
Expand Up @@ -662,7 +662,7 @@ class Server {
);
}

if (this.options.open) {
if (this.options.open || this.options.openPage) {
runOpen(localUrlForTerminal, this.options, this.logger);
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/server/open-option.test.js
Expand Up @@ -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, {
Expand Down
18 changes: 18 additions & 0 deletions test/server/utils/runOpen.test.js
Expand Up @@ -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',
Expand Down

0 comments on commit 581ee07

Please sign in to comment.