Skip to content

Commit

Permalink
fix: errored or skipped referenced httpregion also skips current http…
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Jan 2, 2025
1 parent f7c692b commit d9e932e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
21 changes: 0 additions & 21 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,6 @@
"send",
"${file}",
"--all",
"--bail",
"-o",
"short"
],
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
},
{
"type": "node",
"request": "launch",
"name": "debug files",
"skipFiles": [
"<node_internals>/**"
],
"cwd": "${workspaceFolder:httpyac.github.io}/examples/",
"console": "integratedTerminal",
"program": "${workspaceFolder}/bin/httpyac.js",
"args": [
"send",
"**/*.http",
"-o",
"short"
],
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Fix
- ensure correct order if cli args are used (#773)
- errored or skipped referenced httpregion also skips current http region (#842, AnWeber/vscode-httpyac#339)


## [6.16.4] (2024-11-03)
Expand Down
6 changes: 4 additions & 2 deletions src/httpYacApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ async function sendHttpRegions(context: models.HttpRegionsSendContext): Promise<
if (context.progress) {
context.progress.divider = context.httpRegions.length;
}
let status = true;
for (const httpRegion of context.httpRegions) {
await httpRegion.execute(processorContext, true);
const result = await httpRegion.execute(processorContext, true);
status = status && result;
}
return true;
return status;
}
return false;
}
Expand Down
12 changes: 12 additions & 0 deletions src/plugins/core/metaData/refMetaDataHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { log } from '../../../io';
import * as models from '../../../models';
import * as utils from '../../../utils';
import { addSkippedTestResult } from '../../../utils';

export function refMetaDataHandler(type: string, name: string | undefined, context: models.ParserContext): boolean {
if (['ref', 'forceRef'].indexOf(type) >= 0 && name) {
Expand Down Expand Up @@ -36,6 +37,11 @@ class RefMetaAction {
utils.report(context, `load reference ${name}`);
const reference = utils.findHttpRegionInContext(name, context);
if (reference) {
if (this.isReferenceErroredOrSkipped(reference)) {
addSkippedTestResult(context.httpRegion);
return false;
}

const envKey = utils.toEnvironmentKey(context.activeEnvironment);
utils.setVariableInContext(reference.variablesPerEnv[envKey], context);
log.trace('import variables', reference.variablesPerEnv[envKey]);
Expand All @@ -55,4 +61,10 @@ class RefMetaAction {
}
return result;
}

private isReferenceErroredOrSkipped(ref: models.HttpRegion) {
return !!ref.testResults?.some(
t => t.status === models.TestResultStatus.ERROR || t.status === models.TestResultStatus.SKIPPED
);
}
}
13 changes: 12 additions & 1 deletion src/store/httpRegion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Hook, HookCancel } from 'hookpoint';

import * as models from '../models';
import { addHttpFileRequestClientHooks, isError, toEnvironmentKey } from '../utils';
import {
addHttpFileRequestClientHooks,
addTestResultToHttpRegion,
isError,
parseError,
toEnvironmentKey,
} from '../utils';

export class HttpRegion implements models.HttpRegion {
request?: models.Request<string, models.RequestBody> | undefined;
Expand Down Expand Up @@ -92,6 +98,11 @@ export class HttpRegion implements models.HttpRegion {
return result !== HookCancel && result.every(obj => !!obj);
} catch (err) {
if (isError(err)) {
addTestResultToHttpRegion(this, {
message: err.message,
status: models.TestResultStatus.ERROR,
error: parseError(err),
});
if (!err.handled) {
await context.logResponse?.(this.response, this);
err.handled = true;
Expand Down

0 comments on commit d9e932e

Please sign in to comment.