Skip to content

Commit

Permalink
fix(run-open): introduce open instead of opn (#2532)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy authored and alexander-akait committed May 8, 2020
1 parent 711d7b5 commit fb79bb5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 54 deletions.
2 changes: 1 addition & 1 deletion lib/utils/runOpen.js
@@ -1,6 +1,6 @@
'use strict';

const open = require('opn');
const open = require('open');
const isAbsoluteUrl = require('is-absolute-url');

function runOpen(uri, options, log) {
Expand Down
32 changes: 23 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -52,7 +52,7 @@
"is-absolute-url": "^3.0.3",
"killable": "^1.0.1",
"loglevel": "^1.6.8",
"opn": "^5.5.0",
"open": "^7.0.3",
"p-retry": "^3.0.1",
"portfinder": "^1.0.26",
"schema-utils": "^1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions test/server/open-option.test.js
@@ -1,9 +1,9 @@
'use strict';

jest.mock('opn');
jest.mock('open');

const webpack = require('webpack');
const open = require('opn');
const open = require('open');
const Server = require('../../lib/Server');
const config = require('../fixtures/simple-config/webpack.config');
const port = require('../ports-map')['open-option'];
Expand Down
82 changes: 41 additions & 41 deletions test/server/utils/runOpen.test.js
@@ -1,25 +1,25 @@
'use strict';

const opn = require('opn');
const open = require('open');
const runOpen = require('../../../lib/utils/runOpen');

jest.mock('opn');
jest.mock('open');

describe('runOpen util', () => {
afterEach(() => {
opn.mockClear();
open.mockClear();
});

describe('should open browser', () => {
beforeEach(() => {
opn.mockImplementation(() => Promise.resolve());
open.mockImplementation(() => Promise.resolve());
});

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

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -36,11 +36,11 @@ describe('runOpen util', () => {
{ openPage: '/index.html' },
console
).then(() => {
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
wait: false,
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand All @@ -57,11 +57,11 @@ describe('runOpen util', () => {
{ openPage: ['/index.html'] },
console
).then(() => {
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
wait: false,
});

expect(opn.mock.calls[0]).toMatchSnapshot();
expect(open.mock.calls[0]).toMatchSnapshot();
});
});

Expand All @@ -71,15 +71,15 @@ describe('runOpen util', () => {
{ openPage: ['/index.html', '/index2.html'] },
console
).then(() => {
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
wait: false,
});
expect(opn).toBeCalledWith('https://example.com/index2.html', {
expect(open).toBeCalledWith('https://example.com/index2.html', {
wait: false,
});

expect(opn.mock.calls[0]).toMatchSnapshot();
expect(opn.mock.calls[1]).toMatchSnapshot();
expect(open.mock.calls[0]).toMatchSnapshot();
expect(open.mock.calls[1]).toMatchSnapshot();
});
});

Expand All @@ -89,12 +89,12 @@ describe('runOpen util', () => {
{ open: 'Google Chrome' },
console
).then(() => {
expect(opn).toBeCalledWith('https://example.com', {
expect(open).toBeCalledWith('https://example.com', {
app: 'Google Chrome',
wait: false,
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -112,12 +112,12 @@ describe('runOpen util', () => {
{ open: 'Google Chrome', openPage: '/index.html' },
console
).then(() => {
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
app: 'Google Chrome',
wait: false,
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand All @@ -135,12 +135,12 @@ describe('runOpen util', () => {
{ open: 'Google Chrome', openPage: 'https://example2.com' },
console
).then(() => {
expect(opn).toBeCalledWith('https://example2.com', {
expect(open).toBeCalledWith('https://example2.com', {
app: 'Google Chrome',
wait: false,
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example2.com",
Object {
Expand All @@ -158,11 +158,11 @@ describe('runOpen util', () => {
{ open: 'Google Chrome', openPage: 'http://example2.com' },
console
).then(() => {
expect(opn).toBeCalledWith('http://example2.com', {
expect(open).toBeCalledWith('http://example2.com', {
app: 'Google Chrome',
wait: false,
});
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"http://example2.com",
Object {
Expand All @@ -184,16 +184,16 @@ describe('runOpen util', () => {
},
console
).then(() => {
expect(opn).toBeCalledWith('https://example2.com', {
expect(open).toBeCalledWith('https://example2.com', {
app: 'Google Chrome',
wait: false,
});
expect(opn).toBeCalledWith('https://example3.com', {
expect(open).toBeCalledWith('https://example3.com', {
app: 'Google Chrome',
wait: false,
});
expect(opn.mock.calls[0]).toMatchSnapshot();
expect(opn.mock.calls[1]).toMatchSnapshot();
expect(open.mock.calls[0]).toMatchSnapshot();
expect(open.mock.calls[1]).toMatchSnapshot();
});
});

Expand All @@ -206,25 +206,25 @@ describe('runOpen util', () => {
},
console
).then(() => {
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
app: 'Google Chrome',
wait: false,
});
expect(opn).toBeCalledWith('https://example2.com', {
expect(open).toBeCalledWith('https://example2.com', {
app: 'Google Chrome',
wait: false,
});

expect(opn.mock.calls[0]).toMatchSnapshot();
expect(opn.mock.calls[1]).toMatchSnapshot();
expect(open.mock.calls[0]).toMatchSnapshot();
expect(open.mock.calls[1]).toMatchSnapshot();
});
});

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

beforeEach(() => {
opn.mockImplementation(() => Promise.reject());
open.mockImplementation(() => Promise.reject());
});

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

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -258,11 +258,11 @@ describe('runOpen util', () => {
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"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"`
);
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
wait: false,
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand All @@ -282,12 +282,12 @@ describe('runOpen util', () => {
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"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"`
);
expect(opn).toBeCalledWith('https://example.com', {
expect(open).toBeCalledWith('https://example.com', {
app: 'Google Chrome',
wait: false,
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -308,12 +308,12 @@ describe('runOpen util', () => {
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"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"`
);
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
app: 'Google Chrome',
wait: false,
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand All @@ -334,11 +334,11 @@ describe('runOpen util', () => {
},
logMock
).then(() => {
expect(opn).toBeCalledWith('https://example.com/index.html', {
expect(open).toBeCalledWith('https://example.com/index.html', {
app: ['Google Chrome', '--incognito'],
});

expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand Down

0 comments on commit fb79bb5

Please sign in to comment.