aboutsummaryrefslogtreecommitdiffstats
path: root/tests/runner/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/runner/lib')
-rw-r--r--tests/runner/lib/buildTestUrl.js21
-rw-r--r--tests/runner/lib/generateHash.js10
-rw-r--r--tests/runner/lib/getBrowserString.js49
-rw-r--r--tests/runner/lib/prettyMs.js18
4 files changed, 98 insertions, 0 deletions
diff --git a/tests/runner/lib/buildTestUrl.js b/tests/runner/lib/buildTestUrl.js
new file mode 100644
index 000000000..826548852
--- /dev/null
+++ b/tests/runner/lib/buildTestUrl.js
@@ -0,0 +1,21 @@
+export function buildTestUrl( suite, { jquery, migrate, port, reportId } ) {
+ if ( !port ) {
+ throw new Error( "No port specified." );
+ }
+
+ const query = new URLSearchParams();
+
+ if ( jquery ) {
+ query.append( "jquery", jquery );
+ }
+
+ if ( migrate ) {
+ query.append( "migrate", "true" );
+ }
+
+ if ( reportId ) {
+ query.append( "reportId", reportId );
+ }
+
+ return `http://localhost:${ port }/tests/unit/${ suite }/${ suite }.html?${ query }`;
+}
diff --git a/tests/runner/lib/generateHash.js b/tests/runner/lib/generateHash.js
new file mode 100644
index 000000000..66f2161d5
--- /dev/null
+++ b/tests/runner/lib/generateHash.js
@@ -0,0 +1,10 @@
+import crypto from "node:crypto";
+
+export function generateHash( string ) {
+ const hash = crypto.createHash( "md5" );
+ hash.update( string );
+
+ // QUnit hashes are 8 characters long
+ // We use 10 characters to be more visually distinct
+ return hash.digest( "hex" ).slice( 0, 10 );
+}
diff --git a/tests/runner/lib/getBrowserString.js b/tests/runner/lib/getBrowserString.js
new file mode 100644
index 000000000..413a60500
--- /dev/null
+++ b/tests/runner/lib/getBrowserString.js
@@ -0,0 +1,49 @@
+const browserMap = {
+ chrome: "Chrome",
+ edge: "Edge",
+ firefox: "Firefox",
+ ie: "IE",
+ jsdom: "JSDOM",
+ opera: "Opera",
+ safari: "Safari"
+};
+
+export function browserSupportsHeadless( browser ) {
+ browser = browser.toLowerCase();
+ return (
+ browser === "chrome" ||
+ browser === "firefox" ||
+ browser === "edge"
+ );
+}
+
+export function getBrowserString(
+ {
+ browser,
+ browser_version: browserVersion,
+ device,
+ os,
+ os_version: osVersion
+ },
+ headless
+) {
+ browser = browser.toLowerCase();
+ browser = browserMap[ browser ] || browser;
+ let str = browser;
+ if ( browserVersion ) {
+ str += ` ${ browserVersion }`;
+ }
+ if ( device ) {
+ str += ` for ${ device }`;
+ }
+ if ( os ) {
+ str += ` on ${ os }`;
+ }
+ if ( osVersion ) {
+ str += ` ${ osVersion }`;
+ }
+ if ( headless && browserSupportsHeadless( browser ) ) {
+ str += " (headless)";
+ }
+ return str;
+}
diff --git a/tests/runner/lib/prettyMs.js b/tests/runner/lib/prettyMs.js
new file mode 100644
index 000000000..99bae2b35
--- /dev/null
+++ b/tests/runner/lib/prettyMs.js
@@ -0,0 +1,18 @@
+/**
+ * Pretty print a time in milliseconds.
+ */
+export function prettyMs( time ) {
+ const minutes = Math.floor( time / 60000 );
+ const seconds = Math.floor( time / 1000 );
+ const ms = Math.floor( time % 1000 );
+
+ let prettyTime = `${ ms }ms`;
+ if ( seconds > 0 ) {
+ prettyTime = `${ seconds }s ${ prettyTime }`;
+ }
+ if ( minutes > 0 ) {
+ prettyTime = `${ minutes }m ${ prettyTime }`;
+ }
+
+ return prettyTime;
+}