Skip to content

Commit

Permalink
test: wait for compilation
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Kowalski <robert.kowalski@new-work.se>
  • Loading branch information
ZauberNerd and robertkowalski committed Feb 16, 2022
1 parent eb6737e commit 618fc87
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 26 deletions.
21 changes: 14 additions & 7 deletions packages/jest-environment/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,10 @@ const build = ({ cwd, env = {}, argv = [] }) =>
const startServer = ({ cwd, command, env = {}, argv = [] }) => {
const teardownPromise = new EProm();
const urlPromise = new EProm();
const hasFinishedPromise = 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 @@ -64,20 +63,28 @@ const startServer = ({ cwd, command, env = {}, argv = [] }) => {
return teardownPromise;
};

let serverUrl = '';
let linesToFinish = [];
const hasFinished = (lines) => {
linesToFinish.push(...lines);
return hasFinishedPromise;
};

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);
if (
linesToFinish.length > 0 &&
linesToFinish.every((lineToFinish) => stdout.includes(lineToFinish))
) {
hasFinishedPromise.resolve();
}
});

Expand All @@ -99,7 +106,7 @@ const startServer = ({ cwd, command, env = {}, argv = [] }) => {
stopServer();
});

return { getUrl: () => urlPromise, stopServer };
return { getUrl: () => urlPromise, stopServer, hasFinished };
};

const isPuppeteerDisabled = (pragmas) => {
Expand Down
8 changes: 6 additions & 2 deletions packages/jest-environment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ class FixtureEnvironment extends NodeEnvironment {
);
}
const { env, argv } = getHopsCommandModifications(args);
const { getUrl, stopServer: killServer } = startServer({
const {
getUrl,
stopServer: killServer,
hasFinished,
} = startServer({
cwd: that.cwd,
command: 'start',
env,
Expand All @@ -124,7 +128,7 @@ class FixtureEnvironment extends NodeEnvironment {
delete that.killServer;
return killServer();
};
return { getUrl, stopServer };
return { getUrl, stopServer, hasFinished };
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ describe('development proxy object config', () => {
};
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('proxies with proxy config set as object', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ describe('development proxy string config', () => {
packageJson.hops.proxy = `http://localhost:${PORT}/proxy`;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('proxies with proxy config set as string', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ describe('typescript development server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev', '--experimental-esbuild');
const { getUrl, hasFinished } = HopsCLI.start(
'--fast-dev',
'--experimental-esbuild'
);
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('renders a simple jsx site', async () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/spec/integration/esbuild/__tests__/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ describe('esbuild - develop', () => {
let url, page, getInnerText;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev', '--experimental-esbuild');
const { getUrl, hasFinished } = HopsCLI.start(
'--fast-dev',
'--experimental-esbuild'
);
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
const pptr = await createPage();
page = pptr.page;
getInnerText = pptr.getInnerText;
Expand Down
9 changes: 8 additions & 1 deletion packages/spec/integration/fast-refresh/__tests__/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ describe('react fast refresh', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev', '--fast-refresh');
const { getUrl, hasFinished } = HopsCLI.start(
'--fast-dev',
'--fast-refresh'
);
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('renders caption only once', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ describe('graphql development client', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

describe('/invalid-response (HTML)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ describe('graphql mock server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'graphql-mock-server' finished",
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('renders a mocked quote', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ describe('graphql mock server without SSR', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'graphql-mock-server' finished",
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('requests data on the client & not on the server', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ describe.skip('hot module reload', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('reflects changes automatically', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/spec/integration/postcss/__tests__/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ describe('react-postcss', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('styles when served in development mode', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/spec/integration/react/__tests__/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ describe('react development server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('renders home', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ describe('redux development server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('increments the counter on page load', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/spec/integration/redux/__tests__/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ describe('redux development server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start(
const { getUrl, hasFinished } = HopsCLI.start(
{
PORT: '8950',
},
'--fast-dev'
);
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('has default state', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/spec/integration/redux/__tests__/mocked.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ describe('development server with msw mocks', () => {
let baseUrl;

beforeAll(async () => {
const { getUrl } = HopsCLI.start(
const { getUrl, hasFinished } = HopsCLI.start(
{
ENABLE_MSW: 'true',
PORT: '8949',
},
'--fast-dev'
);
baseUrl = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

describe('Adding up to 12', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ describe('styled-components development server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('allows to use styled components', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ describe('typescript-styled-components development server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('allows to use the css-props', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/spec/integration/typescript/__tests__/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ describe('typescript development server', () => {
let url;

beforeAll(async () => {
const { getUrl } = HopsCLI.start('--fast-dev');
const { getUrl, hasFinished } = HopsCLI.start('--fast-dev');
url = await getUrl();
await hasFinished([
"bundling 'develop' finished",
"bundling 'node' finished",
]);
});

it('renders a simple jsx site', async () => {
Expand Down

0 comments on commit 618fc87

Please sign in to comment.