mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 14:08:38 +00:00
Filter requests by tags in bruno-cli
A request is only included in the test run if its tags include at least one of the include tags and none of the exclude tags specified in the CLI options.
This commit is contained in:
@@ -6,6 +6,7 @@ const { getRunnerSummary } = require('@usebruno/common/runner');
|
||||
const { exists, isFile, isDirectory } = require('../utils/filesystem');
|
||||
const { runSingleRequest } = require('../runner/run-single-request');
|
||||
const { bruToEnvJson, getEnvVars } = require('../utils/bru');
|
||||
const { isRequestTagsIncluded } = require("@usebruno/common")
|
||||
const makeJUnitOutput = require('../reporters/junit');
|
||||
const makeHtmlOutput = require('../reporters/html');
|
||||
const { rpad } = require('../utils/common');
|
||||
@@ -199,6 +200,14 @@ const builder = async (yargs) => {
|
||||
type:"number",
|
||||
description: "Delay between each requests (in miliseconds)"
|
||||
})
|
||||
.option('tags', {
|
||||
type: 'string',
|
||||
description: 'Tags to include in the run'
|
||||
})
|
||||
.option('exclude-tags', {
|
||||
type: 'string',
|
||||
description: 'Tags to exclude from the run'
|
||||
})
|
||||
.example('$0 run request.bru', 'Run a request')
|
||||
.example('$0 run request.bru --env local', 'Run a request with the environment set to local')
|
||||
.example('$0 run request.bru --env-file env.bru', 'Run a request with the environment from env.bru file')
|
||||
@@ -268,7 +277,9 @@ const handler = async function (argv) {
|
||||
reporterSkipHeaders,
|
||||
clientCertConfig,
|
||||
noproxy,
|
||||
delay
|
||||
delay,
|
||||
tags: includeTags,
|
||||
excludeTags
|
||||
} = argv;
|
||||
const collectionPath = process.cwd();
|
||||
|
||||
@@ -353,7 +364,7 @@ const handler = async function (argv) {
|
||||
if (!match) {
|
||||
console.error(
|
||||
chalk.red(`Overridable environment variable not correct: use name=value - presented: `) +
|
||||
chalk.dim(`${value}`)
|
||||
chalk.dim(`${value}`)
|
||||
);
|
||||
process.exit(constants.EXIT_STATUS.ERROR_INCORRECT_ENV_OVERRIDE);
|
||||
}
|
||||
@@ -389,6 +400,9 @@ const handler = async function (argv) {
|
||||
}
|
||||
options['ignoreTruststore'] = ignoreTruststore;
|
||||
|
||||
includeTags = includeTags ? includeTags.split(',') : [];
|
||||
excludeTags = excludeTags ? excludeTags.split(',') : [];
|
||||
|
||||
if (['json', 'junit', 'html'].indexOf(format) === -1) {
|
||||
console.error(chalk.red(`Format must be one of "json", "junit or "html"`));
|
||||
process.exit(constants.EXIT_STATUS.ERROR_INCORRECT_OUTPUT_FORMAT);
|
||||
@@ -444,6 +458,10 @@ const handler = async function (argv) {
|
||||
console.error(chalk.red(`Path not found: ${resolvedPath}`));
|
||||
process.exit(constants.EXIT_STATUS.ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
|
||||
requestItems = requestItems.filter((item) => {
|
||||
return isRequestTagsIncluded(item.tags, includeTags, excludeTags);
|
||||
});
|
||||
}
|
||||
|
||||
requestItems = getCallStack(resolvedPaths, collection, { recursive });
|
||||
|
||||
@@ -60,6 +60,7 @@ const bruToJson = (bru) => {
|
||||
type: requestType,
|
||||
name: _.get(json, 'meta.name'),
|
||||
seq: !isNaN(sequence) ? Number(sequence) : 1,
|
||||
tags: _.get(json, 'tags', []),
|
||||
request: {
|
||||
method: _.upperCase(_.get(json, 'http.method')),
|
||||
url: _.get(json, 'http.url'),
|
||||
|
||||
Reference in New Issue
Block a user