Skip to content

Commit d49c7d8

Browse files
committed
chore: impelemnt json logs and proper counting based on executed
1 parent 814bb9c commit d49c7d8

File tree

23 files changed

+266
-735
lines changed

23 files changed

+266
-735
lines changed

__tests__/respect/reusable-components/__snapshots__/reusable-components.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ exports[`should use inputs from CLI and env to mapp with resolved refs 1`] = `
493493
  
494494
  Workflows: 2 passed, 1 failed, 3 total
495495
  Steps: 5 passed, 1 failed, 6 total
496-
  Checks: 18 passed, 1 failed, 19 total
496+
  Checks: 22 passed, 1 failed, 23 total
497497
  Time: <test>ms
498498
499499

__tests__/respect/server-override-with-console-parameters/__snapshots__/server-override-with-console-parameters.test.ts.snap

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ exports[`should use server override from CLI and env 1`] = `
3232
      }
3333
3434
    ✗ failed network request
35+
3536
────────────────────────────────────────────────────────────────────────────────
3637
3738
Running workflow server-override-with-console-parameters.yaml / events-crud
@@ -54,10 +55,6 @@ exports[`should use server override from CLI and env 1`] = `
5455
    ✗ failed network request
5556
      fetch failed
5657
      
57-
    stepId - buy-ticket
58-
    ✗ unexpected error
59-
    Reason: Failed to resolve output "ticketId" in workflow "get-museum-tickets": Error in resolving runtime expression '$steps.buy-tickets.outputs.ticketId'.
60-
    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.
6158
  Workflow name: events-crud
6259
6360
    stepId - list-events
@@ -83,8 +80,8 @@ exports[`should use server override from CLI and env 1`] = `
8380
  Summary for server-override-with-console-parameters.yaml
8481
  
8582
  Workflows: 2 failed, 2 total
86-
  Steps: 7 failed, 7 total
87-
  Checks: 7 failed, 7 total
83+
  Steps: 6 failed, 6 total
84+
  Checks: 6 failed, 6 total
8885
  Time: <test>ms
8986
9087

