From eb6737e3e38a18814dbb906f3b01c016fcbc9162 Mon Sep 17 00:00:00 2001 From: Robert Kowalski Date: Tue, 15 Feb 2022 11:55:52 +0100 Subject: [PATCH] fix: wait for webpack builds to finish MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in the current setup, webpack builds where still running when the puppeteer tests would start, which leads to timeout issues, especially on slow machines like CI servers. This commit waits for the build to finish before continuing with `getUrl`, which is called by the integration tests upfront Co-authored-by: Björn Brauer --- packages/jest-environment/helpers.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/jest-environment/helpers.js b/packages/jest-environment/helpers.js index 3519fbfa4..174083e86 100644 --- a/packages/jest-environment/helpers.js +++ b/packages/jest-environment/helpers.js @@ -45,8 +45,11 @@ const build = ({ cwd, env = {}, argv = [] }) => const startServer = ({ cwd, command, env = {}, argv = [] }) => { const teardownPromise = new EProm(); const urlPromise = new EProm(); + let stdout = ''; let stderr = ''; + const success1 = "bundling 'develop' finished"; + const success2 = "bundling 'node' finished"; const hopsBin = resolveFrom(cwd, 'hops/bin'); const args = [hopsBin, command].concat(argv); @@ -61,6 +64,7 @@ const startServer = ({ cwd, command, env = {}, argv = [] }) => { return teardownPromise; }; + let serverUrl = ''; started.stdout.on('data', (data) => { const line = data.toString('utf-8'); debug('stdout >', line); @@ -68,8 +72,12 @@ const startServer = ({ cwd, command, env = {}, argv = [] }) => { const [, url] = line.match(/listening at (.*)/i) || []; if (url) { + serverUrl = url; debug('found match:', url); - urlPromise.resolve(url); + } + + if (stdout.includes(success1) && stdout.includes(success2) && serverUrl) { + urlPromise.resolve(serverUrl); } });