Skip to content

Commit b569b5a

Browse files
committed
fix: allow to open browser with --open-page
1 parent 9b6b5c1 commit b569b5a

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ class Server {
662662
);
663663
}
664664

665-
if (this.options.open) {
665+
if (this.options.open || this.options.openPage) {
666666
runOpen(localUrlForTerminal, this.options, this.logger);
667667
}
668668
}

test/server/open-option.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@ describe('open option', () => {
4242
server.listen(port, 'localhost');
4343
});
4444

45+
it('should work with unspecified open option', (done) => {
46+
const compiler = webpack(config);
47+
const server = new Server(compiler, {
48+
openPage: 'index.html',
49+
port,
50+
static: false,
51+
});
52+
53+
compiler.hooks.done.tap('webpack-dev-server', () => {
54+
server.close(() => {
55+
expect(open.mock.calls[1]).toMatchInlineSnapshot(`
56+
Array [
57+
"http://localhost:8117/index.html",
58+
Object {
59+
"wait": false,
60+
},
61+
]
62+
`);
63+
done();
64+
});
65+
});
66+
67+
compiler.run(() => {});
68+
server.listen(port, 'localhost');
69+
});
70+
4571
it('should work with "0.0.0.0" host', (done) => {
4672
const compiler = webpack(config);
4773
const server = new Server(compiler, {

test/server/utils/runOpen.test.js

+18
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,24 @@ describe('runOpen util', () => {
119119
`);
120120
}));
121121

122+
it('on specify URL with openPage option only ', () =>
123+
runOpen('https://example.com', { openPage: '/index.html' }, console).then(
124+
() => {
125+
expect(open).toBeCalledWith('https://example.com/index.html', {
126+
wait: false,
127+
});
128+
129+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
130+
Array [
131+
"https://example.com/index.html",
132+
Object {
133+
"wait": false,
134+
},
135+
]
136+
`);
137+
}
138+
));
139+
122140
it('on specify absolute https URL with page in Google Chrome ', () =>
123141
runOpen(
124142
'https://example.com',

0 commit comments

Comments
 (0)