diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3447f5..26e00fff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 60ee3e5a..71bc52cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "httpyac", - "version": "6.6.4", + "version": "6.6.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "httpyac", - "version": "6.6.4", + "version": "6.6.5", "license": "MIT", "dependencies": { "@cloudamqp/amqp-client": "^2.1.1", diff --git a/package.json b/package.json index 6a46364f..7de88e6d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli/send/bailOnFailedTestInterceptor.ts b/src/cli/send/plugin/bailOnFailedTestInterceptor.ts similarity index 91% rename from src/cli/send/bailOnFailedTestInterceptor.ts rename to src/cli/send/plugin/bailOnFailedTestInterceptor.ts index c70b45a8..bbc6aa2c 100644 --- a/src/cli/send/bailOnFailedTestInterceptor.ts +++ b/src/cli/send/plugin/bailOnFailedTestInterceptor.ts @@ -1,4 +1,4 @@ -import * as models from '../../models'; +import * as models from '../../../models'; import { HookTriggerContext } from 'hookpoint'; export const bailOnFailedTestInterceptor = { diff --git a/src/cli/send/plugin/cliHttpyacPlugin.ts b/src/cli/send/plugin/cliHttpyacPlugin.ts new file mode 100644 index 00000000..094ea96d --- /dev/null +++ b/src/cli/send/plugin/cliHttpyacPlugin.ts @@ -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); + } + }; +} diff --git a/src/cli/send/plugin/index.ts b/src/cli/send/plugin/index.ts new file mode 100644 index 00000000..593f1310 --- /dev/null +++ b/src/cli/send/plugin/index.ts @@ -0,0 +1,4 @@ +export * from './bailOnFailedTestInterceptor'; +export * from './cliHttpyacPlugin'; +export * from './loggerFlushInterceptor'; +export * from './testExitCodeInterceptor'; diff --git a/src/cli/send/loggerFlushInterceptor.ts b/src/cli/send/plugin/loggerFlushInterceptor.ts similarity index 88% rename from src/cli/send/loggerFlushInterceptor.ts rename to src/cli/send/plugin/loggerFlushInterceptor.ts index 5dd51f59..a6c5b913 100644 --- a/src/cli/send/loggerFlushInterceptor.ts +++ b/src/cli/send/plugin/loggerFlushInterceptor.ts @@ -1,4 +1,4 @@ -import * as models from '../../models'; +import * as models from '../../../models'; import { HookTriggerContext } from 'hookpoint'; export const loggerFlushInterceptor = { diff --git a/src/cli/send/testExitCodeInterceptor.ts b/src/cli/send/plugin/testExitCodeInterceptor.ts similarity index 86% rename from src/cli/send/testExitCodeInterceptor.ts rename to src/cli/send/plugin/testExitCodeInterceptor.ts index 4f4294b7..5a8e24d5 100644 --- a/src/cli/send/testExitCodeInterceptor.ts +++ b/src/cli/send/plugin/testExitCodeInterceptor.ts @@ -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); diff --git a/src/cli/send/send.ts b/src/cli/send/send.ts index 46e65461..b7cba879 100644 --- a/src/cli/send/send.ts +++ b/src/cli/send/send.ts @@ -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'; @@ -54,7 +52,6 @@ async function execute(fileNames: Array, options: SendOptions): Promise< initRequestLogger(options, context); try { if (httpFiles.length > 0) { - initCliHooks(httpFiles, options); let isFirstRequest = true; const jsonOutput: Record> = {}; while (options.interactive || isFirstRequest) { @@ -160,19 +157,11 @@ export function initRequestLogger(cliOptions: SendOptions, context: Omit, 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, 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(),