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

Function assertInitScript

packages/web/src/init-scripts.ts:84–93  ·  view source on GitHub ↗

Throws what `fail` makes of the problem unless `script` is one init script.

(script: unknown, fail: (problem: string) => Error)

Source from the content-addressed store, hash-verified

82
83/** Throws what `fail` makes of the problem unless `script` is one init script. */
84function assertInitScript(script: unknown, fail: (problem: string) => Error): asserts script is WebInitScript {
85 if (typeof script === 'string' || typeof script === 'function') return;
86 if (typeof script !== 'object' || script === null || Array.isArray(script)) {
87 const got = script === null ? 'null' : Array.isArray(script) ? 'an array' : typeof script;
88 throw fail(`must be a string of source, a { path }, or a function, got ${got}`);
89 }
90 const unknown = Object.keys(script).filter((key) => key !== 'path');
91 if (unknown.length > 0) throw fail(`takes only path, got ${unknown.join(', ')}`);
92 if (!('path' in script) || typeof script.path !== 'string' || script.path === '') throw fail('path must be a non-empty string');
93}
94
95/**
96 * The page source of one script. A function is called with its JSON argument

Callers 2

validateInitScriptsFunction · 0.85
testInitScriptSourceFunction · 0.85

Calls 2

filterMethod · 0.65
failFunction · 0.50

Tested by

no test coverage detected