mirror of
https://github.com/usebruno/bruno.git
synced 2025-03-13 14:29:04 +01:00
fix: cli - collection level script, added tests
This commit is contained in:
parent
67ead9739e
commit
3fe0d43bdc
@ -143,24 +143,18 @@ const mergeScripts = (collection, request, requestTreePath, scriptFlow) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (combinedPreReqScript.length) {
|
||||
request.script.req = compact([collectionPreReqScript, ...combinedPreReqScript, request?.script?.req || '']).join(os.EOL);
|
||||
request.script.req = compact([collectionPreReqScript, ...combinedPreReqScript, request?.script?.req || '']).join(os.EOL);
|
||||
|
||||
if (scriptFlow === 'sequential') {
|
||||
request.script.res = compact([collectionPostResScript, ...combinedPostResScript, request?.script?.res || '']).join(os.EOL);
|
||||
} else {
|
||||
request.script.res = compact([request?.script?.res || '', ...combinedPostResScript.reverse(), collectionPostResScript]).join(os.EOL);
|
||||
}
|
||||
|
||||
if (combinedPostResScript.length) {
|
||||
if (scriptFlow === 'sequential') {
|
||||
request.script.res = compact([collectionPostResScript, ...combinedPostResScript, request?.script?.res || '']).join(os.EOL);
|
||||
} else {
|
||||
request.script.res = compact([request?.script?.res || '', ...combinedPostResScript.reverse(), collectionPostResScript]).join(os.EOL);
|
||||
}
|
||||
}
|
||||
|
||||
if (combinedTests.length) {
|
||||
if (scriptFlow === 'sequential') {
|
||||
request.tests = compact([collectionTests, ...combinedTests, request?.tests || '']).join(os.EOL);
|
||||
} else {
|
||||
request.tests = compact([request?.tests || '', ...combinedTests.reverse(), collectionTests]).join(os.EOL);
|
||||
}
|
||||
if (scriptFlow === 'sequential') {
|
||||
request.tests = compact([collectionTests, ...combinedTests, request?.tests || '']).join(os.EOL);
|
||||
} else {
|
||||
request.tests = compact([request?.tests || '', ...combinedTests.reverse(), collectionTests]).join(os.EOL);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
headers {
|
||||
check: again
|
||||
token: {{collection_pre_var_token}}
|
||||
collection-header: collection-header-value
|
||||
}
|
||||
|
||||
auth {
|
||||
@ -17,6 +18,27 @@ vars:pre-request {
|
||||
collection-var: collection-var-value
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
// used by `scripting/js/folder-collection script-tests`
|
||||
const shouldTestCollectionScripts = bru.getVar('should-test-collection-scripts');
|
||||
if(shouldTestCollectionScripts) {
|
||||
bru.setVar('collection-var-set-by-collection-script', 'collection-var-value-set-by-collection-script');
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
// used by `scripting/js/folder-collection script-tests`
|
||||
const shouldTestCollectionScripts = bru.getVar('should-test-collection-scripts');
|
||||
const collectionVar = bru.getVar("collection-var-set-by-collection-script");
|
||||
if (shouldTestCollectionScripts && collectionVar) {
|
||||
test("collection level test - should get the var that was set by the collection script", function() {
|
||||
expect(collectionVar).to.equal("collection-var-value-set-by-collection-script");
|
||||
});
|
||||
bru.setVar('collection-var-set-by-collection-script', null);
|
||||
bru.setVar('should-test-collection-scripts', null);
|
||||
}
|
||||
}
|
||||
|
||||
docs {
|
||||
# bruno-testbench 🐶
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
meta {
|
||||
name: folder-collection script-tests pre
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{echo-host}}
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
bru.setVar('should-test-collection-scripts', true);
|
||||
bru.setVar('should-test-folder-scripts', true);
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
meta {
|
||||
name: folder-collection script-tests
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{echo-host}}
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
// do not delete - the collection/folder scripts/tests run during this request execution
|
||||
}
|
||||
|
||||
tests {
|
||||
const collectionHeader = req.getHeader("collection-header");
|
||||
const folderHeader = req.getHeader("folder-header");
|
||||
|
||||
test("should get the header value set at collection level", function() {
|
||||
expect(collectionHeader).to.equal("collection-header-value");
|
||||
});
|
||||
|
||||
test("should get the header value set at folder level", function() {
|
||||
expect(folderHeader).to.equal("folder-header-value");
|
||||
});
|
||||
}
|
28
packages/bruno-tests/collection/scripting/js/folder.bru
Normal file
28
packages/bruno-tests/collection/scripting/js/folder.bru
Normal file
@ -0,0 +1,28 @@
|
||||
meta {
|
||||
name: js
|
||||
}
|
||||
|
||||
headers {
|
||||
folder-header: folder-header-value
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
// used by `scripting/js/folder-collection script-tests`
|
||||
const shouldTestFolderScripts = bru.getVar('should-test-folder-scripts');
|
||||
if(shouldTestFolderScripts) {
|
||||
bru.setVar('folder-var-set-by-folder-script', 'folder-var-value-set-by-folder-script');
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
// used by `scripting/js/folder-collection script-tests`
|
||||
const shouldTestFolderScripts = bru.getVar('should-test-folder-scripts');
|
||||
const folderVar = bru.getVar("folder-var-set-by-folder-script");
|
||||
if (shouldTestFolderScripts && folderVar) {
|
||||
test("folder level test - should get the var that was set by the folder script", function() {
|
||||
expect(folderVar).to.equal("folder-var-value-set-by-folder-script");
|
||||
});
|
||||
bru.setVar('folder-var-set-by-folder-script', null);
|
||||
bru.setVar('should-test-folder-scripts', null);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user