chore: code cleanup + cli updates

This commit is contained in:
Anoop M D
2024-08-19 11:36:24 +05:30
parent 1bf3a15784
commit d187a8efab
9 changed files with 413 additions and 2936 deletions

View File

@@ -190,6 +190,10 @@ const getFolderRoot = (dir) => {
return collectionBruToJson(content);
};
const getJsSandboxRuntime = (sandbox) => {
return sandbox === 'safe' ? 'quickjs' : 'vm2';
};
const builder = async (yargs) => {
yargs
.option('r', {
@@ -215,6 +219,11 @@ const builder = async (yargs) => {
describe: 'Overwrite a single environment variable, multiple usages possible',
type: 'string'
})
.option('sandbox', {
describe: 'Javscript sandbox to use; available sandboxes are "developer" (default) or "safe"',
default: 'developer',
type: 'string'
})
.option('output', {
alias: 'o',
describe: 'Path to write file results to',
@@ -282,6 +291,7 @@ const handler = async function (argv) {
r: recursive,
output: outputPath,
format,
sandbox,
testsOnly,
bail
} = argv;
@@ -451,6 +461,7 @@ const handler = async function (argv) {
}
}
const runtime = getJsSandboxRuntime(sandbox);
let currentRequestIndex = 0;
let nJumps = 0; // count the number of jumps to avoid infinite loops
while (currentRequestIndex < bruJsons.length) {
@@ -466,7 +477,8 @@ const handler = async function (argv) {
envVars,
processEnvVars,
brunoConfig,
collectionRoot
collectionRoot,
runtime
);
results.push({

View File

@@ -29,7 +29,8 @@ const runSingleRequest = async function (
envVariables,
processEnvVars,
brunoConfig,
collectionRoot
collectionRoot,
runtime
) {
try {
let request;
@@ -38,11 +39,7 @@ const runSingleRequest = async function (
request = prepareRequest(bruJson.request, collectionRoot);
const scriptingConfig = get(brunoConfig, 'scripts', {});
// todo: allow to override from cli args
// we will default to vm2 (developer-mode) for 1.x version for backward compatibility
// 2.x will default to isolated-vm (safe mode)
scriptingConfig.runtime = 'quickjs';
scriptingConfig.runtime = runtime;
// make axios work in node using form data
// reference: https://github.com/axios/axios/issues/1006#issuecomment-320165427