Skip to content

Commit 1ec6289

Browse files
committed
fix(reporter): log a more descriptive test URL in the reporter
- Also update all submodules for tests
1 parent b5487da commit 1ec6289

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

lib/buildTestUrl.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { generateModuleId } from "./generateHash.js";
2-
31
export function buildTestUrl( {
42
baseUrl,
53
browserstack,
64
flags,
5+
flagHook,
76
run,
87
jsdom,
98
port,
@@ -19,9 +18,9 @@ export function buildTestUrl( {
1918
for ( const flag of allFlags ) {
2019
const [ key, value ] = flag.split( "=" );
2120

22-
// Special handling for the module flag
23-
if ( key === "module" ) {
24-
query.append( "moduleId", generateModuleId( value ) );
21+
// Allow for custom flag handling
22+
if ( flagHook ) {
23+
query.append.apply( query, flagHook( key, value ) );
2524
} else {
2625
query.append( key, value ?? "true" );
2726
}
@@ -38,5 +37,7 @@ export function buildTestUrl( {
3837
// BrowserStack supplies a custom domain for local testing,
3938
// which is especially necessary for iOS testing.
4039
const host = browserstack ? "bs-local.com" : "localhost";
41-
return `http://${ host }:${ port }${ baseUrl }${ testUrl }?${ query }`;
40+
return `http://${ host }:${ port }${ baseUrl }${ testUrl }${
41+
query.size > 0 ? `?${ query }` : ""
42+
}`;
4243
}

reporter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ export function reportTest( test, { fullBrowser, id } ) {
113113
}
114114
}
115115

116-
export function reportEnd( result, { fullBrowser, id, url } ) {
116+
export function reportEnd( result, { descriptiveUrl, fullBrowser, id } ) {
117117
console.log(
118118
`\n\nTests finished in ${ prettyMs( result.runtime ) } ` +
119-
`at ${ chalk.yellow( url ) } ` +
119+
`at ${ chalk.yellow( descriptiveUrl ) } ` +
120120
`in ${ chalk.yellow( fullBrowser ) } (${ chalk.bold( id ) })...`
121121
);
122122
console.log(

run.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { localTunnel } from "./browserstack/local.js";
66
import { reportEnd, reportTest } from "./reporter.js";
77
import { createTestServer } from "./createTestServer.js";
88
import { buildTestUrl } from "./lib/buildTestUrl.js";
9-
import { generateHash } from "./lib/generateHash.js";
9+
import { generateHash, generateModuleId } from "./lib/generateHash.js";
1010
import { getBrowserString } from "./lib/getBrowserString.js";
1111
import { cleanupAllBrowsers, touchBrowser } from "./browsers.js";
1212
import {
@@ -27,6 +27,7 @@ export async function run( {
2727
concurrency,
2828
debug,
2929
flag: flags = [],
30+
flagHook = defaultFlagHook,
3031
hardRetries,
3132
headless,
3233
middleware = [],
@@ -248,15 +249,21 @@ export async function run( {
248249
`${ hashValue }-${ run }-${ testUrl }-${ fullBrowser }`
249250
);
250251

251-
const url = buildTestUrl( {
252+
const urlOptions = {
252253
baseUrl,
253254
browserstack,
254255
flags,
255256
run,
256257
jsdom: browser.browser === "jsdom",
257258
port,
258-
reportId,
259259
testUrl
260+
};
261+
262+
const descriptiveUrl = buildTestUrl( urlOptions );
263+
const url = buildTestUrl( {
264+
...urlOptions,
265+
flagHook,
266+
reportId
260267
} );
261268

262269
const options = {
@@ -274,8 +281,9 @@ export async function run( {
274281
verbose
275282
};
276283

277-
reports[ reportId ] = {
284+
const report = {
278285
browser,
286+
descriptiveUrl,
279287
flags,
280288
fullBrowser,
281289
headless,
@@ -285,6 +293,8 @@ export async function run( {
285293
url
286294
};
287295

296+
reports[ reportId ] = report;
297+
288298
addRun( url, browser, options );
289299
}
290300

@@ -363,3 +373,12 @@ export async function run( {
363373
}
364374
}
365375
}
376+
377+
function defaultFlagHook( key, value ) {
378+
379+
// Convert module flag to module ID
380+
if ( key === "module" ) {
381+
return [ "moduleId", generateModuleId( value ) ];
382+
}
383+
return [ key, value ];
384+
}

0 commit comments

Comments
 (0)