Skip to content

Commit

Permalink
Merge pull request #258 from happo/initialization-errors
Browse files Browse the repository at this point in the history
Add timeout waiting for `onBundleReady`
  • Loading branch information
trotzig committed Sep 18, 2023
2 parents c4eb30a + eeeb84b commit eb8ed5e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "happo.io",
"version": "8.3.3",
"version": "8.4.0-alpha",
"description": "Visual diffing for UI components",
"main": "./build/index.js",
"engines": {
Expand Down
11 changes: 9 additions & 2 deletions src/JSDOMDomProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,15 @@ export default class JSDOMDomProvider {
}

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

this.dom.window.onBundleReady = () => {
clearTimeout(timeout);
resolve();
};
});
return this.dom.window.happoProcessor.init({ targetName });
}
Expand Down
22 changes: 12 additions & 10 deletions test/integrations/error-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,19 @@ describe('with generated examples that fail to initialize', () => {
config.type = 'react';
});

xdescribe('with the puppeteer plugin', () => {
beforeEach(() => {
config.plugins = [happoPluginPuppeteer()];
});

it('logs an error', async () => {
it('throws a timeout error', async () => {
try {
await subject();
expect(console.log.mock.calls.length).toBe(1);
expect(console.log.mock.calls[0][0]).toEqual(
'Uncaught ReferenceError: foo is not defined',
} catch (e) {
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);
});
});

0 comments on commit eb8ed5e

Please sign in to comment.