__tests__/respect/step-on-failure-type-end-action/__snapshots__/step-on-failure-type-end-action.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ exports[`should end workflow execution, context returns to the caller with appli
3333
  Summary for step-on-failure-type-end-action.yaml
3434
  
3535
  Workflows: 1 passed, 1 failed, 2 total
36-
  Steps: 2 passed, 1 failed, 3 total
36+
  Steps: 1 passed, 1 failed, 2 total
3737
  Checks: 7 passed, 1 failed, 8 total
3838
  Time: <test>ms
3939

__tests__/respect/step-on-success-type-end-action/__snapshots__/step-on-success-type-end-action.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ exports[`should end workflow execution, context returns to the caller with appli
2525
  Summary for step-on-success-type-end-action.yaml
2626
  
2727
  Workflows: 2 passed, 2 total
28-
  Steps: 3 passed, 3 total
28+
  Steps: 2 passed, 2 total
2929
  Checks: 8 passed, 8 total
3030
  Time: <test>ms
3131

__tests__/respect/workflow-failure-actions/__snapshots__/workflow-failure-actions.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ exports[`should execute successActions for each workflow step if it does not hav
5959
  Summary for workflow-failure-actions.yaml
6060
  
6161
  Workflows: 1 failed, 1 total
62-
  Steps: 2 failed, 2 total
63-
  Checks: 6 passed, 2 failed, 8 total
62+
  Steps: 1 passed, 2 failed, 3 total
63+
  Checks: 10 passed, 2 failed, 12 total
6464
  Time: <test>ms
6565
6666

__tests__/respect/workflow-success-actions/__snapshots__/workflow-success-actions.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ exports[`should execute successActions for each workflow step if it does not hav
4444
  Summary for workflow-success-actions.yaml
4545
  
4646
  Workflows: 2 passed, 2 total
47-
  Steps: 3 passed, 3 total
48-
  Checks: 7 passed, 7 total
47+
  Steps: 4 passed, 4 total
48+
  Checks: 15 passed, 15 total
4949
  Time: <test>ms
5050
5151

packages/respect-core/src/handlers/run.ts

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { red } from 'colorette';
1+
import { blue, green, red } from 'colorette';
22
import { type CollectFn } from '@redocly/openapi-core/src/utils';
33
import { runTestFile } from '../modules/flow-runner';
44
import {
55
displayErrors,
66
displaySummary,
77
displayFilesSummaryTable,
88
calculateTotals,
9+
composeJsonLogsFiles,
910
} from '../modules/cli-output';
1011
import { DefaultLogger } from '../utils/logger/logger';
11-
import { type CommandArgs, type RunArgv } from '../types';
1212
import { exitWithError } from '../utils/exit-with-error';
13+
import { writeFileSync } from 'node:fs';
14+
import { indent } from '../utils/cli-outputs';
15+
16+
import type { JsonLogs, CommandArgs, RunArgv } from '../types';
1317

1418
export type RespectOptions = {
1519
files: string[];
@@ -63,22 +67,39 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
6367
for (const path of files) {
6468
const result = await runFile(
6569
{ ...argv, file: path },
66-
startedAt,
70+
performance.now(),
6771
{
6872
harFile: harOutputFile,
69-
jsonFile: jsonOutputFile,
7073
},
7174
collectSpecData
7275
);
7376
testsRunProblemsStatus.push(result.hasProblems);
7477
runAllFilesResult.push(result);
7578
}
7679

80+
const hasProblems = runAllFilesResult.some((result) => result.hasProblems);
81+
const hasWarnings = runAllFilesResult.some((result) => result.hasWarnings);
82+
7783
logger.printNewLine();
7884
displayFilesSummaryTable(runAllFilesResult);
7985
logger.printNewLine();
8086

81-
if (testsRunProblemsStatus.some((problems) => problems)) {
87+
if (jsonOutputFile) {
88+
writeFileSync(
89+
jsonOutputFile,
90+
JSON.stringify({
91+
files: composeJsonLogsFiles(runAllFilesResult),
92+
status: hasProblems ? 'error' : hasWarnings ? 'warn' : 'success',
93+
totalTime: performance.now() - startedAt,
94+
} as JsonLogs),
95+
'utf-8'
96+
);
97+
logger.log(blue(indent(`JSON logs saved in ${green(jsonOutputFile)}`, 2)));
98+
logger.printNewLine();
99+
logger.printNewLine();
100+
}
101+
102+
if (hasProblems) {
82103
throw new Error(' Tests exited with error ');
83104
}
84105
} catch (err) {
@@ -89,19 +110,29 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
89110
async function runFile(
90111
argv: RunArgv,
91112
startedAt: number,
92-
output: { harFile: string | undefined; jsonFile: string | undefined },
113+
output: { harFile: string | undefined },
93114
collectSpecData?: CollectFn
94115
) {
95-
const { workflows } = await runTestFile(argv, output, collectSpecData);
116+
const { executedWorkflows, ctx } = await runTestFile(argv, output, collectSpecData);
96117

97-
const totals = calculateTotals(workflows);
118+
const totals = calculateTotals(executedWorkflows);
98119
const hasProblems = totals.workflows.failed > 0;
120+
const hasWarnings = totals.workflows.warnings > 0;
99121

100122
if (totals.steps.failed > 0 || totals.steps.warnings > 0 || totals.steps.skipped > 0) {
101-
displayErrors(workflows);
123+
displayErrors(executedWorkflows);
102124
}
103125

104-
displaySummary(startedAt, workflows, argv);
126+
displaySummary(startedAt, executedWorkflows, argv);
105127

106-
return { hasProblems, file: argv.file, workflows, argv };
128+
return {
129+
hasProblems,
130+
hasWarnings,
131+
file: argv.file,
132+
executedWorkflows,
133+
argv,
134+
ctx,
135+
totalTimeMs: performance.now() - startedAt,
136+
totalRequests: totals.totalRequests,
137+
};
107138
}

packages/respect-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { handleGenerate, handleRun } from './handlers/index';
22
export type { GenerateArazzoFileOptions } from './handlers/generate';
33
export type { RespectOptions } from './handlers/run';
4+
export type { JsonLogs } from './types';

0 commit comments

Comments
 (0)