Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

possible incorrect format of json bodies in response #35

Open
ghinks opened this issue Feb 24, 2017 · 2 comments
Open

possible incorrect format of json bodies in response #35

ghinks opened this issue Feb 24, 2017 · 2 comments

Comments

@ghinks
Copy link

ghinks commented Feb 24, 2017

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)
  };
}```
@freefri
Copy link

freefri commented Jul 20, 2017

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

@nguyenchr
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants