From bf08dbb3e902ff9832dce14f3991257772270b3c Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Thu, 6 Jul 2017 23:45:18 -0700 Subject: [PATCH] Wait for static Server to start in tests This patch starts waiting for Server's listening event before starting to run any tests. --- test/StaticServer.js | 11 +++++++++++ test/test.js | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/StaticServer.js b/test/StaticServer.js index 6edaa0f71cb..22451e0ef0c 100644 --- a/test/StaticServer.js +++ b/test/StaticServer.js @@ -25,6 +25,17 @@ const fulfillSymbol = Symbol('fullfill callback'); const rejectSymbol = Symbol('reject callback'); class StaticServer { + /** + * @param {string} dirPath + * @param {number} port + * @return {!StaticServer} + */ + static async create(dirPath, port) { + let server = new StaticServer(dirPath, port); + await new Promise(x => server._server.once('listening', x)); + return server; + } + /** * @param {string} dirPath * @param {number} port diff --git a/test/test.js b/test/test.js index 2448543157b..9132d534673 100644 --- a/test/test.js +++ b/test/test.js @@ -30,11 +30,11 @@ describe('Puppeteer', function() { let staticServer; let page; - beforeAll(function() { + beforeAll(SX(async function() { browser = new Browser({args: ['--no-sandbox']}); - staticServer = new StaticServer(path.join(__dirname, 'assets'), PORT); + staticServer = await StaticServer.create(path.join(__dirname, 'assets'), PORT); GoldenUtils.removeOutputDir(); - }); + })); afterAll(function() { staticServer.stop();