1 import chalk from "chalk";
2 import { getBrowserString } from "./lib/getBrowserString.js";
8 } from "./browsers.js";
10 const TEST_POLL_TIMEOUT = 1000;
14 export function getNextBrowserTest( reportId ) {
15 const index = queue.findIndex( ( test ) => test.id === reportId );
20 // Remove the completed test from the queue
21 const previousTest = queue[ index ];
22 queue.splice( index, 1 );
24 // Find the next test for the same browser
25 for ( const test of queue.slice( index ) ) {
26 if ( test.fullBrowser === previousTest.fullBrowser ) {
28 // Set the URL for our tracking
29 setBrowserWorkerUrl( test.browser, test.url );
32 // Return the URL for the next test.
33 // listeners.js will use this to set the browser URL.
34 return { url: test.url };
39 export function retryTest( reportId, maxRetries ) {
43 const test = queue.find( ( test ) => test.id === reportId );
46 if ( test.retries <= maxRetries ) {
48 `\nRetrying test ${ reportId } for ${ chalk.yellow(
49 test.options.modules.join( ", " )
50 ) }...${ test.retries }`
57 export async function hardRetryTest( reportId, maxHardRetries ) {
58 if ( !maxHardRetries ) {
61 const test = queue.find( ( test ) => test.id === reportId );
64 if ( test.hardRetries <= maxHardRetries ) {
66 `\nHard retrying test ${ reportId } for ${ chalk.yellow(
67 test.options.modules.join( ", " )
68 ) }...${ test.hardRetries }`
70 await restartBrowser( test.browser );
77 export function addRun( url, browser, options ) {
80 fullBrowser: getBrowserString( browser ),
90 export async function runAll() {
91 return new Promise( async( resolve, reject ) => {
92 while ( queue.length ) {
94 await checkLastTouches();
99 // Run one test URL per browser at a time
100 const browsersTaken = [];
101 for ( const test of queue ) {
102 if ( browsersTaken.indexOf( test.fullBrowser ) > -1 ) {
105 browsersTaken.push( test.fullBrowser );
106 if ( !test.running ) {
109 await createBrowserWorker( test.url, test.browser, test.options );
115 await new Promise( ( resolve ) => setTimeout( resolve, TEST_POLL_TIMEOUT ) );