mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-26 22:25:40 +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>
60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
meta {
|
|
name: cheerio
|
|
type: http
|
|
seq: 1
|
|
}
|
|
|
|
post {
|
|
url: https://echo.usebruno.com
|
|
body: text
|
|
auth: none
|
|
}
|
|
|
|
body:text {
|
|
<h2 class="title">Hello Bruno!</h2>
|
|
}
|
|
|
|
script:pre-request {
|
|
const cheerio = require('cheerio');
|
|
|
|
const $ = cheerio.load('<h2 class="title">Hello world</h2>');
|
|
|
|
$('h2.title').text('Hello pre-request!');
|
|
$('h2').addClass('welcome');
|
|
|
|
bru.setVar("cheerio-test-pre-request", $.html());
|
|
}
|
|
|
|
script:post-response {
|
|
const cheerio = require('cheerio');
|
|
|
|
const $ = cheerio.load('<h2 class="title">Hello world</h2>');
|
|
|
|
$('h2.title').text('Hello post-response!');
|
|
$('h2').addClass('welcome');
|
|
|
|
bru.setVar("cheerio-test-post-response", $.html());
|
|
}
|
|
|
|
tests {
|
|
const cheerio = require('cheerio');
|
|
|
|
test("cheerio html - from pre request script", function() {
|
|
const expected = '<html><head></head><body><h2 class="title welcome">Hello pre-request!</h2></body></html>';
|
|
const html = bru.getVar('cheerio-test-pre-request');
|
|
expect(html).to.eql(expected);
|
|
});
|
|
|
|
test("cheerio html - from post response script", function() {
|
|
const expected = '<html><head></head><body><h2 class="title welcome">Hello post-response!</h2></body></html>';
|
|
const html = bru.getVar('cheerio-test-post-response');
|
|
expect(html).to.eql(expected);
|
|
});
|
|
|
|
test("cheerio html - from tests", function() {
|
|
const expected = '<html><head></head><body><h2 class="title">Hello Bruno!</h2></body></html>';
|
|
const $ = cheerio.load(res.body);
|
|
expect($.html()).to.eql(expected);
|
|
});
|
|
}
|