mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-22 14:41:04 +01:00
feat: Add flow
option for "natural" flow in scripts (#2704)
- Adds a new key in the `bruno.json` under `scripts.flow` - When concating post and tests scripts the flow will now be used to determine to correct order Fixes: #2648 #2680 #2597 #2639
This commit is contained in:
parent
1d2e06d419
commit
2e2c60d90e
@ -408,10 +408,13 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
}
|
||||
|
||||
// run post-response script
|
||||
const responseScript = compact(scriptingConfig.flow === 'natural' ? [
|
||||
get(collectionRoot, 'request.script.res'), get(request, 'script.res')
|
||||
] : [
|
||||
get(request, 'script.res'), get(collectionRoot, 'request.script.res')
|
||||
]).join(os.EOL);
|
||||
|
||||
let scriptResult;
|
||||
const responseScript = compact([get(request, 'script.res'), get(collectionRoot, 'request.script.res')]).join(
|
||||
os.EOL
|
||||
);
|
||||
if (responseScript?.length) {
|
||||
const scriptRuntime = new ScriptRuntime();
|
||||
scriptResult = await scriptRuntime.runResponseScript(
|
||||
@ -592,10 +595,13 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
}
|
||||
|
||||
// run tests
|
||||
const testFile = compact([
|
||||
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'),
|
||||
get(collectionRoot, 'request.tests')
|
||||
const testScript = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||
const testFile = compact(scriptingConfig.flow === 'natural' ? [
|
||||
get(collectionRoot, 'request.tests'), testScript,
|
||||
] : [
|
||||
testScript, get(collectionRoot, 'request.tests')
|
||||
]).join(os.EOL);
|
||||
|
||||
if (typeof testFile === 'string') {
|
||||
const testRuntime = new TestRuntime();
|
||||
const testResults = await testRuntime.runTests(
|
||||
@ -1029,10 +1035,13 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
}
|
||||
|
||||
// run tests
|
||||
const testFile = compact([
|
||||
item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests'),
|
||||
get(collectionRoot, 'request.tests')
|
||||
const testScript = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||
const testFile = compact(scriptingConfig.flow === 'natural' ? [
|
||||
get(collectionRoot, 'request.tests'), testScript
|
||||
] : [
|
||||
testScript, get(collectionRoot, 'request.tests')
|
||||
]).join(os.EOL);
|
||||
|
||||
if (typeof testFile === 'string') {
|
||||
const testRuntime = new TestRuntime();
|
||||
const testResults = await testRuntime.runTests(
|
||||
|
@ -119,7 +119,7 @@ const mergeFolderLevelVars = (request, requestTreePath) => {
|
||||
}));
|
||||
};
|
||||
|
||||
const mergeFolderLevelScripts = (request, requestTreePath) => {
|
||||
const mergeFolderLevelScripts = (request, requestTreePath, scriptFlow) => {
|
||||
let folderCombinedPreReqScript = [];
|
||||
let folderCombinedPostResScript = [];
|
||||
let folderCombinedTests = [];
|
||||
@ -147,11 +147,19 @@ const mergeFolderLevelScripts = (request, requestTreePath) => {
|
||||
}
|
||||
|
||||
if (folderCombinedPostResScript.length) {
|
||||
request.script.res = compact([request?.script?.res || '', ...folderCombinedPostResScript.reverse()]).join(os.EOL);
|
||||
if (scriptFlow === 'natural') {
|
||||
request.script.res = compact([...folderCombinedPostResScript, request?.script?.res || '']).join(os.EOL);
|
||||
} else {
|
||||
request.script.res = compact([request?.script?.res || '', ...folderCombinedPostResScript.reverse()]).join(os.EOL);
|
||||
}
|
||||
}
|
||||
|
||||
if (folderCombinedTests.length) {
|
||||
request.tests = compact([request?.tests || '', ...folderCombinedTests.reverse()]).join(os.EOL);
|
||||
if (scriptFlow === 'natural') {
|
||||
request.tests = compact([...folderCombinedTests, request?.tests || '']).join(os.EOL);
|
||||
} else {
|
||||
request.tests = compact([request?.tests || '', ...folderCombinedTests.reverse()]).join(os.EOL);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -301,10 +309,12 @@ const prepareRequest = (item, collection) => {
|
||||
}
|
||||
});
|
||||
|
||||
// scriptFlow is either "sandwich" or "natural"
|
||||
const scriptFlow = collection.brunoConfig?.scripts?.flow ?? 'sandwich';
|
||||
const requestTreePath = getTreePathFromCollectionToItem(collection, item);
|
||||
if (requestTreePath && requestTreePath.length > 0) {
|
||||
mergeFolderLevelHeaders(request, requestTreePath);
|
||||
mergeFolderLevelScripts(request, requestTreePath);
|
||||
mergeFolderLevelScripts(request, requestTreePath, scriptFlow);
|
||||
mergeFolderLevelVars(request, requestTreePath);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user