Skip to content

Commit

Permalink
fix: wait for webpack builds to finish
Browse files Browse the repository at this point in the history
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 <bjoern.brauer@new-work.se>
  • Loading branch information
robertkowalski and ZauberNerd committed Feb 16, 2022
1 parent a9ffd0a commit eb6737e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/jest-environment/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -61,15 +64,20 @@ const startServer = ({ cwd, command, env = {}, argv = [] }) => {
return teardownPromise;
};

let serverUrl = '';
started.stdout.on('data', (data) => {
const line = data.toString('utf-8');
debug('stdout >', line);
stdout += line;

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);
}
});

Expand Down

0 comments on commit eb6737e

Please sign in to comment.