usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.56k stars 1.27k forks source link

Variables Set in Pre-Request Script Remain Unresolved in Bruno Requests #3513

Open christopherbholland opened 2 days ago

christopherbholland commented 2 days ago

I have checked the following:

Describe the bug

Description:

I'm encountering an issue in Bruno where variables set within the pre-request script remain unresolved in the requests. Despite correctly implementing the script to generate and set these variables, they are not being recognized when referenced in the request no matter which level they're in (collection, folder, request).

Steps to Reproduce:

Pre-Request Script: const { nanoid } = require('nanoid'); // Import nanoid function const moment = require('moment'); // Import moment.js library

// Generate a unique message ID and set it as a variable bru.setVar("UniqueMsgID", nanoid());

// Capture the current date/time in ISO 8601 format and set it as a variable bru.setVar("CurInstISO", moment().format('YYYY-MM-DDTHH:mm:ss.SSSZ'));

// Capture the current date/time in HL7v2 format and set it as a variable bru.setVar("CurInstHL7v2", moment().format('YYYYMMDDHHmmss'));

Expected Behavior: The variables UniqueMsgID, CurInstISO, and CurInstHL7v2 should be correctly set in the pre-request script and their values should be accessible and resolved when referenced in the request headers.

Actual Behavior: The variables remain unresolved in the request headers, resulting in empty or undefined values being sent.

Additional Information: I have verified that the bru object is properly initialized and that the bru.setVar function is available in the scripting context. The nanoid and moment libraries are correctly installed and imported. The variables are set before the request is sent.

Environment:

Bruno Version: 1.28 and 1.34.2 Operating System: Windows 11 Request: Assistance in resolving this issue would be greatly appreciated. If additional information is required, please let me know.

.bru file to reproduce the bug

No response

Screenshots/Live demo link

image image

ayumakesit commented 17 hours ago

Hi! Is this a similar or even the same topic as this discussion? https://github.com/usebruno/bruno/discussions/992

Thanks