Skip to content

Commit 990fcfb

Browse files
committed
test(Server): add tests for open option
1 parent 07a5e9f commit 990fcfb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/Server.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
const { relative, sep } = require('path');
44
const webpack = require('webpack');
55
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+
});
615
const Server = require('../lib/Server');
716
const config = require('./fixtures/simple-config/webpack.config');
817
const helper = require('./helper');
@@ -189,6 +198,26 @@ describe('Server', () => {
189198
server.listen(8080, 'localhost');
190199
});
191200
});
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+
});
192221
});
193222

194223
describe('host', () => {

0 commit comments

Comments
 (0)