supersamples icon indicating copy to clipboard operation
supersamples copied to clipboard

possible incorrect format of json bodies in response

Open ghinks opened this issue 8 years ago • 2 comments

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

screen shot 2017-02-23 at 9 20 52 pm

whereas if supertest 2.0.0 is used you see

screen shot 2017-02-23 at 9 23 13 pm

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)
  };
}```

ghinks avatar Feb 24 '17 02:02 ghinks

I confirm this issue, downgrading from "supertest": "~3.0.0" to "supertest": "~2.0.0", makes the json output to look pretty again

freefri avatar Jul 20 '17 15:07 freefri

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

nguyenchr avatar Jul 20 '17 21:07 nguyenchr