When running via CLI, preserve changes to collection variables and

environment variables.

Closes #1255
This commit is contained in:
Scott LaPlante 2024-03-02 21:55:55 -05:00
parent 9320b8faf0
commit 7c94c9ec19
2 changed files with 10 additions and 5 deletions

View File

@ -422,6 +422,7 @@ const handler = async function (argv) {
brunoConfig, brunoConfig,
collectionRoot collectionRoot
); );
({ collectionVariables, envVariables } = result);
results.push({ results.push({
...result, ...result,

View File

@ -57,14 +57,14 @@ const runSingleRequest = async function (
const preRequestVars = get(bruJson, 'request.vars.req'); const preRequestVars = get(bruJson, 'request.vars.req');
if (preRequestVars?.length) { if (preRequestVars?.length) {
const varsRuntime = new VarsRuntime(); const varsRuntime = new VarsRuntime();
varsRuntime.runPreRequestVars( ({ collectionVariables } = varsRuntime.runPreRequestVars(
preRequestVars, preRequestVars,
request, request,
envVariables, envVariables,
collectionVariables, collectionVariables,
collectionPath, collectionPath,
processEnvVars processEnvVars
); ));
} }
// run pre request script // run pre request script
@ -87,6 +87,7 @@ const runSingleRequest = async function (
if (result?.nextRequestName !== undefined) { if (result?.nextRequestName !== undefined) {
nextRequestName = result.nextRequestName; nextRequestName = result.nextRequestName;
} }
({ collectionVariables, envVariables } = result);
} }
// interpolate variables inside request // interpolate variables inside request
@ -248,7 +249,7 @@ const runSingleRequest = async function (
const postResponseVars = get(bruJson, 'request.vars.res'); const postResponseVars = get(bruJson, 'request.vars.res');
if (postResponseVars?.length) { if (postResponseVars?.length) {
const varsRuntime = new VarsRuntime(); const varsRuntime = new VarsRuntime();
varsRuntime.runPostResponseVars( ({ collectionVariables, envVariables } = varsRuntime.runPostResponseVars(
postResponseVars, postResponseVars,
request, request,
response, response,
@ -256,7 +257,7 @@ const runSingleRequest = async function (
collectionVariables, collectionVariables,
collectionPath, collectionPath,
processEnvVars processEnvVars
); ));
} }
// run post response script // run post response script
@ -322,6 +323,7 @@ const runSingleRequest = async function (
processEnvVars, processEnvVars,
scriptingConfig scriptingConfig
); );
({ collectionVariables, envVariables } = result);
testResults = get(result, 'results', []); testResults = get(result, 'results', []);
} }
@ -355,7 +357,9 @@ const runSingleRequest = async function (
error: null, error: null,
assertionResults, assertionResults,
testResults, testResults,
nextRequestName: nextRequestName nextRequestName: nextRequestName,
collectionVariables,
envVariables
}; };
} catch (err) { } catch (err) {
console.log(chalk.red(stripExtension(filename)) + chalk.dim(` (${err.message})`)); console.log(chalk.red(stripExtension(filename)) + chalk.dim(` (${err.message})`));