(
script: unknown,
argument: { readonly arg: unknown } | undefined,
resolvePath: (file: string) => string,
)
| 58 | * argument, as in Playwright. |
| 59 | */ |
| 60 | export 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. */ |
| 78 | export function initScriptLabel(script: unknown): string { |
no test coverage detected