mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-08 23:18:54 +01:00
feat: bruno cli can sort the requests being run
This commit is contained in:
parent
d0f2eb27bc
commit
03fa46d8b3
@ -5,6 +5,7 @@ const { exists, isFile, isDirectory } = require('../utils/filesystem');
|
||||
const { runSingleRequest } = require('../runner/run-single-request');
|
||||
const { bruToEnvJson, getEnvVars } = require('../utils/bru');
|
||||
const { rpad } = require('../utils/common');
|
||||
const { bruToJson } = require('../utils/bru');
|
||||
|
||||
const command = 'run <filename>';
|
||||
const desc = 'Run a request';
|
||||
@ -83,10 +84,12 @@ const handler = async function (argv) {
|
||||
const _isFile = await isFile(filename);
|
||||
if(_isFile) {
|
||||
console.log(chalk.yellow('Running Request \n'));
|
||||
const bruContent = fs.readFileSync(filename, 'utf8');
|
||||
const bruJson = bruToJson(bruContent);
|
||||
const {
|
||||
assertionResults,
|
||||
testResults
|
||||
} = await runSingleRequest(filename, collectionPath, collectionVariables, envVars);
|
||||
} = await runSingleRequest(filename, bruJson, collectionPath, collectionVariables, envVars);
|
||||
|
||||
printRunSummary(assertionResults, testResults);
|
||||
console.log(chalk.dim(chalk.grey('Done.')));
|
||||
@ -98,15 +101,36 @@ const handler = async function (argv) {
|
||||
|
||||
const files = fs.readdirSync(filename);
|
||||
const bruFiles = files.filter((file) => file.endsWith('.bru'));
|
||||
const bruJsons = [];
|
||||
for (const bruFile of bruFiles) {
|
||||
const bruFilepath = path.join(filename, bruFile)
|
||||
const bruContent = fs.readFileSync(bruFilepath, 'utf8');
|
||||
const bruJson = bruToJson(bruContent);
|
||||
bruJsons.push({
|
||||
bruFilepath,
|
||||
bruJson
|
||||
});
|
||||
}
|
||||
|
||||
// order requests by sequence
|
||||
bruJsons.sort((a, b) => {
|
||||
const aSequence = a.bruJson.seq || 0;
|
||||
const bSequence = b.bruJson.seq || 0;
|
||||
return aSequence - bSequence;
|
||||
});
|
||||
|
||||
let assertionResults = [];
|
||||
let testResults = [];
|
||||
|
||||
for (const bruFile of bruFiles) {
|
||||
for (const iter of bruJsons) {
|
||||
const {
|
||||
bruFilepath,
|
||||
bruJson
|
||||
} = iter;
|
||||
const {
|
||||
assertionResults: _assertionResults,
|
||||
testResults: _testResults
|
||||
} = await runSingleRequest(path.join(filename, bruFile), collectionPath, collectionVariables, envVars);
|
||||
} = await runSingleRequest(bruFilepath, bruJson, collectionPath, collectionVariables, envVars);
|
||||
|
||||
assertionResults = assertionResults.concat(_assertionResults);
|
||||
testResults = testResults.concat(_testResults);
|
||||
|
@ -1,4 +1,3 @@
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const { forOwn, each, extend, get } = require('lodash');
|
||||
const FormData = require('form-data');
|
||||
@ -6,14 +5,10 @@ const axios = require('axios');
|
||||
const prepareRequest = require('./prepare-request');
|
||||
const interpolateVars = require('./interpolate-vars');
|
||||
const { ScriptRuntime, TestRuntime, VarsRuntime, AssertRuntime } = require('@usebruno/js');
|
||||
const { bruToJson } = require('../utils/bru');
|
||||
const { stripExtension } = require('../utils/filesystem');
|
||||
|
||||
const runSingleRequest = async function (filename, collectionPath, collectionVariables, envVariables) {
|
||||
const runSingleRequest = async function (filename, bruJson, collectionPath, collectionVariables, envVariables) {
|
||||
try {
|
||||
const bruContent = fs.readFileSync(filename, 'utf8');
|
||||
|
||||
const bruJson = bruToJson(bruContent);
|
||||
const request = prepareRequest(bruJson.request);
|
||||
|
||||
// make axios work in node using form data
|
||||
|
Loading…
Reference in New Issue
Block a user