Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase bundle timeout to 60s, make it configurable #259

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/JSDOMDomProvider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { JSDOM, VirtualConsole } from 'jsdom';
import mergeJsdomOptions from './mergeJSDOMOptions';

const { VERBOSE } = process.env;
const { VERBOSE, HAPPO_BUNDLE_LOAD_TIMEOUT_MS: rawBundleLoadTimeout = '60000' } =
process.env;

const HAPPO_BUNDLE_LOAD_TIMEOUT_MS = parseInt(rawBundleLoadTimeout, 10);

const MAX_ERROR_DETAIL_LENGTH = 200;

Expand All @@ -10,7 +13,11 @@ export default class JSDOMDomProvider {
const virtualConsole = new VirtualConsole();
virtualConsole.on('jsdomError', (e) => {
const { stack, detail = '' } = e;
if (VERBOSE || typeof detail !== 'string' || detail.length < MAX_ERROR_DETAIL_LENGTH) {
if (
VERBOSE ||
typeof detail !== 'string' ||
detail.length < MAX_ERROR_DETAIL_LENGTH
) {
console.error(stack, detail);
} else {
const newDetail = `${(detail || '').slice(0, MAX_ERROR_DETAIL_LENGTH)}...
Expand Down Expand Up @@ -56,9 +63,15 @@ export default class JSDOMDomProvider {

async init({ targetName }) {
await new Promise((resolve, reject) => {
const timeout = setTimeout(() =>
reject(new Error('Failed to load Happo bundle within 10s. Check console log for errors.')),
10000);
const timeout = setTimeout(
() =>
reject(
new Error(
`Failed to load Happo bundle within ${HAPPO_BUNDLE_LOAD_TIMEOUT_MS}ms. Check console log for errors.`,
),
),
HAPPO_BUNDLE_LOAD_TIMEOUT_MS,
);

this.dom.window.onBundleReady = () => {
clearTimeout(timeout);
Expand Down
5 changes: 1 addition & 4 deletions test/integrations/error-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,11 @@ describe('with generated examples that fail to initialize', () => {
try {
await subject();
} catch (e) {
expect(e.message).toMatch(
/Failed to load Happo bundle within/,
);
expect(e.message).toMatch(/Failed to load Happo bundle within/);
expect(console.error.mock.calls[1][0]).toMatch(/foo is not defined/);
return;
}


// If we end up here, something is wrong
expect(false).toBe(true);
});
Expand Down
1 change: 1 addition & 0 deletions test/jestSetup.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
jest.setTimeout(10000);
delete process.env.HAPPO_API_KEY;
delete process.env.HAPPO_API_SECRET;
process.env.HAPPO_BUNDLE_LOAD_TIMEOUT_MS = '10000';
Loading