Skip to content

Commit 06d8166

Browse files
committed
chore: impelemnt json logs and proper counting based on executed
1 parent fd089b4 commit 06d8166

File tree

24 files changed

+267
-736
lines changed

24 files changed

+267
-736
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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"coverage:core": "npm run jest -- --roots packages/core/src --coverage",
1818
"coverage:respect-core": "npm run jest -- --roots packages/respect-core/src --coverage",
1919
"typecheck": "tsc --noEmit --skipLibCheck",
20-
"e2e": "npm run webpack-bundle -- --mode=none && REDOCLY_TELEMETRY=off NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --roots=./__tests__/",
20+
"e2e": "npm run webpack-bundle -- --mode=none && REDOCLY_TELEMETRY=off NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest --roots=./__tests__/ -u",
2121
"prettier": " npx prettier --write \"**/*.{ts,js,yaml,yml,json,md}\"",
2222
"prettier:check": "npx prettier --check \"**/*.{ts,js,yaml,yml,json,md}\"",
2323
"eslint": "eslint packages/**",

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[];
@@ -62,22 +66,39 @@ export async function handleRun({ argv, collectSpecData }: CommandArgs<RespectOp
6266
for (const path of files) {
6367
const result = await runFile(
6468
{ ...argv, file: path },
65-
startedAt,
69+
performance.now(),
6670
{
6771
harFile: harOutputFile,
68-
jsonFile: jsonOutputFile,
6972
},
7073
collectSpecData
7174
);
7275
testsRunProblemsStatus.push(result.hasProblems);
7376
runAllFilesResult.push(result);
7477
}
7578

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

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

96-
const totals = calculateTotals(workflows);
117+
const totals = calculateTotals(executedWorkflows);
97118
const hasProblems = totals.workflows.failed > 0;
119+
const hasWarnings = totals.workflows.warnings > 0;
98120

99121
if (totals.steps.failed > 0 || totals.steps.warnings > 0 || totals.steps.skipped > 0) {
100-
displayErrors(workflows);
122+
displayErrors(executedWorkflows);
101123
}
102124

103-
displaySummary(startedAt, workflows, argv);
125+
displaySummary(startedAt, executedWorkflows, argv);
104126

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

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)