-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ensure variables set in scripts/tests during
bru.runRequest
reflect…
… in original request scripts/tests
- Loading branch information
Showing
3 changed files
with
105 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
packages/bruno-tests/collection/scripting/api/bru/runRequest-1.bru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
meta { | ||
name: runRequest-1 | ||
type: http | ||
seq: 10 | ||
} | ||
|
||
post { | ||
url: {{echo-host}} | ||
body: text | ||
auth: none | ||
} | ||
|
||
body:text { | ||
bruno | ||
} | ||
|
||
script:pre-request { | ||
// reset values | ||
bru.setVar('run-request-runtime-var', null); | ||
bru.setEnvVar('run-request-env-var', null); | ||
bru.setGlobalEnvVar('run-request-global-env-var', null); | ||
|
||
// the above vars will be set in the below request | ||
const resp = await bru.runRequest('scripting/api/bru/runRequest-2'); | ||
|
||
bru.setVar('run-request-resp', { | ||
data: resp?.data, | ||
statusText: resp?.statusText, | ||
status: resp?.status | ||
}); | ||
} | ||
|
||
tests { | ||
test("should get runtime var set in runRequest-2", function() { | ||
const val = bru.getVar("run-request-runtime-var"); | ||
expect(val).to.equal("run-request-runtime-var-value"); | ||
}); | ||
|
||
test("should get env var set in runRequest-2", function() { | ||
const val = bru.getEnvVar("run-request-env-var"); | ||
expect(val).to.equal("run-request-env-var-value"); | ||
}); | ||
|
||
test("should get global env var set in runRequest-2", function() { | ||
const val = bru.getGlobalEnvVar("run-request-global-env-var"); | ||
expect(val).to.equal("run-request-global-env-var-value"); | ||
}); | ||
|
||
test("should get response of runRequest-2", function() { | ||
const val = bru.getVar('run-request-resp'); | ||
expect(JSON.stringify(val)).to.equal(JSON.stringify({ | ||
"data": "bruno", | ||
"statusText": "OK", | ||
"status": 200 | ||
})); | ||
}); | ||
} |
21 changes: 21 additions & 0 deletions
21
packages/bruno-tests/collection/scripting/api/bru/runRequest-2.bru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
meta { | ||
name: runRequest-2 | ||
type: http | ||
seq: 11 | ||
} | ||
|
||
post { | ||
url: {{echo-host}} | ||
body: text | ||
auth: none | ||
} | ||
|
||
body:text { | ||
bruno | ||
} | ||
|
||
script:pre-request { | ||
bru.setVar('run-request-runtime-var', 'run-request-runtime-var-value'); | ||
bru.setEnvVar('run-request-env-var', 'run-request-env-var-value'); | ||
bru.setGlobalEnvVar('run-request-global-env-var', 'run-request-global-env-var-value'); | ||
} |