Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reporter): log a more descriptive test URL in the reporter #5

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/buildTestUrl.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { generateModuleId } from "./generateHash.js";

export function buildTestUrl( {
baseUrl,
browserstack,
flags,
flagHook,
run,
jsdom,
port,
Expand All @@ -19,9 +18,9 @@ export function buildTestUrl( {
for ( const flag of allFlags ) {
const [ key, value ] = flag.split( "=" );

// Special handling for the module flag
if ( key === "module" ) {
query.append( "moduleId", generateModuleId( value ) );
// Allow for custom flag handling
if ( flagHook ) {
query.append.apply( query, flagHook( key, value ) );
} else {
query.append( key, value ?? "true" );
}
Expand All @@ -38,5 +37,7 @@ export function buildTestUrl( {
// BrowserStack supplies a custom domain for local testing,
// which is especially necessary for iOS testing.
const host = browserstack ? "bs-local.com" : "localhost";
return `http://${ host }:${ port }${ baseUrl }${ testUrl }?${ query }`;
return `http://${ host }:${ port }${ baseUrl }${ testUrl }${
query.size > 0 ? `?${ query }` : ""
}`;
}
4 changes: 2 additions & 2 deletions reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ export function reportTest( test, { fullBrowser, id } ) {
}
}

export function reportEnd( result, { fullBrowser, id, url } ) {
export function reportEnd( result, { descriptiveUrl, fullBrowser, id } ) {
console.log(
`\n\nTests finished in ${ prettyMs( result.runtime ) } ` +
`at ${ chalk.yellow( url ) } ` +
`at ${ chalk.yellow( descriptiveUrl ) } ` +
`in ${ chalk.yellow( fullBrowser ) } (${ chalk.bold( id ) })...`
);
console.log(
Expand Down
27 changes: 23 additions & 4 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { localTunnel } from "./browserstack/local.js";
import { reportEnd, reportTest } from "./reporter.js";
import { createTestServer } from "./createTestServer.js";
import { buildTestUrl } from "./lib/buildTestUrl.js";
import { generateHash } from "./lib/generateHash.js";
import { generateHash, generateModuleId } from "./lib/generateHash.js";
import { getBrowserString } from "./lib/getBrowserString.js";
import { cleanupAllBrowsers, touchBrowser } from "./browsers.js";
import {
Expand All @@ -27,6 +27,7 @@ export async function run( {
concurrency,
debug,
flag: flags = [],
flagHook = defaultFlagHook,
hardRetries,
headless,
middleware = [],
Expand Down Expand Up @@ -248,15 +249,21 @@ export async function run( {
`${ hashValue }-${ run }-${ testUrl }-${ fullBrowser }`
);

const url = buildTestUrl( {
const urlOptions = {
baseUrl,
browserstack,
flags,
run,
jsdom: browser.browser === "jsdom",
port,
reportId,
testUrl
};

const descriptiveUrl = buildTestUrl( urlOptions );
const url = buildTestUrl( {
Copy link
Member Author

@timmywil timmywil Feb 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The moduleId replacement and reportId are the things left out of the descriptive URL.

Example for jQuery when running the basic module:

http://localhost:53730/test/?module=basic

...urlOptions,
flagHook,
reportId
} );

const options = {
Expand All @@ -274,8 +281,9 @@ export async function run( {
verbose
};

reports[ reportId ] = {
const report = {
browser,
descriptiveUrl,
flags,
fullBrowser,
headless,
Expand All @@ -285,6 +293,8 @@ export async function run( {
url
};

reports[ reportId ] = report;

addRun( url, browser, options );
}

Expand Down Expand Up @@ -363,3 +373,12 @@ export async function run( {
}
}
}

function defaultFlagHook( key, value ) {

// Convert module flag to module ID
if ( key === "module" ) {
return [ "moduleId", generateModuleId( value ) ];
}
return [ key, value ];
}
2 changes: 1 addition & 1 deletion selenium/createDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default async function createDriver( { browserName, headless, url, verbos
.build();

if ( verbose ) {
const driverCapabilities = await driver.getCapabilities();
const driverCapabilities = driver.getCapabilities();
const name = driverCapabilities.getBrowserName();
const version = driverCapabilities.getBrowserVersion();
console.log( `\nDriver created for ${ name } ${ version }` );
Expand Down
Loading