Skip to content

Commit d2a0bfd

Browse files
committed
test: convert promises to async/await
1 parent f241bdf commit d2a0bfd

File tree

2 files changed

+18
-43
lines changed

2 files changed

+18
-43
lines changed

test/client/__snapshots__/index.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports[`index should run onSocketMessage.close (liveReload enabled) 1`] = `"[WD
88

99
exports[`index should run onSocketMessage.close (liveReload enabled) 2`] = `"Close"`;
1010

11-
exports[`index should run onSocketMessage.close 1`] = `"[WDS] Hot Module Replacement & Live Reloading are disabled!"`;
11+
exports[`index should run onSocketMessage.close 1`] = `"[WDS] Disconnected!"`;
1212

1313
exports[`index should run onSocketMessage.close 2`] = `"Close"`;
1414

test/e2e/ClientOptions.test.js

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -419,53 +419,28 @@ describe('Client console.log', () => {
419419
},
420420
];
421421

422-
transportModes.forEach((mode) => {
423-
cases.forEach(({ title, options }) => {
422+
transportModes.forEach(async (mode) => {
423+
await cases.forEach(async ({ title, options }) => {
424424
title += ` (${
425425
Object.keys(mode).length ? mode.transportMode : 'default'
426426
})`;
427427
options = { ...mode, ...options };
428-
it(title, (done) => {
428+
const testOptions = Object.assign({}, baseOptions, options);
429+
await it(title, async (done) => {
430+
await testServer.startAwaitingCompilation(config, testOptions);
429431
const res = [];
430-
const testOptions = Object.assign({}, baseOptions, options);
431-
432-
// TODO: use async/await when Node.js v6 support is dropped
433-
Promise.resolve()
434-
.then(() => {
435-
return new Promise((resolve) => {
436-
testServer.startAwaitingCompilation(config, testOptions, resolve);
437-
});
438-
})
439-
.then(() => {
440-
// make sure the previous Promise is not passing along strange arguments to runBrowser
441-
return runBrowser();
442-
})
443-
.then(({ page, browser }) => {
444-
return new Promise((resolve) => {
445-
page.goto(`http://localhost:${port2}/main`);
446-
page.on('console', ({ _text }) => {
447-
res.push(_text);
448-
});
449-
// wait for load before closing the browser
450-
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
451-
page.waitFor(beforeBrowserCloseDelay).then(() => {
452-
browser.close().then(() => {
453-
resolve();
454-
});
455-
});
456-
});
457-
});
458-
})
459-
.then(() => {
460-
return new Promise((resolve) => {
461-
testServer.close(resolve);
462-
});
463-
})
464-
.then(() => {
465-
// Order doesn't matter, maybe we should improve that in future
466-
expect(res.sort()).toMatchSnapshot();
467-
done();
468-
});
432+
const { page, browser } = await runBrowser();
433+
page.goto(`http://localhost:${port2}/main`);
434+
page.on('console', ({ _text }) => {
435+
res.push(_text);
436+
});
437+
// wait for load before closing the browser
438+
await page.waitForNavigation({ waitUntil: 'load' });
439+
await page.waitFor(beforeBrowserCloseDelay);
440+
await browser.close();
441+
// Order doesn't matter, maybe we should improve that in future
442+
await expect(res.sort()).toMatchSnapshot();
443+
await testServer.close(done);
469444
});
470445
});
471446
});

0 commit comments

Comments
 (0)