mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-16 04:11:29 +00:00
* Bugfix: Add cheerio and xml2js modules to post-response scripts * chore: improved cheerio and xml2js test --------- Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
58 lines
1.4 KiB
Plaintext
58 lines
1.4 KiB
Plaintext
meta {
|
|
name: xml2js
|
|
type: http
|
|
seq: 1
|
|
}
|
|
|
|
get {
|
|
url: {{host}}/ping
|
|
body: none
|
|
auth: none
|
|
}
|
|
|
|
script:pre-request {
|
|
var parseString = require('xml2js').parseString;
|
|
var xml = "<root>Hello xml2js - pre request!</root>"
|
|
parseString(xml, function (err, result) {
|
|
bru.setVar("xml2js-test-result-pre-request", result);
|
|
});
|
|
}
|
|
|
|
script:post-response {
|
|
var parseString = require('xml2js').parseString;
|
|
var xml = "<root>Hello xml2js - post response!</root>"
|
|
parseString(xml, function (err, result) {
|
|
bru.setVar("xml2js-test-result-post-response", result);
|
|
});
|
|
}
|
|
|
|
tests {
|
|
var parseString = require('xml2js').parseString;
|
|
|
|
test("xml2js parseString in scripts - pre request", function() {
|
|
const expected = {
|
|
root: 'Hello xml2js - pre request!'
|
|
};
|
|
const result = bru.getVar('xml2js-test-result-pre-request');
|
|
expect(result).to.eql(expected);
|
|
});
|
|
|
|
test("xml2js parseString in scripts - post response", function() {
|
|
const expected = {
|
|
root: 'Hello xml2js - post response!'
|
|
};
|
|
const result = bru.getVar('xml2js-test-result-post-response');
|
|
expect(result).to.eql(expected);
|
|
});
|
|
|
|
test("xml2js parseString in tests", async function() {
|
|
var xml = "<root>Hello inside test!</root>"
|
|
const expected = {
|
|
root: 'Hello inside test!'
|
|
};
|
|
parseString(xml, function (err, result) {
|
|
expect(result).to.eql(expected);
|
|
});
|
|
});
|
|
}
|