Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ exports[`should use inputs from CLI and env to mapp with resolved refs 1`] = `

  Workflows: 2 passed, 1 failed, 3 total
  Steps: 5 passed, 1 failed, 6 total
  Checks: 18 passed, 1 failed, 19 total
  Checks: 22 passed, 1 failed, 23 total
  Time: <test>ms


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports[`should use server override from CLI and env 1`] = `
      }

    ✗ failed network request

────────────────────────────────────────────────────────────────────────────────

Running workflow server-override-with-console-parameters.yaml / events-crud
Expand All @@ -54,10 +55,6 @@ exports[`should use server override from CLI and env 1`] = `
    ✗ failed network request
      fetch failed

    stepId - buy-ticket
    ✗ unexpected error
    Reason: Failed to resolve outputs in workflow "get-museum-tickets": Error in resolving runtime expression '$steps.buy-tickets.outputs.ticketId'.
    This could be because the expression references a value from a previous failed step, or is trying to reference a variable that hasn't been set.
  Workflow name: events-crud

    stepId - list-events
Expand All @@ -83,8 +80,8 @@ exports[`should use server override from CLI and env 1`] = `
  Summary for server-override-with-console-parameters.yaml

  Workflows: 2 failed, 2 total
  Steps: 7 failed, 7 total
  Checks: 7 failed, 7 total
  Steps: 6 failed, 6 total
  Checks: 6 failed, 6 total
  Time: <test>ms


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports[`should end workflow execution, context returns to the caller with appli
  Summary for step-on-failure-type-end-action.yaml

  Workflows: 1 passed, 1 failed, 2 total
  Steps: 2 passed, 1 failed, 3 total
  Steps: 1 passed, 1 failed, 2 total
  Checks: 7 passed, 1 failed, 8 total
  Time: <test>ms

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`should end workflow execution, context returns to the caller with appli
  Summary for step-on-success-type-end-action.yaml

  Workflows: 2 passed, 2 total
  Steps: 3 passed, 3 total
  Steps: 2 passed, 2 total
  Checks: 8 passed, 8 total
  Time: <test>ms

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ exports[`should execute successActions for each workflow step if it does not hav
  Summary for workflow-failure-actions.yaml

  Workflows: 1 failed, 1 total
  Steps: 2 failed, 2 total
  Checks: 6 passed, 2 failed, 8 total
  Steps: 1 passed, 2 failed, 3 total
  Checks: 10 passed, 2 failed, 12 total
  Time: <test>ms


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ exports[`should execute successActions for each workflow step if it does not hav
  Summary for workflow-success-actions.yaml

  Workflows: 2 passed, 2 total
  Steps: 3 passed, 3 total
  Checks: 7 passed, 7 total
  Steps: 4 passed, 4 total
  Checks: 15 passed, 15 total
  Time: <test>ms


Expand Down
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ module.exports = {
lines: 64,
},
'packages/respect-core/': {
statements: 83,
branches: 74,
functions: 84,
lines: 84,
statements: 79,
branches: 68,
functions: 75,
lines: 79,
},
},
testMatch: ['**/__tests__/**/*.test.ts', '**/*.test.ts'],
Expand Down
53 changes: 42 additions & 11 deletions packages/respect-core/src/handlers/run.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { red } from 'colorette';
import { blue, green, red } from 'colorette';
import { type CollectFn } from '@redocly/openapi-core/src/utils';
import { runTestFile } from '../modules/flow-runner';
import {
displayErrors,
displaySummary,
displayFilesSummaryTable,
calculateTotals,
composeJsonLogsFiles,
} from '../modules/cli-output';
import { DefaultLogger } from '../utils/logger/logger';
import { type CommandArgs, type RunArgv } from '../types';
import { exitWithError } from '../utils/exit-with-error';
import { writeFileSync } from 'node:fs';
import { indent } from '../utils/cli-outputs';

import type { JsonLogs, CommandArgs, RunArgv } from '../types';

export type RespectOptions = {
files: string[];
Expand Down Expand Up @@ -63,22 +67,39 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
for (const path of files) {
const result = await runFile(
{ ...argv, file: path },
startedAt,
performance.now(),
{
harFile: harOutputFile,
jsonFile: jsonOutputFile,
},
collectSpecData
);
testsRunProblemsStatus.push(result.hasProblems);
runAllFilesResult.push(result);
}

const hasProblems = runAllFilesResult.some((result) => result.hasProblems);
const hasWarnings = runAllFilesResult.some((result) => result.hasWarnings);

logger.printNewLine();
displayFilesSummaryTable(runAllFilesResult);
logger.printNewLine();

if (testsRunProblemsStatus.some((problems) => problems)) {
if (jsonOutputFile) {
writeFileSync(
jsonOutputFile,
JSON.stringify({
files: composeJsonLogsFiles(runAllFilesResult),
status: hasProblems ? 'error' : hasWarnings ? 'warn' : 'success',
totalTime: performance.now() - startedAt,
} as JsonLogs),
'utf-8'
);
logger.log(blue(indent(`JSON logs saved in ${green(jsonOutputFile)}`, 2)));
logger.printNewLine();
logger.printNewLine();
}

if (hasProblems) {
throw new Error(' Tests exited with error ');
}
} catch (err) {
Expand All @@ -89,19 +110,29 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
async function runFile(
argv: RunArgv,
startedAt: number,
output: { harFile: string | undefined; jsonFile: string | undefined },
output: { harFile: string | undefined },
collectSpecData?: CollectFn
) {
const { workflows } = await runTestFile(argv, output, collectSpecData);
const { executedWorkflows, ctx } = await runTestFile(argv, output, collectSpecData);

const totals = calculateTotals(workflows);
const totals = calculateTotals(executedWorkflows);
const hasProblems = totals.workflows.failed > 0;
const hasWarnings = totals.workflows.warnings > 0;

if (totals.steps.failed > 0 || totals.steps.warnings > 0 || totals.steps.skipped > 0) {
displayErrors(workflows);
displayErrors(executedWorkflows);
}

displaySummary(startedAt, workflows, argv);
displaySummary(startedAt, executedWorkflows, argv);

return { hasProblems, file: argv.file, workflows, argv };
return {
hasProblems,
hasWarnings,
file: argv.file,
executedWorkflows,
argv,
ctx,
totalTimeMs: performance.now() - startedAt,
totalRequests: totals.totalRequests,
};
}
1 change: 1 addition & 0 deletions packages/respect-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { handleGenerate, handleRun } from './handlers/index';
export type { GenerateArazzoFileOptions } from './handlers/generate';
export type { RespectOptions } from './handlers/run';
export type { JsonLogs } from './types';
Loading
Loading