Skip to content

Commit 148dfd5

Browse files
committed
test: update syntax
1 parent 2ce7d04 commit 148dfd5

File tree

6 files changed

+48
-64
lines changed

6 files changed

+48
-64
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"supertest": "^4.0.2",
110110
"tcp-port-used": "^1.0.1",
111111
"typescript": "^3.5.3",
112-
"url-loader": "^2.0.0",
112+
"url-loader": "^2.1.0",
113113
"webpack": "^4.39.0",
114114
"webpack-cli": "^3.3.6"
115115
},

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: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,17 @@ describe('Client code', () => {
5050
});
5151

5252
afterAll((done) => {
53-
proxy.close(() => {
54-
done();
55-
});
53+
proxy.close(done);
5654
});
5755

58-
it('responds with a 200', (done) => {
56+
it('responds with a 200', async () => {
5957
{
6058
const req = request(`http://localhost:${port2}`);
61-
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
59+
await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n');
6260
}
6361
{
6462
const req = request(`http://localhost:${port1}`);
65-
req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n', done);
63+
await req.get('/sockjs-node').expect(200, 'Welcome to SockJS!\n');
6664
}
6765
});
6866

@@ -297,47 +295,34 @@ describe('Client console.log', () => {
297295
},
298296
];
299297

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

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

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)