Wait for static Server to start in tests

This patch starts waiting for Server's listening event
before starting to run any tests.
This commit is contained in:
Andrey Lushnikov 2017-07-06 23:45:18 -07:00
parent c8664319ed
commit bf08dbb3e9
2 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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();