aboutsummaryrefslogtreecommitdiffstats
path: root/test/runner/lib/buildTestUrl.js
blob: 6e0f1a9b0211bb2ab8ba3f3b32ae79175fcc2e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { generateModuleId } from "./generateHash.js";

export function buildTestUrl( modules, { browserstack, esm, jsdom, port, reportId } ) {
	if ( !port ) {
		throw new Error( "No port specified." );
	}

	const query = new URLSearchParams();
	for ( const module of modules ) {
		query.append( "moduleId", generateModuleId( module ) );
	}

	if ( esm ) {
		query.append( "esmodules", "true" );
	}

	if ( jsdom ) {
		query.append( "jsdom", "true" );
	}

	if ( reportId ) {
		query.append( "reportId", reportId );
	}

	// 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 }/test/?${ query }`;
}