Skip to content

Commit

Permalink
Fix: Resolved the issue of garbled characters in JSON response conten…
Browse files Browse the repository at this point in the history
…t displaying in Allure reports.
  • Loading branch information
win5923 committed Nov 17, 2023
1 parent 557ca0e commit a5b1af1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/newman-reporter-allure/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,21 @@ class AllureReporter {
}

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

// Check if the response content type is JSON
const contentTypeHeader = args.item.responses.members[0]?.getHeader('Content-Type');
if (contentTypeHeader && contentTypeHeader.toLowerCase().includes('application/json')) {
contentType = ContentType.JSON;
}

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

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

0 comments on commit a5b1af1

Please sign in to comment.