MCPcopy Index your code
hub / github.com/code-pushup/cli / createRunnerFunction

Function createRunnerFunction

packages/plugin-lighthouse/src/lib/runner/runner.ts:31–65  ·  view source on GitHub ↗
(
  urls: string[],
  flags: LighthouseCliFlags = DEFAULT_CLI_FLAGS,
)

Source from the content-addressed store, hash-verified

29} from './utils.js';
30
31export function createRunnerFunction(
32 urls: string[],
33 flags: LighthouseCliFlags = DEFAULT_CLI_FLAGS,
34): RunnerFunction {
35 return withLocalTmpDir(async (): Promise<AuditOutputs> => {
36 const config = await getConfig(flags);
37 const normalizationFlags = enrichFlags(flags);
38 const urlsCount = urls.length;
39 const isSingleUrl = !shouldExpandForUrls(urlsCount);
40
41 const allResults = await asyncSequential(urls, (url, urlIndex) => {
42 const enrichedFlags = isSingleUrl
43 ? normalizationFlags
44 : enrichFlags(flags, urlIndex + 1);
45 const step = { urlIndex, urlsCount };
46 return runLighthouseForUrl(url, enrichedFlags, config, step);
47 });
48
49 const collectedResults = allResults.filter(res => res != null);
50 if (collectedResults.length === 0) {
51 throw new Error(
52 isSingleUrl
53 ? 'Lighthouse did not produce a result.'
54 : 'Lighthouse failed to produce results for all URLs.',
55 );
56 }
57
58 logResultsForAllUrls(collectedResults);
59
60 const auditOutputs: AuditOutputs = collectedResults.flatMap(
61 res => res.auditOutputs,
62 );
63 return filterAuditOutputs(auditOutputs, normalizationFlags);
64 });
65}
66
67type ResultForUrl = {
68 url: string;

Callers

nothing calls this directly

Calls 8

shouldExpandForUrlsFunction · 0.90
asyncSequentialFunction · 0.90
withLocalTmpDirFunction · 0.85
getConfigFunction · 0.85
enrichFlagsFunction · 0.85
runLighthouseForUrlFunction · 0.85
filterAuditOutputsFunction · 0.85
logResultsForAllUrlsFunction · 0.70

Tested by

no test coverage detected