diff --git a/test/cli/cli.test.js b/test/cli/cli.test.js index e4106217b2..60618eb544 100644 --- a/test/cli/cli.test.js +++ b/test/cli/cli.test.js @@ -25,9 +25,7 @@ describe('CLI', () => { const { code, stderr } = await testBin('--progress --profile'); expect(code).toEqual(0); // should profile - expect(output.stderr.includes('after chunk modules optimization')).toBe( - true - ); + expect(stderr.includes('after chunk modules optimization')).toBe(true); }); it('--bonjour', async () => { @@ -58,8 +56,8 @@ describe('CLI', () => { }); it('unspecified port', async () => { - const { output } = await testBin(''); - expect(/http:\/\/localhost:[0-9]+/.test(output.stdout)).toEqual(true); + const { stdout } = await testBin(''); + expect(/http:\/\/localhost:[0-9]+/.test(stdout)).toEqual(true); }); it('--color', async () => { diff --git a/test/client/socket-helper.test.js b/test/client/socket-helper.test.js index a40007aa49..b8074cebd5 100644 --- a/test/client/socket-helper.test.js +++ b/test/client/socket-helper.test.js @@ -8,7 +8,7 @@ describe('socket', () => { it('should default to SockJSClient when no __webpack_dev_server_client__ set', () => { jest.mock('../../client/clients/SockJSClient'); - const socket = require('../../client/socket'); + const { default: socket } = require('../../client/socket'); const SockJSClient = require('../../client/clients/SockJSClient'); const mockHandler = jest.fn(); @@ -36,7 +36,7 @@ describe('socket', () => { it('should use __webpack_dev_server_client__ when set', () => { jest.mock('../../client/clients/SockJSClient'); - const socket = require('../../client/socket'); + const { default: socket } = require('../../client/socket'); global.__webpack_dev_server_client__ = require('../../client/clients/SockJSClient'); const mockHandler = jest.fn(); diff --git a/test/e2e/ClientOptions.test.js b/test/e2e/ClientOptions.test.js index b753f1a24e..6f2c5ac8d9 100644 --- a/test/e2e/ClientOptions.test.js +++ b/test/e2e/ClientOptions.test.js @@ -50,19 +50,17 @@ describe('Client code', () => { }); afterAll((done) => { - proxy.close(() => { - done(); - }); + proxy.close(done); }); - it('responds with a 200', (done) => { + it('responds with a 200', async () => { { const req = request(`http://localhost:${port2}`); - req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done); + await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n'); } { const req = request(`http://localhost:${port1}`); - req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done); + await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n'); } }); @@ -297,47 +295,34 @@ describe('Client console.log', () => { }, ]; - cases.forEach(({ title, options }) => { - it(title, (done) => { + for (const { title, options } of cases) { + it(title, async () => { const res = []; const testOptions = Object.assign({}, baseOptions, options); - // TODO: use async/await when Node.js v6 support is dropped - Promise.resolve() - .then(() => { - return new Promise((resolve) => { - testServer.startAwaitingCompilation(config, testOptions, resolve); - }); - }) - .then(() => { - // make sure the previous Promise is not passing along strange arguments to runBrowser - return runBrowser(); - }) - .then(({ page, browser }) => { - return new Promise((resolve) => { - page.goto(`http://localhost:${port2}/main`); - page.on('console', ({ _text }) => { - res.push(_text); - }); - // wait for load before closing the browser - page.waitForNavigation({ waitUntil: 'load' }).then(() => { - page.waitFor(beforeBrowserCloseDelay).then(() => { - browser.close().then(() => { - resolve(); - }); - }); - }); - }); - }) - .then(() => { - return new Promise((resolve) => { - testServer.close(resolve); - }); - }) - .then(() => { - expect(res).toMatchSnapshot(); - done(); - }); + // TODO: refactor(hiroppy) + await new Promise((resolve) => { + testServer.startAwaitingCompilation(config, testOptions, resolve); + }); + + const { page, browser } = await runBrowser(); + + page.goto(`http://localhost:${port2}/main`); + page.on('console', ({ _text }) => { + res.push(_text); + }); + + // wait for load before closing the browser + await page.waitForNavigation({ waitUntil: 'load' }); + await page.waitFor(beforeBrowserCloseDelay); + await browser.close(); + + expect(res).toMatchSnapshot(); + + // TODO: refactor(hiroppy) + await new Promise((resolve) => { + testServer.close(resolve); + }); }); - }); + } }); diff --git a/test/server/servers/SockJSServer.test.js b/test/server/servers/SockJSServer.test.js index 054ec18f31..c3203f3627 100644 --- a/test/server/servers/SockJSServer.test.js +++ b/test/server/servers/SockJSServer.test.js @@ -37,7 +37,8 @@ describe('SockJSServer', () => { const data = []; let headers; - socketServer.onConnection(async (connection) => { + socketServer.onConnection(async (connection, h) => { + headers = h; data.push('open'); socketServer.send(connection, 'hello world'); diff --git a/test/server/utils/runOpen.test.js b/test/server/utils/runOpen.test.js index 0c37e488b0..1ae6b092d1 100644 --- a/test/server/utils/runOpen.test.js +++ b/test/server/utils/runOpen.test.js @@ -78,13 +78,14 @@ describe('runOpen util', () => { }); }); - it('on specify absolute https URL with page in Google Chrome ', () => { - return runOpen( + it('on specify absolute https URL with page in Google Chrome ', async () => { + await runOpen( 'https://example.com', { open: 'Google Chrome', openPage: 'https://example2.com' }, console - ).then(() => { - expect(open.mock.calls[0]).toMatchInlineSnapshot(` + ); + + expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ "https://example2.com", Object { @@ -93,16 +94,16 @@ describe('runOpen util', () => { }, ] `); - }); }); - it('on specify absolute http URL with page in Google Chrome ', () => { - return runOpen( + it('on specify absolute http URL with page in Google Chrome ', async () => { + runOpen( 'https://example.com', { open: 'Google Chrome', openPage: 'http://example2.com' }, console - ).then(() => { - expect(open.mock.calls[0]).toMatchInlineSnapshot(` + ); + + expect(open.mock.calls[0]).toMatchInlineSnapshot(` Array [ "http://example2.com", Object { @@ -111,7 +112,6 @@ describe('runOpen util', () => { }, ] `); - }); }); describe('should not open browser', () => {