Skip to content

Commit

Permalink
chore: fix tests (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroppy committed Dec 23, 2019
1 parent 25447ea commit f7b7e4d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 15 deletions.
116 changes: 116 additions & 0 deletions test/__snapshots__/Server.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Server addEntries add hot option 1`] = `
Array [
Array [
"client",
"index.js?http:",
"localhost",
],
Array [
"node_modules",
"webpack",
"hot",
"dev-server.js",
],
Array [
"foo.js",
],
]
`;

exports[`Server addEntries add hot option 2`] = `
Array [
HotModuleReplacementPlugin {
"fullBuildTimeout": 200,
"multiStep": undefined,
"options": Object {},
"requestTimeout": 10000,
},
]
`;

exports[`Server addEntries add hotOnly option 1`] = `
Array [
Array [
"client",
"index.js?http:",
"localhost",
],
Array [
"node_modules",
"webpack",
"hot",
"only-dev-server.js",
],
Array [
"foo.js",
],
]
`;

exports[`Server addEntries add hotOnly option 2`] = `
Array [
HotModuleReplacementPlugin {
"fullBuildTimeout": 200,
"multiStep": undefined,
"options": Object {},
"requestTimeout": 10000,
},
]
`;

exports[`Server stats should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors') 1`] = `
Array [
"errors",
"warnings",
"hash",
"assetsByChunkName",
"assets",
"filteredAssets",
]
`;

exports[`Server stats should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors') 2`] = `
Array [
"errors",
"warnings",
"hash",
"assetsByChunkName",
"assets",
"filteredAssets",
]
`;

exports[`Server stats should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors') 3`] = `
Array [
"errors",
"warnings",
"hash",
"assetsByChunkName",
"assets",
"filteredAssets",
]
`;

exports[`Server stats should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors') 4`] = `
Array [
"errors",
"warnings",
"hash",
"assetsByChunkName",
"assets",
"filteredAssets",
]
`;

exports[`Server stats should works with difference stats values (contains 'hash', 'assets', 'warnings' and 'errors') 5`] = `
Array [
"errors",
"warnings",
"hash",
"assetsByChunkName",
"assets",
"filteredAssets",
]
`;
4 changes: 2 additions & 2 deletions test/server/open-option.test.js
Original file line number Diff line number Diff line change
@@ -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
26 changes: 13 additions & 13 deletions test/server/utils/runOpen.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
'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.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -34,7 +34,7 @@ describe('runOpen util', () => {
{ openPage: '/index.html' },
console
).then(() => {
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('runOpen util', () => {
{ open: 'Google Chrome' },
console
).then(() => {
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -90,7 +90,7 @@ describe('runOpen util', () => {
{ open: 'Google Chrome', openPage: '/index.html' },
console
).then(() => {
expect(opn.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('runOpen util', () => {
const logMock = { warn: jest.fn() };

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

afterEach(() => {
Expand All @@ -183,7 +183,7 @@ 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.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -203,7 +203,7 @@ 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.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand All @@ -223,7 +223,7 @@ 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.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com",
Object {
Expand All @@ -244,7 +244,7 @@ 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.mock.calls[0]).toMatchInlineSnapshot(`
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"https://example.com/index.html",
Object {
Expand Down

0 comments on commit f7b7e4d

Please sign in to comment.