From fa0b37f6ef972ac47033bee428e0e3b7b18e654a Mon Sep 17 00:00:00 2001 From: Gert Hengeveld Date: Sat, 14 Oct 2023 23:09:20 +0200 Subject: [PATCH] Fix missing options object in runAll and ensure exitCode and http client is properly set in tests --- node-src/index.ts | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/node-src/index.ts b/node-src/index.ts index 0af5fb5c8..9f6f91ebf 100644 --- a/node-src/index.ts +++ b/node-src/index.ts @@ -40,10 +40,11 @@ interface Output { export type { Flags, Options, TaskName, Context, Configuration } from './types'; +// Main entry point for CLI, GitHub Action and Node API export async function run({ argv = [], flags, - options, + options: extraOptions, }: { argv?: string[]; flags?: Flags; @@ -67,22 +68,27 @@ export async function run({ const ctx: AtLeast< Context, - 'argv' | 'flags' | 'help' | 'pkg' | 'packagePath' | 'packageJson' | 'env' | 'log' | 'sessionId' + | 'argv' + | 'flags' + | 'extraOptions' + | 'help' + | 'pkg' + | 'packagePath' + | 'packageJson' + | 'env' + | 'log' + | 'sessionId' > = { ...parseArgs(argv), + ...(flags && { flags }), + ...(extraOptions && { extraOptions }), packagePath, packageJson, env, log, sessionId, - ...(flags && { flags }), }; - setExitCode(ctx, exitCodes.OK); - - ctx.http = (ctx.http as HTTPClient) || new HTTPClient(ctx); - ctx.extraOptions = options; - await runAll(ctx as Context); return { @@ -103,7 +109,12 @@ export async function run({ }; } +// Entry point for testing export async function runAll(ctx: Context) { + setExitCode(ctx, exitCodes.OK); + + ctx.http = (ctx.http as HTTPClient) || new HTTPClient(ctx); + // Run these in parallel; neither should ever reject await Promise.all([runBuild(ctx), checkForUpdates(ctx)]); @@ -111,11 +122,11 @@ export async function runAll(ctx: Context) { await checkPackageJson(ctx); } - if (ctx.options.diagnostics) { + if (ctx.flags?.diagnostics || ctx.extraOptions?.diagnostics) { await writeChromaticDiagnostics(ctx); } - if (ctx.options.uploadMetadata) { + if (ctx.flags?.uploadMetadata || ctx.extraOptions?.uploadMetadata) { await uploadMetadataFiles(ctx); } }