Skip to content

Commit

Permalink
fix: support of --bail does also work in referenced http files (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Sep 6, 2023
1 parent 8fd9e32 commit e4f867a
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [6.6.5] (2023-09-06)

### Fixes

- support of `--bail` does also work in referenced http files (#540)

## [6.6.4] (2023-09-02)

### Fixes
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"publisher": "AnWeber",
"description": "HTTP/REST CLI Client for *.http files",
"version": "6.6.4",
"version": "6.6.5",
"homepage": "https://github.com/AnWeber/httpyac",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as models from '../../models';
import * as models from '../../../models';
import { HookTriggerContext } from 'hookpoint';

export const bailOnFailedTestInterceptor = {
Expand Down
14 changes: 14 additions & 0 deletions src/cli/send/plugin/cliHttpyacPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { HttpyacHooksApi } from '../../../models';
import { bailOnFailedTestInterceptor } from './bailOnFailedTestInterceptor';
import { loggerFlushInterceptor } from './loggerFlushInterceptor';
import { testExitCodeInterceptor } from './testExitCodeInterceptor';

export function createCliPluginRegister(bail: boolean) {
return function registerCliPlugin(api: HttpyacHooksApi) {
api.hooks.execute.addInterceptor(loggerFlushInterceptor);
api.hooks.execute.addInterceptor(testExitCodeInterceptor);
if (bail) {
api.hooks.execute.addInterceptor(bailOnFailedTestInterceptor);
}
};
}
4 changes: 4 additions & 0 deletions src/cli/send/plugin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './bailOnFailedTestInterceptor';
export * from './cliHttpyacPlugin';
export * from './loggerFlushInterceptor';
export * from './testExitCodeInterceptor';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as models from '../../models';
import * as models from '../../../models';
import { HookTriggerContext } from 'hookpoint';

export const loggerFlushInterceptor = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as models from '../../models';
import * as models from '../../../models';
import { HookTriggerContext } from 'hookpoint';

export const testExitCodeInterceptor = {
id: 'bailOnFailed',
id: 'testExitCode',
afterTrigger: async function bail(hookContext: HookTriggerContext<[models.ProcessorContext], boolean>) {
const context = hookContext.args[0];
const failedTest = context.httpRegion.testResults?.find?.(obj => !obj.result);
Expand Down
19 changes: 4 additions & 15 deletions src/cli/send/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { fileProvider, Logger } from '../../io';
import * as models from '../../models';
import { HttpFileStore } from '../../store';
import * as utils from '../../utils';
import { bailOnFailedTestInterceptor } from './bailOnFailedTestInterceptor';
import { createCliPluginRegister } from './plugin';
import { toSendJsonOutput } from './jsonOutput';
import { loggerFlushInterceptor } from './loggerFlushInterceptor';
import { SendOptions, getLogLevel, SendFilterOptions, OutputType } from './options';
import { testExitCodeInterceptor } from './testExitCodeInterceptor';
import { default as chalk } from 'chalk';
import { Command } from 'commander';
import { promises as fs } from 'fs';
Expand Down Expand Up @@ -54,7 +52,6 @@ async function execute(fileNames: Array<string>, options: SendOptions): Promise<
initRequestLogger(options, context);
try {
if (httpFiles.length > 0) {
initCliHooks(httpFiles, options);
let isFirstRequest = true;
const jsonOutput: Record<string, Array<models.ProcessedHttpRegion>> = {};
while (options.interactive || isFirstRequest) {
Expand Down Expand Up @@ -160,19 +157,11 @@ export function initRequestLogger(cliOptions: SendOptions, context: Omit<models.
}
}

function initCliHooks(httpFiles: Array<models.HttpFile>, cliOptions: SendOptions) {
for (const httpFile of utils.distinct(httpFiles)) {
httpFile.hooks.execute.addInterceptor(loggerFlushInterceptor);
httpFile.hooks.execute.addInterceptor(testExitCodeInterceptor);
if (cliOptions.bail) {
httpFile.hooks.execute.addInterceptor(bailOnFailedTestInterceptor);
}
}
}

async function getHttpFiles(fileNames: Array<string>, options: SendOptions, config: models.EnvironmentConfig) {
const httpFiles: models.HttpFile[] = [];
const httpFileStore = new HttpFileStore();
const httpFileStore = new HttpFileStore({
cli: createCliPluginRegister(!!options.bail),
});

const parseOptions: models.HttpFileStoreOptions = {
workingDir: process.cwd(),
Expand Down

0 comments on commit e4f867a

Please sign in to comment.