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 Jun 8, 2019
1 parent dfe1a4f commit 4558b1e
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 29 deletions.
2 changes: 0 additions & 2 deletions client-src/clients/BaseClient.js
@@ -1,5 +1,3 @@
'use strict';

/* eslint-disable
no-unused-vars
*/
Expand Down
2 changes: 0 additions & 2 deletions client-src/clients/SockJSClient.js
@@ -1,5 +1,3 @@
'use strict';

/* eslint-disable
no-unused-vars
*/
Expand Down
2 changes: 0 additions & 2 deletions client-src/clients/WebsocketClient.js
@@ -1,5 +1,3 @@
'use strict';

const BaseClient = require('./BaseClient');

module.exports = class WebsocketClient extends BaseClient {};
116 changes: 116 additions & 0 deletions test/__snapshots__/Server.test.js.snap
@@ -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",
]
`;
2 changes: 1 addition & 1 deletion test/client/utils/createSocketUrl.test.js
Expand Up @@ -24,7 +24,7 @@ describe('createSocketUrl', () => {
const {
default: createSocketUrl,
// eslint-disable-next-line global-require
} = require('../../../../client-src/default/utils/createSocketUrl');
} = require('../../../client-src/default/utils/createSocketUrl');

test(`should return the url when __resourceQuery is ${url}`, () => {
expect(createSocketUrl(url)).toMatchSnapshot();
Expand Down
2 changes: 1 addition & 1 deletion test/client/utils/getCurrentScriptSource.test.js
Expand Up @@ -2,7 +2,7 @@

const {
default: getCurrentScriptSource,
} = require('../../../../client-src/default/utils/getCurrentScriptSource');
} = require('../../../client-src/default/utils/getCurrentScriptSource');

describe('getCurrentScriptSource', () => {
afterEach(() => {
Expand Down
3 changes: 1 addition & 2 deletions test/client/utils/reloadApp.test.js
Expand Up @@ -25,8 +25,7 @@ describe('reloadApp', () => {
});

// eslint-disable-next-line global-require
reloadApp = require('../../../../client-src/default/utils/reloadApp')
.default;
reloadApp = require('../../../client-src/default/utils/reloadApp').default;
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/client/utils/sendMessage.test.js
Expand Up @@ -4,7 +4,7 @@

const {
default: sendMessage,
} = require('../../../../client-src/default/utils/sendMessage');
} = require('../../../client-src/default/utils/sendMessage');

describe('sendMessage', () => {
afterEach(() => {
Expand Down
10 changes: 5 additions & 5 deletions test/server/open-option.test.js
@@ -1,13 +1,13 @@
'use strict';

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

const webpack = require('webpack');
const opn = require('opn');
const open = require('open');
const Server = require('../../lib/Server');
const config = require('../fixtures/simple-config/webpack.config');

opn.mockImplementation(() => {
open.mockImplementation(() => {
return {
catch: jest.fn(),
};
Expand All @@ -21,8 +21,8 @@ describe('open option', () => {
});

compiler.hooks.done.tap('webpack-dev-server', () => {
expect(opn.mock.calls[0]).toEqual(['http://localhost:8080/', {}]);
expect(opn.mock.invocationCallOrder[0]).toEqual(1);
expect(open.mock.calls[0]).toEqual(['http://localhost:8080/', {}]);
expect(open.mock.invocationCallOrder[0]).toEqual(1);
server.close(done);
});

Expand Down
26 changes: 13 additions & 13 deletions test/server/utils/runOpen.test.js
@@ -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]).toEqual(['https://example.com', {}]);
expect(open.mock.calls[0]).toEqual(['https://example.com', {}]);
});
});

Expand All @@ -27,7 +27,7 @@ describe('runOpen util', () => {
{ openPage: '/index.html' },
console
).then(() => {
expect(opn.mock.calls[0]).toEqual([
expect(open.mock.calls[0]).toEqual([
'https://example.com/index.html',
{},
]);
Expand All @@ -40,7 +40,7 @@ describe('runOpen util', () => {
{ open: 'Google Chrome' },
console
).then(() => {
expect(opn.mock.calls[0]).toEqual([
expect(open.mock.calls[0]).toEqual([
'https://example.com',
{ app: 'Google Chrome' },
]);
Expand All @@ -53,7 +53,7 @@ describe('runOpen util', () => {
{ open: 'Google Chrome', openPage: '/index.html' },
console
).then(() => {
expect(opn.mock.calls[0]).toEqual([
expect(open.mock.calls[0]).toEqual([
'https://example.com/index.html',
{ app: 'Google Chrome' },
]);
Expand All @@ -65,7 +65,7 @@ describe('runOpen util', () => {
const logMock = { warn: jest.fn() };

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

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

Expand All @@ -90,7 +90,7 @@ describe('runOpen util', () => {
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"Unable to open browser. If you are running in a headless environment, please do not use the --open flag"`
);
expect(opn.mock.calls[0]).toEqual([
expect(open.mock.calls[0]).toEqual([
'https://example.com/index.html',
{},
]);
Expand All @@ -106,7 +106,7 @@ describe('runOpen util', () => {
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"Unable to open browser: Google Chrome. If you are running in a headless environment, please do not use the --open flag"`
);
expect(opn.mock.calls[0]).toEqual([
expect(open.mock.calls[0]).toEqual([
'https://example.com',
{
app: 'Google Chrome',
Expand All @@ -124,7 +124,7 @@ describe('runOpen util', () => {
expect(logMock.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"Unable to open browser: Google Chrome. If you are running in a headless environment, please do not use the --open flag"`
);
expect(opn.mock.calls[0]).toEqual([
expect(open.mock.calls[0]).toEqual([
'https://example.com/index.html',
{ app: 'Google Chrome' },
]);
Expand Down

0 comments on commit 4558b1e

Please sign in to comment.