Skip to content

Commit 21c1f14

Browse files
committed
fix(run-open): introduce open instead of opn
1 parent 776e7d4 commit 21c1f14

File tree

5 files changed

+68
-54
lines changed

5 files changed

+68
-54
lines changed

lib/utils/runOpen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const open = require('opn');
3+
const open = require('open');
44
const isAbsoluteUrl = require('is-absolute-url');
55

66
function runOpen(uri, options, log) {

package-lock.json

Lines changed: 23 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"is-absolute-url": "^3.0.3",
5353
"killable": "^1.0.1",
5454
"loglevel": "^1.6.8",
55-
"opn": "^5.5.0",
55+
"open": "^7.0.3",
5656
"p-retry": "^3.0.1",
5757
"portfinder": "^1.0.25",
5858
"schema-utils": "^1.0.0",

test/server/open-option.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

3-
jest.mock('opn');
3+
jest.mock('open');
44

55
const webpack = require('webpack');
6-
const open = require('opn');
6+
const open = require('open');
77
const Server = require('../../lib/Server');
88
const config = require('../fixtures/simple-config/webpack.config');
99
const port = require('../ports-map')['open-option'];

test/server/utils/runOpen.test.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
'use strict';
22

3-
const opn = require('opn');
3+
const open = require('open');
44
const runOpen = require('../../../lib/utils/runOpen');
55

6-
jest.mock('opn');
6+
jest.mock('open');
77

88
describe('runOpen util', () => {
99
afterEach(() => {
10-
opn.mockClear();
10+
open.mockClear();
1111
});
1212

1313
describe('should open browser', () => {
1414
beforeEach(() => {
15-
opn.mockImplementation(() => Promise.resolve());
15+
open.mockImplementation(() => Promise.resolve());
1616
});
1717

1818
it('on specify URL', () => {
1919
return runOpen('https://example.com', {}, console).then(() => {
20-
expect(opn).toBeCalledWith('https://example.com', { wait: false });
20+
expect(open).toBeCalledWith('https://example.com', { wait: false });
2121

22-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
22+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
2323
Array [
2424
"https://example.com",
2525
Object {
@@ -36,11 +36,11 @@ describe('runOpen util', () => {
3636
{ openPage: '/index.html' },
3737
console
3838
).then(() => {
39-
expect(opn).toBeCalledWith('https://example.com/index.html', {
39+
expect(open).toBeCalledWith('https://example.com/index.html', {
4040
wait: false,
4141
});
4242

43-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
43+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
4444
Array [
4545
"https://example.com/index.html",
4646
Object {
@@ -57,11 +57,11 @@ describe('runOpen util', () => {
5757
{ openPage: ['/index.html'] },
5858
console
5959
).then(() => {
60-
expect(opn).toBeCalledWith('https://example.com/index.html', {
60+
expect(open).toBeCalledWith('https://example.com/index.html', {
6161
wait: false,
6262
});
6363

64-
expect(opn.mock.calls[0]).toMatchSnapshot();
64+
expect(open.mock.calls[0]).toMatchSnapshot();
6565
});
6666
});
6767

@@ -71,15 +71,15 @@ describe('runOpen util', () => {
7171
{ openPage: ['/index.html', '/index2.html'] },
7272
console
7373
).then(() => {
74-
expect(opn).toBeCalledWith('https://example.com/index.html', {
74+
expect(open).toBeCalledWith('https://example.com/index.html', {
7575
wait: false,
7676
});
77-
expect(opn).toBeCalledWith('https://example.com/index2.html', {
77+
expect(open).toBeCalledWith('https://example.com/index2.html', {
7878
wait: false,
7979
});
8080

81-
expect(opn.mock.calls[0]).toMatchSnapshot();
82-
expect(opn.mock.calls[1]).toMatchSnapshot();
81+
expect(open.mock.calls[0]).toMatchSnapshot();
82+
expect(open.mock.calls[1]).toMatchSnapshot();
8383
});
8484
});
8585

@@ -89,12 +89,12 @@ describe('runOpen util', () => {
8989
{ open: 'Google Chrome' },
9090
console
9191
).then(() => {
92-
expect(opn).toBeCalledWith('https://example.com', {
92+
expect(open).toBeCalledWith('https://example.com', {
9393
app: 'Google Chrome',
9494
wait: false,
9595
});
9696

97-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
97+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
9898
Array [
9999
"https://example.com",
100100
Object {
@@ -112,12 +112,12 @@ describe('runOpen util', () => {
112112
{ open: 'Google Chrome', openPage: '/index.html' },
113113
console
114114
).then(() => {
115-
expect(opn).toBeCalledWith('https://example.com/index.html', {
115+
expect(open).toBeCalledWith('https://example.com/index.html', {
116116
app: 'Google Chrome',
117117
wait: false,
118118
});
119119

120-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
120+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
121121
Array [
122122
"https://example.com/index.html",
123123
Object {
@@ -135,12 +135,12 @@ describe('runOpen util', () => {
135135
{ open: 'Google Chrome', openPage: 'https://example2.com' },
136136
console
137137
).then(() => {
138-
expect(opn).toBeCalledWith('https://example2.com', {
138+
expect(open).toBeCalledWith('https://example2.com', {
139139
app: 'Google Chrome',
140140
wait: false,
141141
});
142142

143-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
143+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
144144
Array [
145145
"https://example2.com",
146146
Object {
@@ -158,11 +158,11 @@ describe('runOpen util', () => {
158158
{ open: 'Google Chrome', openPage: 'http://example2.com' },
159159
console
160160
).then(() => {
161-
expect(opn).toBeCalledWith('http://example2.com', {
161+
expect(open).toBeCalledWith('http://example2.com', {
162162
app: 'Google Chrome',
163163
wait: false,
164164
});
165-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
165+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
166166
Array [
167167
"http://example2.com",
168168
Object {
@@ -184,16 +184,16 @@ describe('runOpen util', () => {
184184
},
185185
console
186186
).then(() => {
187-
expect(opn).toBeCalledWith('https://example2.com', {
187+
expect(open).toBeCalledWith('https://example2.com', {
188188
app: 'Google Chrome',
189189
wait: false,
190190
});
191-
expect(opn).toBeCalledWith('https://example3.com', {
191+
expect(open).toBeCalledWith('https://example3.com', {
192192
app: 'Google Chrome',
193193
wait: false,
194194
});
195-
expect(opn.mock.calls[0]).toMatchSnapshot();
196-
expect(opn.mock.calls[1]).toMatchSnapshot();
195+
expect(open.mock.calls[0]).toMatchSnapshot();
196+
expect(open.mock.calls[1]).toMatchSnapshot();
197197
});
198198
});
199199

@@ -206,25 +206,25 @@ describe('runOpen util', () => {
206206
},
207207
console
208208
).then(() => {
209-
expect(opn).toBeCalledWith('https://example.com/index.html', {
209+
expect(open).toBeCalledWith('https://example.com/index.html', {
210210
app: 'Google Chrome',
211211
wait: false,
212212
});
213-
expect(opn).toBeCalledWith('https://example2.com', {
213+
expect(open).toBeCalledWith('https://example2.com', {
214214
app: 'Google Chrome',
215215
wait: false,
216216
});
217217

218-
expect(opn.mock.calls[0]).toMatchSnapshot();
219-
expect(opn.mock.calls[1]).toMatchSnapshot();
218+
expect(open.mock.calls[0]).toMatchSnapshot();
219+
expect(open.mock.calls[1]).toMatchSnapshot();
220220
});
221221
});
222222

223223
describe('should not open browser', () => {
224224
const logMock = { warn: jest.fn() };
225225

226226
beforeEach(() => {
227-
opn.mockImplementation(() => Promise.reject());
227+
open.mockImplementation(() => Promise.reject());
228228
});
229229

230230
afterEach(() => {
@@ -236,9 +236,9 @@ describe('runOpen util', () => {
236236
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
237237
`"Unable to open \\"https://example.com\\" in browser. If you are running in a headless environment, please do not use the --open flag"`
238238
);
239-
expect(opn).toBeCalledWith('https://example.com', { wait: false });
239+
expect(open).toBeCalledWith('https://example.com', { wait: false });
240240

241-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
241+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
242242
Array [
243243
"https://example.com",
244244
Object {
@@ -258,11 +258,11 @@ describe('runOpen util', () => {
258258
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
259259
`"Unable to open \\"https://example.com/index.html\\" in browser. If you are running in a headless environment, please do not use the --open flag"`
260260
);
261-
expect(opn).toBeCalledWith('https://example.com/index.html', {
261+
expect(open).toBeCalledWith('https://example.com/index.html', {
262262
wait: false,
263263
});
264264

265-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
265+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
266266
Array [
267267
"https://example.com/index.html",
268268
Object {
@@ -282,12 +282,12 @@ describe('runOpen util', () => {
282282
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
283283
`"Unable to open \\"https://example.com\\" in browser: \\"Google Chrome\\". If you are running in a headless environment, please do not use the --open flag"`
284284
);
285-
expect(opn).toBeCalledWith('https://example.com', {
285+
expect(open).toBeCalledWith('https://example.com', {
286286
app: 'Google Chrome',
287287
wait: false,
288288
});
289289

290-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
290+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
291291
Array [
292292
"https://example.com",
293293
Object {
@@ -308,12 +308,12 @@ describe('runOpen util', () => {
308308
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
309309
`"Unable to open \\"https://example.com/index.html\\" in browser: \\"Google Chrome\\". If you are running in a headless environment, please do not use the --open flag"`
310310
);
311-
expect(opn).toBeCalledWith('https://example.com/index.html', {
311+
expect(open).toBeCalledWith('https://example.com/index.html', {
312312
app: 'Google Chrome',
313313
wait: false,
314314
});
315315

316-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
316+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
317317
Array [
318318
"https://example.com/index.html",
319319
Object {
@@ -334,11 +334,11 @@ describe('runOpen util', () => {
334334
},
335335
logMock
336336
).then(() => {
337-
expect(opn).toBeCalledWith('https://example.com/index.html', {
337+
expect(open).toBeCalledWith('https://example.com/index.html', {
338338
app: ['Google Chrome', '--incognito'],
339339
});
340340

341-
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
341+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
342342
Array [
343343
"https://example.com/index.html",
344344
Object {

0 commit comments

Comments
 (0)