fix: cli - collection level script, added tests

This commit is contained in:
lohxt1
2024-12-06 22:58:02 +05:30
parent 67ead9739e
commit 3fe0d43bdc
5 changed files with 104 additions and 16 deletions

View File

@@ -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);
}

View File

@@ -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");
});
}

View 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);
}
}