diff --git a/js/local/testPage.js b/js/local/testPage.js index a01a267..dbd3ad3 100644 --- a/js/local/testPage.js +++ b/js/local/testPage.js @@ -4,89 +4,102 @@ const puppeteer = require( 'puppeteer' ); -module.exports = async function( targetURL ) { +module.exports = function( targetURL ) { 'use strict'; - // const timeout = 30000; + const myFirstPromise = new Promise( async function( resolve, reject ) { + // do something asynchronous which eventually calls either: + // + // resolve(someValue); // fulfilled + // or + // reject("failure reason"); // rejected - const browser = await puppeteer.launch(); - const page = await browser.newPage(); - // Output log - // page.on( 'console', msg => console.log( 'PAGE LOG:', msg.text() ) ); + // const timeout = 30000; - var moduleErrors = []; - var testErrors = []; - var assertionErrors = []; + const browser = await puppeteer.launch(); + const page = await browser.newPage(); - await page.exposeFunction( 'harness_moduleDone', context => { - if ( context.failed ) { - var msg = 'Module Failed: ' + context.name + '\n' + testErrors.join( '\n' ); - moduleErrors.push( msg ); - testErrors = []; - } - } ); - - await page.exposeFunction( 'harness_testDone', context => { - if ( context.failed ) { - var msg = ' Test Failed: ' + context.name + assertionErrors.join( ' ' ); - testErrors.push( msg ); - assertionErrors = []; - process.stdout.write( 'F' ); - } - else { - process.stdout.write( '.' ); - } - } ); - - await page.exposeFunction( 'harness_log', context => { - if ( context.result ) { return; } // If success don't log + // Output log + // page.on( 'console', msg => console.log( 'PAGE LOG:', msg.text() ) ); - var msg = '\n Assertion Failed:'; - if ( context.message ) { - msg += ' ' + context.message; - } + var moduleErrors = []; + var testErrors = []; + var assertionErrors = []; - if ( context.expected ) { - msg += '\n Expected: ' + context.expected + ', Actual: ' + context.actual; - } - - assertionErrors.push( msg ); - } ); + await page.exposeFunction( 'harness_moduleDone', context => { + if ( context.failed ) { + var msg = 'Module Failed: ' + context.name + '\n' + testErrors.join( '\n' ); + moduleErrors.push( msg ); + testErrors = []; + } + } ); + + await page.exposeFunction( 'harness_testDone', context => { + if ( context.failed ) { + var msg = ' Test Failed: ' + context.name + assertionErrors.join( ' ' ); + testErrors.push( msg ); + assertionErrors = []; + process.stdout.write( 'F' ); + } + else { + process.stdout.write( '.' ); + } + } ); - await page.exposeFunction( 'harness_done', context => { - console.log( '\n' ); + await page.exposeFunction( 'harness_log', context => { + if ( context.result ) { return; } // If success don't log - if ( moduleErrors.length > 0 ) { - for ( var idx = 0; idx < moduleErrors.length; idx++ ) { - console.error( moduleErrors[ idx ] + '\n' ); + var msg = '\n Assertion Failed:'; + if ( context.message ) { + msg += ' ' + context.message; } - } - var stats = [ - 'Time: ' + context.runtime + 'ms', - 'Total: ' + context.total, - 'Passed: ' + context.passed, - 'Failed: ' + context.failed - ]; - console.log( stats.join( ', ' ) ); + if ( context.expected ) { + msg += '\n Expected: ' + context.expected + ', Actual: ' + context.actual; + } - browser.close(); + assertionErrors.push( msg ); + } ); - } ); + await page.exposeFunction( 'harness_done', context => { + console.log( '\n' ); - await page.goto( targetURL ); + if ( moduleErrors.length > 0 ) { + for ( var idx = 0; idx < moduleErrors.length; idx++ ) { + console.error( moduleErrors[ idx ] + '\n' ); + } + } - await page.evaluate( () => { - QUnit.config.testTimeout = 10000; + var stats = [ + 'Time: ' + context.runtime + 'ms', + 'Total: ' + context.total, + 'Passed: ' + context.passed, + 'Failed: ' + context.failed + ]; + console.log( stats.join( ', ' ) ); + + browser.close(); + console.log( 'hello' ); + resolve( 'hello2' ); + } ); + + await page.goto( targetURL ); + + 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 ) ); + + console.log( '\nRunning: ' + JSON.stringify( QUnit.urlParams ) + '\n' ); + } ); + } ); - // 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 ) ); + return myFirstPromise; - console.log( '\nRunning: ' + JSON.stringify( QUnit.urlParams ) + '\n' ); - } ); }; \ No newline at end of file