fix: fixing issues in bru cli

This commit is contained in:
Anoop M D 2023-02-07 02:58:44 +05:30
parent 89b721d726
commit 580d681e0a
2 changed files with 12 additions and 12 deletions

View File

@ -32,7 +32,9 @@ const handler = async function (argv) {
const _isFile = await isFile(filename); const _isFile = await isFile(filename);
if(_isFile) { if(_isFile) {
runSingleRequest(filename, collectionPath, collectionVariables); console.log(chalk.yellow('Running Request \n'));
await runSingleRequest(filename, collectionPath, collectionVariables);
console.log(chalk.green('\nDone!'));
} }
} catch (err) { } catch (err) {
console.error(err); console.error(err);

View File

@ -55,19 +55,18 @@ const runSingleRequest = async function (filename, collectionPath, collectionVar
const envVars = getEnvVars({}); const envVars = getEnvVars({});
if(request.script && request.script.length) { const requestScriptFile = get(bruJson, 'request.script.req');
let script = request.script + '\n if (typeof onRequest === "function") {onRequest(__brunoRequest);}'; if(requestScriptFile && requestScriptFile.length) {
const scriptRuntime = new ScriptRuntime(); const scriptRuntime = new ScriptRuntime();
const result = scriptRuntime.runRequestScript(script, request, envVars, collectionVariables, collectionPath); const result = scriptRuntime.runRequestScript(requestScriptFile, request, envVars, collectionVariables, collectionPath);
} }
const response = await axios(request); const response = await axios(request);
const scriptFile = get(bruJson, 'request.script'); const responseScriptFile = get(bruJson, 'request.script.req');
if(scriptFile && scriptFile.length) { if(responseScriptFile && responseScriptFile.length) {
let script = scriptFile + '\n if (typeof onResponse === "function") {onResponse(__brunoResponse);}';
const scriptRuntime = new ScriptRuntime(); const scriptRuntime = new ScriptRuntime();
const result = scriptRuntime.runResponseScript(script, response, envVars, collectionVariables, collectionPath); const result = scriptRuntime.runResponseScript(responseScriptFile, response, envVars, collectionVariables, collectionPath);
} }
let testResults = []; let testResults = [];
@ -78,19 +77,18 @@ const runSingleRequest = async function (filename, collectionPath, collectionVar
testResults = get(result, 'results', []); testResults = get(result, 'results', []);
} }
console.log(JSON.stringify(bruJson, null, 2));
console.log(chalk.green(stripExtension(filename)) + chalk.dim(` (${response.status} ${response.statusText})`)); console.log(chalk.green(stripExtension(filename)) + chalk.dim(` (${response.status} ${response.statusText})`));
if(testResults && testResults.length) { if(testResults && testResults.length) {
each(testResults, (testResult) => { each(testResults, (testResult) => {
if(testResult.status === 'pass') { if(testResult.status === 'pass') {
console.log(chalk.green(` ✔️ `) + chalk.dim(testResult.description)); console.log(chalk.green(` `) + chalk.dim(testResult.description));
} else { } else {
console.log(chalk.red(` `) + chalk.red(testResult.description)); console.log(chalk.red(` `) + chalk.red(testResult.description));
} }
}); });
} }
} catch (err) { } catch (err) {
console.log(err.response);
Promise.reject(err); Promise.reject(err);
} }
}; };