diff --git a/src/index.ts b/src/index.ts index 43791227..0a567ddb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -347,7 +347,10 @@ export class CucumberJsJsonReporter extends WDIOReporter { let data = attachment?.data // If the mime_type is 'text/plain' or 'application/json', encode the data to a base64 string (like Cucumber v10+ does) - if (attachment.type === 'text/plain' || attachment.type === 'application/json') { + if (attachment.type === 'text/plain') { + data = Buffer.from(String(data)).toString('base64') + } + if (attachment.type === 'application/json') { data = Buffer.from(JSON.stringify(data)).toString('base64') } diff --git a/tests/__snapshots__/reporter.spec.ts.snap b/tests/__snapshots__/reporter.spec.ts.snap index 187e644c..0d217525 100644 --- a/tests/__snapshots__/reporter.spec.ts.snap +++ b/tests/__snapshots__/reporter.spec.ts.snap @@ -19,7 +19,7 @@ exports[`reporter > cucumberJsAttachment > should be able to add embeddings to a { "embeddings": [ { - "data": "ImRhdGEi", + "data": "ZGF0YQ==", "mime_type": "text/plain", }, ], @@ -52,7 +52,7 @@ exports[`reporter > cucumberJsAttachment > should be able to add embeddings to a "mime_type": "text/plain", }, { - "data": "ImRhdGEtMiI=", + "data": "ZGF0YS0y", "mime_type": "text/plain", }, ], diff --git a/tests/__snapshots__/reporter.test.ts.snap b/tests/__snapshots__/reporter.test.ts.snap index 144246a3..98b25dc1 100644 --- a/tests/__snapshots__/reporter.test.ts.snap +++ b/tests/__snapshots__/reporter.test.ts.snap @@ -19,7 +19,7 @@ exports[`reporter > cucumberJsAttachment > should be able to add embeddings to a { "embeddings": [ { - "data": "ImRhdGEi", + "data": "ZGF0YQ==", "mime_type": "text/plain", }, ], @@ -52,7 +52,7 @@ exports[`reporter > cucumberJsAttachment > should be able to add embeddings to a "mime_type": "text/plain", }, { - "data": "ImRhdGEtMiI=", + "data": "ZGF0YS0y", "mime_type": "text/plain", }, ],