mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
add: hooks component add support for hooks within bruno-lang fix: hooks is not getting save hooks implemtation add hooks component within folders, requests add: quick js shims for hooks fix: garbage collected hook managers send logs to main rm: hook manager store feat: introduce HOOK_EVENTS constant for improved hook management add folder start/end events add folder run events rm: folder run related events add cli support for hooks support script:hooks instead of hooks move hooks to script tab make outer scope available within callback in safemode added runner, req apis as an abstraction over event based hooks fix: crash while editing folder hooks rm: unused files fix: self review changes refactor, request specific hook manager deleted once add: cm rm: spaces add prompt var rm: indent fix: lint refactor: shims handling for hooks fix: enable async calling in dev mode for gui, cli fix: support async callbacks within safe mode rm: vm instance fix: review comments fix: review comments add cli tests for hooks rm: client certs fix: add hooks to oc yaml fix: rename uid ot path name for better clarity, app crash when saving folder hooks rm: console rm: vm2 runtime leftover rm: check add: handler cleanup function add: playwright test case for hooks rm: review fixes fix: review comments add fallback hook manager add fallback hook manager fix: show error from hooks scripts within response pane change: collection events name feat: add name spaced hooks fix: review comments add: hooks specific collection for testing use hooks manager as a private field fix: tests use collection from bruno-test within playwright rm: databuffer test fix: playwright test rm: unintended changes rm: file
62 lines
1.6 KiB
Plaintext
62 lines
1.6 KiB
Plaintext
meta {
|
|
name: both-hooks-req-res
|
|
type: http
|
|
seq: 3
|
|
}
|
|
|
|
post {
|
|
url: {{host}}/api/echo/json
|
|
body: json
|
|
auth: none
|
|
}
|
|
|
|
body:json {
|
|
{
|
|
"test": "data"
|
|
}
|
|
}
|
|
|
|
script:hooks {
|
|
// beforeRequest: Only req is available
|
|
bru.hooks.http.onBeforeRequest(({ req }) => {
|
|
bru.setVar('before-req-url', req.getUrl());
|
|
bru.setVar('before-req-method', req.getMethod());
|
|
bru.setVar('before-req-name', req.getName());
|
|
req.setHeader('X-Modified-In-Before', 'yes');
|
|
});
|
|
|
|
// afterResponse: Both req and res are available
|
|
bru.hooks.http.onAfterResponse(({ req, res }) => {
|
|
// Can still access req in afterResponse
|
|
bru.setVar('after-req-url', req.getUrl());
|
|
bru.setVar('after-req-method', req.getMethod());
|
|
bru.setVar('after-req-header', req.getHeader('X-Modified-In-Before'));
|
|
|
|
// Access res
|
|
bru.setVar('after-res-status', res.getStatus());
|
|
bru.setVar('after-res-body', res.getBody());
|
|
});
|
|
}
|
|
|
|
tests {
|
|
test("req is accessible in beforeRequest", function() {
|
|
expect(bru.getVar('before-req-url')).to.include('/api/echo/json');
|
|
expect(bru.getVar('before-req-method')).to.equal('POST');
|
|
});
|
|
|
|
test("req is accessible in afterResponse", function() {
|
|
expect(bru.getVar('after-req-url')).to.include('/api/echo/json');
|
|
expect(bru.getVar('after-req-method')).to.equal('POST');
|
|
});
|
|
|
|
test("modifications from beforeRequest visible in afterResponse", function() {
|
|
expect(bru.getVar('after-req-header')).to.equal('yes');
|
|
});
|
|
|
|
test("res is accessible in afterResponse", function() {
|
|
expect(bru.getVar('after-res-status')).to.equal(200);
|
|
expect(bru.getVar('after-res-body')).to.have.property('test');
|
|
});
|
|
}
|
|
|