Feature/add execution context
Description
In reference to https://github.com/usebruno/bruno/issues/1874 I have the need to now the execution context of the request:
- Name of the Request executed
- Path of the .bru name
- Execution mode: single, runner, cli
- Associated documentation of the request
This will allow me to take some decisions in scripts, such as how to name logs, where to find data associated to every request, apply or exclude some tests depending on the way it is launched, etc.
Pre Request script example
console.log("-------- executionMode ----------")
console.log(bru.getVar("executionMode"))
console.log("-------- pathname ----------")
console.log(bru.getVar("currentItem").pathname)
console.log("-------- filename ----------")
console.log(bru.getVar("currentItem").filename)
Outputs
Contribution Checklist:
- [X] The pull request only addresses one issue or adds one feature.
- [X] The pull request does not introduce any breaking changes
- [X] I have added screenshots or gifs to help explain the change if applicable.
- [X] I have read the contribution guidelines.
- [X] Create an issue and link to the pull request.
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Interesting idea! But I worry about potential name-conflicts with user-defined variables.
How about attaching this info to the bru object? Something like
bru.context.executionMode
bru.context.currentItem
In Postman, there was pm.request.name for the currentItem.fileName...
hi @mjhcorporate, in fact, I wanted to include it in the request object, but I notice the req object is different depending on the context: single request, runner or cli and I prefer not to touch it because it can break somenone's script
Yes, I agree that we should not put it on the request object, and that we should not break existing scripts. I think attaching new properties to the bru object is the safest path forward.