Skip to content

Commit

Permalink
Poll for starting if not ready, see #102
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jul 6, 2020
1 parent d6b2ffa commit a6f424f
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions js/local/puppeteerQUnit.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,36 @@ module.exports = function( browser, targetURL ) {
await page.goto( `${targetURL}&qunitHooks` );

await page.evaluate( () => {
QUnit.config.testTimeout = 10000;

// Cannot pass the window.harness_blah methods directly, because they are
// automatically defined as async methods, which QUnit does not support
QUnit.moduleDone( context => window.harness_moduleDone( context ) );
QUnit.testDone( context => window.harness_testDone( context ) );
QUnit.log( context => window.harness_log( context ) );
QUnit.done( context => window.harness_done( context ) );
const launch = () => {
QUnit.config.testTimeout = 10000;

// Launch the qunit tests now that listeners are wired up
window.qunitLaunchAfterHooks();
// Cannot pass the window.harness_blah methods directly, because they are
// automatically defined as async methods, which QUnit does not support
QUnit.moduleDone( context => window.harness_moduleDone( context ) );
QUnit.testDone( context => window.harness_testDone( context ) );
QUnit.log( context => window.harness_log( context ) );
QUnit.done( context => window.harness_done( context ) );

// Launch the qunit tests now that listeners are wired up
window.qunitLaunchAfterHooks();
};

// Start right away if the page is ready
if ( window.qunitLaunchAfterHooks ) {
launch();
}
else {

// Polling to wait until the page is ready for launch
let id = null;
id = setInterval( () => {
if ( window.qunitLaunchAfterHooks ) {
clearInterval( id );
launch();
}
}, 16 );
}
} );
}
catch( e ) {
Expand Down

0 comments on commit a6f424f

Please sign in to comment.