MCPcopy Create free account
hub / github.com/tester-army/e2e / testInitScriptSource

Function testInitScriptSource

packages/web/src/init-scripts.ts:60–75  ·  view source on GitHub ↗
(
  script: unknown,
  argument: { readonly arg: unknown } | undefined,
  resolvePath: (file: string) => string,
)

Source from the content-addressed store, hash-verified

58 * argument, as in Playwright.
59 */
60export async function testInitScriptSource(
61 script: unknown,
62 argument: { readonly arg: unknown } | undefined,
63 resolvePath: (file: string) => string,
64): Promise<string> {
65 assertInitScript(script, (problem) => new TestError('INVALID_ARGUMENT', `browser.addInitScript script ${problem}`));
66 if (argument !== undefined && typeof script !== 'function') {
67 throw new TestError('INVALID_ARGUMENT', 'browser.addInitScript takes an argument only with a function script');
68 }
69 validateJsonValue(argument?.arg, 'addInitScript argument');
70 try {
71 return await initScriptSource(script, argument?.arg as JsonValue | undefined, resolvePath);
72 } catch (cause) {
73 throw new TestError('INVALID_ARGUMENT', `browser.addInitScript ${message(cause)}`, { cause });
74 }
75}
76
77/** The step label of a script: the file a `path` names, else its kind, never its source. */
78export function initScriptLabel(script: unknown): string {

Callers 1

addInitScriptFunction · 0.90

Calls 4

messageFunction · 0.90
assertInitScriptFunction · 0.85
validateJsonValueFunction · 0.85
initScriptSourceFunction · 0.85

Tested by

no test coverage detected