mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-23 05:01:43 +01:00
feat: bru.setNextRequest()
This commit is contained in:
parent
a9459bc236
commit
d4c0207545
@ -357,7 +357,9 @@ const handler = async function (argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const iter of bruJsons) {
|
let currentRequestIndex = 0;
|
||||||
|
while (currentRequestIndex < bruJsons.length) {
|
||||||
|
const iter = bruJsons[currentRequestIndex];
|
||||||
const { bruFilepath, bruJson } = iter;
|
const { bruFilepath, bruJson } = iter;
|
||||||
const result = await runSingleRequest(
|
const result = await runSingleRequest(
|
||||||
bruFilepath,
|
bruFilepath,
|
||||||
@ -370,6 +372,19 @@ const handler = async function (argv) {
|
|||||||
collectionRoot
|
collectionRoot
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const nextRequestName = result?.nextRequestName;
|
||||||
|
if (nextRequestName) {
|
||||||
|
const nextRequestIdx = bruJsons.findIndex((iter) => iter.bruJson.name === nextRequestName);
|
||||||
|
if (nextRequestIdx > 0) {
|
||||||
|
currentRequestIndex = nextRequestIdx;
|
||||||
|
} else {
|
||||||
|
console.error("Could not find request with name '" + nextRequestName + "'");
|
||||||
|
currentRequestIndex++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentRequestIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
results.push(result);
|
results.push(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ const runSingleRequest = async function (
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
let request;
|
let request;
|
||||||
|
let nextRequestName;
|
||||||
|
|
||||||
request = prepareRequest(bruJson.request, collectionRoot);
|
request = prepareRequest(bruJson.request, collectionRoot);
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ const runSingleRequest = async function (
|
|||||||
]).join(os.EOL);
|
]).join(os.EOL);
|
||||||
if (requestScriptFile && requestScriptFile.length) {
|
if (requestScriptFile && requestScriptFile.length) {
|
||||||
const scriptRuntime = new ScriptRuntime();
|
const scriptRuntime = new ScriptRuntime();
|
||||||
await scriptRuntime.runRequestScript(
|
const result = await scriptRuntime.runRequestScript(
|
||||||
decomment(requestScriptFile),
|
decomment(requestScriptFile),
|
||||||
request,
|
request,
|
||||||
envVariables,
|
envVariables,
|
||||||
@ -76,6 +77,9 @@ const runSingleRequest = async function (
|
|||||||
processEnvVars,
|
processEnvVars,
|
||||||
scriptingConfig
|
scriptingConfig
|
||||||
);
|
);
|
||||||
|
if (result?.nextRequestName) {
|
||||||
|
nextRequestName = result.nextRequestName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolate variables inside request
|
// interpolate variables inside request
|
||||||
@ -187,7 +191,8 @@ const runSingleRequest = async function (
|
|||||||
},
|
},
|
||||||
error: err.message,
|
error: err.message,
|
||||||
assertionResults: [],
|
assertionResults: [],
|
||||||
testResults: []
|
testResults: [],
|
||||||
|
nextRequestName: nextRequestName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,7 +224,7 @@ const runSingleRequest = async function (
|
|||||||
]).join(os.EOL);
|
]).join(os.EOL);
|
||||||
if (responseScriptFile && responseScriptFile.length) {
|
if (responseScriptFile && responseScriptFile.length) {
|
||||||
const scriptRuntime = new ScriptRuntime();
|
const scriptRuntime = new ScriptRuntime();
|
||||||
await scriptRuntime.runResponseScript(
|
const result = await scriptRuntime.runResponseScript(
|
||||||
decomment(responseScriptFile),
|
decomment(responseScriptFile),
|
||||||
request,
|
request,
|
||||||
response,
|
response,
|
||||||
@ -230,6 +235,9 @@ const runSingleRequest = async function (
|
|||||||
processEnvVars,
|
processEnvVars,
|
||||||
scriptingConfig
|
scriptingConfig
|
||||||
);
|
);
|
||||||
|
if (result?.nextRequestName) {
|
||||||
|
nextRequestName = result.nextRequestName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run assertions
|
// run assertions
|
||||||
@ -301,7 +309,8 @@ const runSingleRequest = async function (
|
|||||||
},
|
},
|
||||||
error: null,
|
error: null,
|
||||||
assertionResults,
|
assertionResults,
|
||||||
testResults
|
testResults,
|
||||||
|
nextRequestName: nextRequestName
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(chalk.red(stripExtension(filename)) + chalk.dim(` (${err.message})`));
|
console.log(chalk.red(stripExtension(filename)) + chalk.dim(` (${err.message})`));
|
||||||
|
@ -605,7 +605,10 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let item of folderRequests) {
|
let currentRequestIndex = 0;
|
||||||
|
while (currentRequestIndex < folderRequests.length) {
|
||||||
|
item = folderRequests[currentRequestIndex];
|
||||||
|
let nextRequestName = undefined;
|
||||||
const itemUid = item.uid;
|
const itemUid = item.uid;
|
||||||
const eventData = {
|
const eventData = {
|
||||||
collectionUid,
|
collectionUid,
|
||||||
@ -685,6 +688,10 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables: result.collectionVariables,
|
collectionVariables: result.collectionVariables,
|
||||||
collectionUid
|
collectionUid
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (result?.nextRequestName) {
|
||||||
|
nextRequestName = result.nextRequestName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// interpolate variables inside request
|
// interpolate variables inside request
|
||||||
@ -807,6 +814,10 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
collectionVariables: result.collectionVariables,
|
collectionVariables: result.collectionVariables,
|
||||||
collectionUid
|
collectionUid
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (result?.nextRequestName) {
|
||||||
|
nextRequestName = result.nextRequestName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// run assertions
|
// run assertions
|
||||||
@ -963,6 +974,17 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
...eventData
|
...eventData
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (nextRequestName) {
|
||||||
|
const nextRequestIdx = folderRequests.findIndex((request) => request.name === nextRequestName);
|
||||||
|
if (nextRequestIdx > 0) {
|
||||||
|
currentRequestIndex = nextRequestIdx;
|
||||||
|
} else {
|
||||||
|
console.error("Could not find request with name '" + nextRequestName + "'");
|
||||||
|
currentRequestIndex++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
currentRequestIndex++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.webContents.send('main:run-folder-event', {
|
mainWindow.webContents.send('main:run-folder-event', {
|
||||||
|
@ -65,6 +65,10 @@ class Bru {
|
|||||||
getVar(key) {
|
getVar(key) {
|
||||||
return this.collectionVariables[key];
|
return this.collectionVariables[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setNextRequest(nextRequest) {
|
||||||
|
this.nextRequest = nextRequest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Bru;
|
module.exports = Bru;
|
||||||
|
@ -116,7 +116,8 @@ class ScriptRuntime {
|
|||||||
return {
|
return {
|
||||||
request,
|
request,
|
||||||
envVariables: cleanJson(envVariables),
|
envVariables: cleanJson(envVariables),
|
||||||
collectionVariables: cleanJson(collectionVariables)
|
collectionVariables: cleanJson(collectionVariables),
|
||||||
|
nextRequestName: bru.nextRequest
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +208,8 @@ class ScriptRuntime {
|
|||||||
return {
|
return {
|
||||||
response,
|
response,
|
||||||
envVariables: cleanJson(envVariables),
|
envVariables: cleanJson(envVariables),
|
||||||
collectionVariables: cleanJson(collectionVariables)
|
collectionVariables: cleanJson(collectionVariables),
|
||||||
|
nextRequestName: bru.nextRequest
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user