From bc8322326be0bb6c5198417eac29f1b9325afac3 Mon Sep 17 00:00:00 2001 From: Yuta Hiroto Date: Wed, 29 May 2019 10:55:36 +0100 Subject: [PATCH] test(client): check console.log (#1907) --- test/Client.test.js | 68 ++++++++++++++++++++++++++ test/__snapshots__/Client.test.js.snap | 29 +++++++++++ 2 files changed, 97 insertions(+) create mode 100644 test/__snapshots__/Client.test.js.snap diff --git a/test/Client.test.js b/test/Client.test.js index 335425b7ab..f29666ecdf 100644 --- a/test/Client.test.js +++ b/test/Client.test.js @@ -229,3 +229,71 @@ describe('Client complex inline script path with sockHost', () => { }); }); }); + +describe('Client console.log', () => { + jest.setTimeout(30000); + + const baseOptions = { + port: 9000, + host: '0.0.0.0', + }; + const cases = [ + { + title: 'hot disabled', + options: { + hot: false, + }, + }, + { + title: 'hot enabled', + options: { + hot: true, + }, + }, + { + title: 'liveReload disabled', + options: { + liveReload: false, + }, + }, + { + title: 'liveReload enabled', + options: { + liveReload: true, + }, + }, + ]; + + for (const { title, options } of cases) { + it(title, () => { + const res = []; + const testOptions = Object.assign({}, baseOptions, options); + + // TODO: use async/await when Node.js v6 support is dropped + return Promise.resolve() + .then(() => { + return new Promise((resolve) => { + testServer.startAwaitingCompilation(config, testOptions, resolve); + }); + }) + .then(runBrowser) + .then(({ page, browser }) => { + return new Promise((resolve) => { + page.goto('http://localhost:9000/main'); + page.on('console', ({ _text }) => { + res.push(_text); + }); + setTimeout(() => { + expect(res).toMatchSnapshot(); + browser.close().then(resolve); + }, 3000); + }); + }) + .then(() => { + return new Promise((resolve) => { + testServer.close(resolve); + }); + }); + }); + } +}); diff --git a/test/__snapshots__/Client.test.js.snap b/test/__snapshots__/Client.test.js.snap new file mode 100644 index 0000000000..92ec069c30 --- /dev/null +++ b/test/__snapshots__/Client.test.js.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Client console.log hot disabled 1`] = ` +Array [ + "Hey.", + "[WDS] Live Reloading enabled.", +] +`; + +exports[`Client console.log hot enabled 1`] = ` +Array [ + "[HMR] Waiting for update signal from WDS...", + "Hey.", + "[WDS] Hot Module Replacement enabled.", + "[WDS] Live Reloading enabled.", +] +`; + +exports[`Client console.log liveReload disabled 1`] = ` +Array [ + "Hey.", +] +`; + +exports[`Client console.log liveReload enabled 1`] = ` +Array [ + "Hey.", +] +`;