aboutsummaryrefslogtreecommitdiffstats
path: root/tests/runner/selenium/queue.js
diff options
context:
space:
mode:
authorTimmy Willison <timmywil@users.noreply.github.com>2024-03-29 09:13:46 -0400
committerGitHub <noreply@github.com>2024-03-29 09:13:46 -0400
commit91df20be6b488ac6cf4da291d7ee3aa5d6feac73 (patch)
tree56b5c4f8b96a8323e3a6ce9c02c3e84c85a9d6d5 /tests/runner/selenium/queue.js
parent802642c37323d5fc05bfa4cee90a900953f9a98d (diff)
downloadjquery-ui-91df20be6b488ac6cf4da291d7ee3aa5d6feac73.tar.gz
jquery-ui-91df20be6b488ac6cf4da291d7ee3aa5d6feac73.zip
Tests: replace grunt-contrib-qunit with jQuery test runner
- add filestash workflow Close gh-2221
Diffstat (limited to 'tests/runner/selenium/queue.js')
-rw-r--r--tests/runner/selenium/queue.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/runner/selenium/queue.js b/tests/runner/selenium/queue.js
new file mode 100644
index 000000000..de24c5bb0
--- /dev/null
+++ b/tests/runner/selenium/queue.js
@@ -0,0 +1,97 @@
+import chalk from "chalk";
+import { getBrowserString } from "../lib/getBrowserString.js";
+import {
+ checkLastTouches,
+ createBrowserWorker,
+ setBrowserWorkerUrl
+} from "./browsers.js";
+
+const TEST_POLL_TIMEOUT = 1000;
+
+const queue = [];
+
+export function getNextBrowserTest( reportId ) {
+ const index = queue.findIndex( ( test ) => test.id === reportId );
+ if ( index === -1 ) {
+ return;
+ }
+
+ // Remove the completed test from the queue
+ const previousTest = queue[ index ];
+ queue.splice( index, 1 );
+
+ // Find the next test for the same browser
+ for ( const test of queue.slice( index ) ) {
+ if ( test.fullBrowser === previousTest.fullBrowser ) {
+
+ // Set the URL for our tracking
+ setBrowserWorkerUrl( test.browser, test.url );
+ test.running = true;
+
+ // Return the URL for the next test.
+ // listeners.js will use this to set the browser URL.
+ return { url: test.url };
+ }
+ }
+}
+
+export function retryTest( reportId, maxRetries ) {
+ if ( !maxRetries ) {
+ return;
+ }
+ const test = queue.find( ( test ) => test.id === reportId );
+ if ( test ) {
+ test.retries++;
+ if ( test.retries <= maxRetries ) {
+ console.log(
+ `\nRetrying test ${ reportId } for ${ chalk.yellow( test.options.suite ) }...${
+ test.retries
+ }`
+ );
+ return test;
+ }
+ }
+}
+
+export function addRun( url, browser, options ) {
+ queue.push( {
+ browser,
+ fullBrowser: getBrowserString( browser ),
+ id: options.reportId,
+ retries: 0,
+ url,
+ options,
+ running: false
+ } );
+}
+
+export async function runAll() {
+ return new Promise( async( resolve, reject ) => {
+ while ( queue.length ) {
+ try {
+ await checkLastTouches();
+ } catch ( error ) {
+ reject( error );
+ }
+
+ // Run one test URL per browser at a time
+ const browsersTaken = [];
+ for ( const test of queue ) {
+ if ( browsersTaken.indexOf( test.fullBrowser ) > -1 ) {
+ continue;
+ }
+ browsersTaken.push( test.fullBrowser );
+ if ( !test.running ) {
+ test.running = true;
+ try {
+ await createBrowserWorker( test.url, test.browser, test.options );
+ } catch ( error ) {
+ reject( error );
+ }
+ }
+ }
+ await new Promise( ( resolve ) => setTimeout( resolve, TEST_POLL_TIMEOUT ) );
+ }
+ resolve();
+ } );
+}