Skip to content

Commit 1679797

Browse files
committed
test: update syntax
1 parent 5c0dced commit 1679797

File tree

6 files changed

+54
-69
lines changed

6 files changed

+54
-69
lines changed

test/cli/cli.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ describe('CLI', () => {
2525
const { code, stderr } = await testBin('--progress --profile');
2626
expect(code).toEqual(0);
2727
// should profile
28-
expect(output.stderr.includes('after chunk modules optimization')).toBe(
29-
true
30-
);
28+
expect(stderr.includes('after chunk modules optimization')).toBe(true);
3129
});
3230

3331
it('--bonjour', async () => {
@@ -58,8 +56,8 @@ describe('CLI', () => {
5856
});
5957

6058
it('unspecified port', async () => {
61-
const { output } = await testBin('');
62-
expect(/http:\/\/localhost:[0-9]+/.test(output.stdout)).toEqual(true);
59+
const { stdout } = await testBin('');
60+
expect(/http:\/\/localhost:[0-9]+/.test(stdout)).toEqual(true);
6361
});
6462

6563
it('--color', async () => {

test/client/socket-helper.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('socket', () => {
88

99
it('should default to SockJSClient when no __webpack_dev_server_client__ set', () => {
1010
jest.mock('../../client/clients/SockJSClient');
11-
const socket = require('../../client/socket');
11+
const { default: socket } = require('../../client/socket');
1212
const SockJSClient = require('../../client/clients/SockJSClient');
1313

1414
const mockHandler = jest.fn();
@@ -36,7 +36,7 @@ describe('socket', () => {
3636

3737
it('should use __webpack_dev_server_client__ when set', () => {
3838
jest.mock('../../client/clients/SockJSClient');
39-
const socket = require('../../client/socket');
39+
const { default: socket } = require('../../client/socket');
4040
global.__webpack_dev_server_client__ = require('../../client/clients/SockJSClient');
4141

4242
const mockHandler = jest.fn();

test/e2e/ClientOptions.test.js

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,18 @@ describe('Client code', () => {
5050
});
5151

5252
afterAll((done) => {
53-
proxy.close(() => {
54-
done();
55-
});
56-
});
57-
58-
it('responds with a 200 on proxy port', (done) => {
59-
const req = request(`http://localhost:${port2}`);
60-
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
53+
proxy.close(done);
6154
});
6255

63-
it('responds with a 200 on non-proxy port', (done) => {
64-
const req = request(`http://localhost:${port1}`);
65-
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
56+
it('responds with a 200', async () => {
57+
{
58+
const req = request(`http://localhost:${port2}`);
59+
await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n');
60+
}
61+
{
62+
const req = request(`http://localhost:${port1}`);
63+
await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n');
64+
}
6665
});
6766

6867
it('requests websocket through the proxy with proper port number', (done) => {
@@ -296,47 +295,34 @@ describe('Client console.log', () => {
296295
},
297296
];
298297

299-
cases.forEach(({ title, options }) => {
300-
it(title, (done) => {
298+
for (const { title, options } of cases) {
299+
it(title, async () => {
301300
const res = [];
302301
const testOptions = Object.assign({}, baseOptions, options);
303302

304-
// TODO: use async/await when Node.js v6 support is dropped
305-
Promise.resolve()
306-
.then(() => {
307-
return new Promise((resolve) => {
308-
testServer.startAwaitingCompilation(config, testOptions, resolve);
309-
});
310-
})
311-
.then(() => {
312-
// make sure the previous Promise is not passing along strange arguments to runBrowser
313-
return runBrowser();
314-
})
315-
.then(({ page, browser }) => {
316-
return new Promise((resolve) => {
317-
page.goto(`http://localhost:${port2}/main`);
318-
page.on('console', ({ _text }) => {
319-
res.push(_text);
320-
});
321-
// wait for load before closing the browser
322-
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
323-
page.waitFor(beforeBrowserCloseDelay).then(() => {
324-
browser.close().then(() => {
325-
resolve();
326-
});
327-
});
328-
});
329-
});
330-
})
331-
.then(() => {
332-
return new Promise((resolve) => {
333-
testServer.close(resolve);
334-
});
335-
})
336-
.then(() => {
337-
expect(res).toMatchSnapshot();
338-
done();
339-
});
303+
// TODO: refactor(hiroppy)
304+
await new Promise((resolve) => {
305+
testServer.startAwaitingCompilation(config, testOptions, resolve);
306+
});
307+
308+
const { page, browser } = await runBrowser();
309+
310+
page.goto(`http://localhost:${port2}/main`);
311+
page.on('console', ({ _text }) => {
312+
res.push(_text);
313+
});
314+
315+
// wait for load before closing the browser
316+
await page.waitForNavigation({ waitUntil: 'load' });
317+
await page.waitFor(beforeBrowserCloseDelay);
318+
await browser.close();
319+
320+
expect(res).toMatchSnapshot();
321+
322+
// TODO: refactor(hiroppy)
323+
await new Promise((resolve) => {
324+
testServer.close(resolve);
325+
});
340326
});
341-
});
327+
}
342328
});

test/options.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('options', () => {
2626
const properties = Object.keys(options.properties);
2727
const messages = Object.keys(options.errorMessage.properties);
2828

29-
expect(properties.length).toEqual(messages.length);
29+
expect(properties).toEqual(messages);
3030

3131
const res = properties.every((name) => messages.includes(name));
3232

test/server/servers/SockJSServer.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ describe('SockJSServer', () => {
3737
const data = [];
3838
let headers;
3939

40-
socketServer.onConnection(async (connection) => {
40+
socketServer.onConnection(async (connection, h) => {
41+
headers = h;
4142
data.push('open');
4243
socketServer.send(connection, 'hello world');
4344

test/server/utils/runOpen.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ describe('runOpen util', () => {
7878
});
7979
});
8080

81-
it('on specify absolute https URL with page in Google Chrome ', () => {
82-
return runOpen(
81+
it('on specify absolute https URL with page in Google Chrome ', async () => {
82+
await runOpen(
8383
'https://example.com',
8484
{ open: 'Google Chrome', openPage: 'https://example2.com' },
8585
console
86-
).then(() => {
87-
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
86+
);
87+
88+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
8889
Array [
8990
"https://example2.com",
9091
Object {
@@ -93,16 +94,16 @@ describe('runOpen util', () => {
9394
},
9495
]
9596
`);
96-
});
9797
});
9898

99-
it('on specify absolute http URL with page in Google Chrome ', () => {
100-
return runOpen(
99+
it('on specify absolute http URL with page in Google Chrome ', async () => {
100+
runOpen(
101101
'https://example.com',
102102
{ open: 'Google Chrome', openPage: 'http://example2.com' },
103103
console
104-
).then(() => {
105-
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
104+
);
105+
106+
expect(open.mock.calls[0]).toMatchInlineSnapshot(`
106107
Array [
107108
"http://example2.com",
108109
Object {
@@ -111,7 +112,6 @@ describe('runOpen util', () => {
111112
},
112113
]
113114
`);
114-
});
115115
});
116116

117117
describe('should not open browser', () => {

0 commit comments

Comments
 (0)