-
Notifications
You must be signed in to change notification settings - Fork 2.3k
require() local script with additionalContextRoots works differently in pre-request and post-request code #2942
Description
I have checked the following:
- I use the newest version of bruno.
- I've searched existing issues and found nothing related to my issue.
Describe the bug
I'm building a small shared module for cross cutting needs that will be used in all my collections.
But when I try to include file from additionalContextRoots - require() behavior is different in pre-request and post-response steps:
- pre-request - everything works as expected
- post-response -
Error invoking remote method 'send-http-request': VMError: Cannot find module '../_bruno-scripts/foo.js'
Reproducing it should be quite straightforward. Repro collection attached.
What I'm trying to do is to have a common library with log() in foo.js file above collection. And I want to require it in both - collection pre-request and post-response scripts (so I have Log statement invoked before and after any call )
Expected to see : LOG post-response as a last message, but getting
Error invoking remote method 'send-http-request': VMError: Cannot find module '../_bruno-scripts/foo.js'
in main window.
Hardware :
CPU Arch: M1
OS: MacOS Sonoma 14.6.1 (23G93)
Bruno v1.26.2
electron : 31.2.1
chrome : 126.0.6478.127
node : 20.15.0
v8 : 12.6.228.21-electron.0
.bru file to reproduce the bug
bruno.json
{
"version": "1",
"name": "Example Bruno collection",
"type": "collection",
"ignore": [
"node_modules",
".git",
".vscode"
],
"scripts": {
"additionalContextRoots": [
"../_bruno-scripts"
],
"moduleWhitelist": [
"form-data"
],
"filesystemAccess": {
"allow": true
}
}
}
collection.bru
auth {
mode: none
}
script:pre-request {
console.log("-------------- PRE-REQUEST:")
var tools = require('../_bruno-scripts/foo.js')
tools.log("LOG pre-request")
}
script:post-response {
console.log("-------------- POST-RESPONSE")
var tools = require('../_bruno-scripts/foo.js')
tools.log("LOG post-response")
}
TestCall.bru (can be anything):
meta {
name: TestCall
type: http
seq: 2
}
get {
url: https://webhook.site/0d6eeef8-c745-4895-a566-65e9f6ef0bef
body: none
auth: none
}
_bruno-scripts/foo.js (above collection folder) :
const helpers = {
log: function (str) {
var now = new Date();
var res = str
if (typeof str === 'object')
res = JSON.stringify(str)
console.log(`${now.toISOString()} > ${res}`);
},
}
module.exports = helpers;
Screenshots/Live demo link
https://github.com/user-attachments/assets/59f02912-b57f-4fc1-be86-a24ae987f971
