From f7b7e4d8b6608e99ed761abdbb915742e8a13b5c 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) --- test/__snapshots__/Server.test.js.snap | 116 +++++++++++++++++++++++++ test/server/open-option.test.js | 4 +- test/server/utils/runOpen.test.js | 26 +++--- 3 files changed, 131 insertions(+), 15 deletions(-) create mode 100644 test/__snapshots__/Server.test.js.snap 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/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 80fe358512..e8b2ce1cb5 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 { @@ -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 { @@ -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 { @@ -171,7 +171,7 @@ describe('runOpen util', () => { const logMock = { warn: jest.fn() }; beforeEach(() => { - opn.mockImplementation(() => Promise.reject()); + open.mockImplementation(() => Promise.reject()); }); afterEach(() => { @@ -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 { @@ -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 { @@ -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 { @@ -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 {