Skip to content

Commit

Permalink
Fix: Resolved the issue of formatting in JSON response content displa…
Browse files Browse the repository at this point in the history
…ying in Allure reports.
  • Loading branch information
win5923 committed Nov 29, 2023
1 parent 9b32c6c commit 92daa86
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/newman-reporter-allure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,21 @@ class AllureReporter {
}

if (response?.body) {
let contentType = ContentType.TEXT;

// check if the response is JSON
const contentTypeHeader = response.headers?.one("Content-Type") ?? "";;
if (contentTypeHeader && /application\/json/i.test(contentTypeHeader)) {
contentType = ContentType.JSON;
}

const attachment = this.allureRuntime.writeAttachment(response.body, {
contentType: ContentType.TEXT,
contentType: contentType,
});

this.currentExecutable.addAttachment(
"Response Body",
{ contentType: ContentType.TEXT },
{ contentType: contentType },
attachment,
);
}
Expand Down

0 comments on commit 92daa86

Please sign in to comment.