Skip to content

Commit

Permalink
Close pages, see #52
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Oct 10, 2018
1 parent 7539b76 commit 283356d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
25 changes: 25 additions & 0 deletions js/local/runPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2018, University of Colorado Boulder

module.exports = function( browser, targetURL ) {
'use strict';

return new Promise( async function( resolve, reject ) {

const page = await browser.newPage();
page.on( 'error', msg => {
page.close();
clearTimeout( id );
resolve( { result: 'error', message: msg } );
} );
page.on( 'pageerror', msg => {
page.close();
clearTimeout( id );
resolve( { result: 'pageerror', message: msg } );
} );
await page.goto( targetURL );
var id = setTimeout( async function() {
await page.close();
resolve( { result: 'success' } );
}, 5000 );
} );
};
23 changes: 8 additions & 15 deletions js/local/test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
// Copyright 2018, University of Colorado Boulder
const testPage = require( './testPage' );
const runPage = require( './runPage' );
const puppeteer = require( 'puppeteer' );

( async () => {
'use strict';

var x = await testPage( 'http://localhost/axon/axon-tests.html' );
var y = await testPage( 'http://localhost/scenery/scenery-tests.html?ea' );
console.log( 'await complete!' );
console.log( x );
console.log( y );

// var values = await Promise.all( [
// testPage( 'http://localhost/axon/axon-tests.html' ),
// testPage( 'http://localhost/scenery/scenery-tests.html?ea' )
// ]);
// Promise.all( [ testPage ] ).then( function( values ) {
// console.log( values );
// } );
const browser = await puppeteer.launch();

// const targetURL = 'http://localhost/scenery/scenery-tests.html?ea';
// await testPage( 'http://localhost/axon/axon-tests.html' );
var x = await testPage( browser, 'http://localhost/axon/axon-tests.html' );
console.log( x );
var z = await runPage( browser, 'http://localhost/faradays-law/faradays-law_en.html?brand=phet&ea&fuzzMouse' );
console.log( z );
browser.close();
} )();
18 changes: 3 additions & 15 deletions js/local/testPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,10 @@
// Adapted from https://github.com/davidtaylorhq/qunit-puppeteer which is distributed under the MIT License // eslint-disable-line
/* eslint-enable */

const puppeteer = require( 'puppeteer' );

module.exports = function( targetURL ) {
module.exports = function( browser, targetURL ) {
'use strict';

return new Promise( async function( resolve, reject ) {
// do something asynchronous which eventually calls either:
//
// resolve(someValue); // fulfilled
// or
// reject("failure reason"); // rejected


// const timeout = 30000;

const browser = await puppeteer.launch();
const page = await browser.newPage();

// Output log
Expand Down Expand Up @@ -62,7 +50,7 @@ module.exports = function( targetURL ) {
assertionErrors.push( msg );
} );

await page.exposeFunction( 'harness_done', context => {
await page.exposeFunction( 'harness_done', async function( context ) {
console.log( '\n' );

if ( moduleErrors.length > 0 ) {
Expand All @@ -79,7 +67,7 @@ module.exports = function( targetURL ) {
];
console.log( stats.join( ', ' ) );

browser.close();
await page.close();
resolve( stats );
} );

Expand Down

0 comments on commit 283356d

Please sign in to comment.