mirror of
https://github.com/usebruno/bruno.git
synced 2025-01-09 23:48:13 +01:00
fix: fixing issues in bru cli
This commit is contained in:
parent
89b721d726
commit
580d681e0a
@ -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);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user