Skip to content

Commit

Permalink
Fix missing options object in runAll and ensure exitCode and http cli…
Browse files Browse the repository at this point in the history
…ent is properly set in tests
  • Loading branch information
ghengeveld committed Oct 14, 2023
1 parent 9db311c commit fa0b37f
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions node-src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -103,19 +109,24 @@ 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)]);

if (ctx.exitCode === 0 || ctx.exitCode === 1) {
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);
}
}
Expand Down

0 comments on commit fa0b37f

Please sign in to comment.