supersamples
supersamples copied to clipboard
possible incorrect format of json bodies in response
I believe that the update to supertest/superagent(depenency) from major version 2 to 3 has caused the body part of the supersamples report to change from being json formated to a single escaped string.
This is what is seen if you use supertest 3.0.0

whereas if supertest 2.0.0 is used you see

I have a simple repo to demonstrate the issue https://github.com/ghinks/supersamples-json-issue.git
I'm happy to lend a hand sorting it out too :)
node version 4.2.6
I'm probable not as familiar with this as you but the superagent response does not have body so I tried this hack
function extractResponse(superTest, response) {
if (!superTest.res.body) {
console.log('no body on the supertest response');
console.log(`but the text was ${superTest.res.text}`);
} else {
console.log('was a body');
}
const headers = responseHeaders(superTest, response);
console.log(`headers are ....=======> ${JSON.stringify(headers)}`);
// headers.forEach(h => console.log(`${h}`));
return {
status: response.status,
headers: headers,
body: superTest.res.body || JSON.parse(superTest.res.text)
};
}```
I confirm this issue, downgrading from "supertest": "~3.0.0"
to "supertest": "~2.0.0"
, makes the json output to look pretty again
I may have fixed this in my latest PR
https://github.com/rprieto/supersamples/pull/39/files#diff-7ae011eac59e190d6a735e0fd4e1431aR9
Although my solution assumes that the response is always json, so will not work for xml apis etc