From 5815cd217b8e60a01846dc9c7e699a65f8f46e02 Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Sat, 8 Jun 2019 13:46:20 +0200 Subject: [PATCH] chore: fix tests (#1997) --- client-src/clients/BaseClient.js | 2 - client-src/clients/SockJSClient.js | 2 - test/__snapshots__/Server.test.js.snap | 116 ++++++++++++++++++ .../utils/getCurrentScriptSource.test.js | 2 +- test/client/utils/sendMessage.test.js | 2 +- test/server/open-option.test.js | 4 +- test/server/utils/runOpen.test.js | 26 ++-- 7 files changed, 133 insertions(+), 21 deletions(-) create mode 100644 test/__snapshots__/Server.test.js.snap diff --git a/client-src/clients/BaseClient.js b/client-src/clients/BaseClient.js index 1dfa65911b..7c47b70e2a 100644 --- a/client-src/clients/BaseClient.js +++ b/client-src/clients/BaseClient.js @@ -1,5 +1,3 @@ -'use strict'; - /* eslint-disable no-unused-vars */ diff --git a/client-src/clients/SockJSClient.js b/client-src/clients/SockJSClient.js index 388c25fef1..5824bc9af9 100644 --- a/client-src/clients/SockJSClient.js +++ b/client-src/clients/SockJSClient.js @@ -1,5 +1,3 @@ -'use strict'; - /* eslint-disable no-unused-vars */ diff --git a/test/__snapshots__/Server.test.js.snap b/test/__snapshots__/Server.test.js.snap new file mode 100644 index 0000000000..afd2139df5 --- /dev/null +++ b/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", +] +`; diff --git a/test/client/utils/getCurrentScriptSource.test.js b/test/client/utils/getCurrentScriptSource.test.js index e7ec05aceb..b6c4f4d017 100644 --- a/test/client/utils/getCurrentScriptSource.test.js +++ b/test/client/utils/getCurrentScriptSource.test.js @@ -2,7 +2,7 @@ const { default: getCurrentScriptSource, -} = require('../../../../client-src/default/utils/getCurrentScriptSource'); +} = require('../../../client-src/default/utils/getCurrentScriptSource'); describe('getCurrentScriptSource', () => { afterEach(() => { diff --git a/test/client/utils/sendMessage.test.js b/test/client/utils/sendMessage.test.js index fd8ecbd315..17cbb4ea61 100644 --- a/test/client/utils/sendMessage.test.js +++ b/test/client/utils/sendMessage.test.js @@ -4,7 +4,7 @@ const { default: sendMessage, -} = require('../../../../client-src/default/utils/sendMessage'); +} = require('../../../client-src/default/utils/sendMessage'); describe('sendMessage', () => { afterEach(() => { diff --git a/test/server/open-option.test.js b/test/server/open-option.test.js index 9eeb8d3cd8..01f7d88b8a 100644 --- a/test/server/open-option.test.js +++ b/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']; diff --git a/test/server/utils/runOpen.test.js b/test/server/utils/runOpen.test.js index e6fa3b155a..d8c258008d 100644 --- a/test/server/utils/runOpen.test.js +++ b/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]).toMatchInlineSnapshot(` + expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ "https://example.com", Object { @@ -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 { @@ -51,7 +51,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 { @@ -69,7 +69,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 { @@ -122,7 +122,7 @@ describe('runOpen util', () => { const logMock = { warn: jest.fn() }; beforeEach(() => { - opn.mockImplementation(() => Promise.reject()); + open.mockImplementation(() => Promise.reject()); }); afterEach(() => { @@ -134,7 +134,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]).toMatchInlineSnapshot(` + expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ "https://example.com", Object { @@ -154,7 +154,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]).toMatchInlineSnapshot(` + expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ "https://example.com/index.html", Object { @@ -174,7 +174,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]).toMatchInlineSnapshot(` + expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ "https://example.com", Object { @@ -195,7 +195,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]).toMatchInlineSnapshot(` + expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ "https://example.com/index.html", Object {