diff options
author | Timmy Willison <timmywil@users.noreply.github.com> | 2024-04-01 10:23:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-01 10:23:36 -0400 |
commit | 284b082eb86602705519d6ca754c40f6d2f8fcc0 (patch) | |
tree | be30f1d0656bdab531f9eeefacc2a99e7d6d70bf /test/runner/selenium | |
parent | 691c0aeeded5dea1ca2a0c5474c7adfdb1dadffe (diff) | |
download | jquery-284b082eb86602705519d6ca754c40f6d2f8fcc0.tar.gz jquery-284b082eb86602705519d6ca754c40f6d2f8fcc0.zip |
Tests: share queue/browser handling for all worker types
- one queue to rule them all: browserstack, selenium, and jsdom
- retries and hard retries are now supported in selenium
- selenium tests now re-use browsers in the same way as browserstack
Close gh-5460
Diffstat (limited to 'test/runner/selenium')
-rw-r--r-- | test/runner/selenium/createDriver.js | 5 | ||||
-rw-r--r-- | test/runner/selenium/queue.js | 70 | ||||
-rw-r--r-- | test/runner/selenium/runSelenium.js | 30 |
3 files changed, 4 insertions, 101 deletions
diff --git a/test/runner/selenium/createDriver.js b/test/runner/selenium/createDriver.js index d1680b22d..095c12214 100644 --- a/test/runner/selenium/createDriver.js +++ b/test/runner/selenium/createDriver.js @@ -7,7 +7,7 @@ import { browserSupportsHeadless } from "../lib/getBrowserString.js"; // Set script timeout to 10min const DRIVER_SCRIPT_TIMEOUT = 1000 * 60 * 10; -export default async function createDriver( { browserName, headless, verbose } ) { +export default async function createDriver( { browserName, headless, url, verbose } ) { const capabilities = Capabilities[ browserName ](); const prefs = new logging.Preferences(); prefs.setLevel( logging.Type.BROWSER, logging.Level.ALL ); @@ -77,5 +77,8 @@ export default async function createDriver( { browserName, headless, verbose } ) // Increase script timeout to 10min await driver.manage().setTimeouts( { script: DRIVER_SCRIPT_TIMEOUT } ); + // Set the first URL for the browser + await driver.get( url ); + return driver; } diff --git a/test/runner/selenium/queue.js b/test/runner/selenium/queue.js deleted file mode 100644 index 863db4d9b..000000000 --- a/test/runner/selenium/queue.js +++ /dev/null @@ -1,70 +0,0 @@ -// Build a queue that runs both browsers and modules -// in parallel when the length reaches the concurrency limit -// and refills the queue when one promise resolves. - -import chalk from "chalk"; -import { getBrowserString } from "../lib/getBrowserString.js"; -import { runSelenium } from "./runSelenium.js"; -import { runJSDOM } from "../jsdom.js"; - -const promises = []; -const queue = []; - -const SELENIUM_WAIT_TIME = 100; - -// Limit concurrency to 8 by default in selenium -// BrowserStack defaults to the max allowed by the plan -// More than this will log MaxListenersExceededWarning -const MAX_CONCURRENCY = 8; - -export function addSeleniumRun( url, browser, options ) { - queue.push( { url, browser, options } ); -} - -export async function runAllSelenium( { concurrency = MAX_CONCURRENCY, verbose } ) { - while ( queue.length ) { - const next = queue.shift(); - const { url, browser, options } = next; - - const fullBrowser = getBrowserString( browser, options.headless ); - console.log( - `\nRunning ${ chalk.yellow( options.modules.join( ", " ) ) } tests ` + - `in ${ chalk.yellow( fullBrowser ) } (${ chalk.bold( options.reportId ) })...` - ); - - // Wait enough time between requests - // to give concurrency a chance to update. - // In selenium, this helps avoid undici connect timeout errors. - await new Promise( ( resolve ) => setTimeout( resolve, SELENIUM_WAIT_TIME ) ); - - if ( verbose ) { - console.log( `\nTests remaining: ${ queue.length + 1 }.` ); - } - - let promise; - if ( browser.browser === "jsdom" ) { - promise = runJSDOM( url, options ); - } else { - promise = runSelenium( url, browser, options ); - } - - // Remove the promise from the list when it resolves - promise.then( () => { - const index = promises.indexOf( promise ); - if ( index !== -1 ) { - promises.splice( index, 1 ); - } - } ); - - // Add the promise to the list - promises.push( promise ); - - // Wait until at least one promise resolves - // if we've reached the concurrency limit - if ( promises.length >= concurrency ) { - await Promise.any( promises ); - } - } - - await Promise.all( promises ); -} diff --git a/test/runner/selenium/runSelenium.js b/test/runner/selenium/runSelenium.js deleted file mode 100644 index 848db36c7..000000000 --- a/test/runner/selenium/runSelenium.js +++ /dev/null @@ -1,30 +0,0 @@ -import createDriver from "./createDriver.js"; - -export async function runSelenium( - url, - { browser }, - { debug, headless, verbose } = {} -) { - if ( debug && headless ) { - throw new Error( "Cannot debug in headless mode." ); - } - - const driver = await createDriver( { - browserName: browser, - headless, - verbose - } ); - - try { - await driver.get( url ); - await driver.executeScript( -`return new Promise( ( resolve ) => { - QUnit.on( "runEnd", resolve ); -} )` - ); - } finally { - if ( !debug || headless ) { - await driver.quit(); - } - } -} |