mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-07 22:18:33 +00:00
fix: cli - collection level script, added tests
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user