From 3c5073ce3c3c578db08f3518a7c0477ad7500a4e Mon Sep 17 00:00:00 2001 From: Vitaliy Potapov Date: Thu, 4 Apr 2024 15:01:08 +0400 Subject: [PATCH] reporter: remove color symbols from stdout / stderr --- src/reporter/cucumber/messagesBuilder/AttachmentMapper.ts | 5 ++++- test/reporter-cucumber-html/check-report/passed.test.ts | 2 +- test/reporter-cucumber-html/features/steps.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/reporter/cucumber/messagesBuilder/AttachmentMapper.ts b/src/reporter/cucumber/messagesBuilder/AttachmentMapper.ts index f994b73b..97cf7214 100644 --- a/src/reporter/cucumber/messagesBuilder/AttachmentMapper.ts +++ b/src/reporter/cucumber/messagesBuilder/AttachmentMapper.ts @@ -59,6 +59,7 @@ import { AutofillMap } from '../../../utils/AutofillMap'; import { collectStepsWithCategory, getHooksRootPwStep } from './pwStepUtils'; import { PwAttachment } from '../../../playwright/types'; import { isBddDataAttachment } from '../../../run/bddDataAttachment'; +import { stripAnsiEscapes } from '../../../utils/stripAnsiEscapes'; export class AttachmentMapper { private stepAttachments = new AutofillMap(); @@ -115,7 +116,9 @@ export class AttachmentMapper { private mapStdoutAttachments(name: 'stdout' | 'stderr') { // map stdout / stderr to the 'After Hooks' step if (!this.result[name]?.length) return; - const body = this.result[name].join(''); + const body = this.result[name] + .map((s) => (typeof s === 'string' ? stripAnsiEscapes(s) : s)) + .join(''); const afterHooksRoot = this.getAfterHooksRoot(); const stepAttachments = this.stepAttachments.getOrCreate(afterHooksRoot, () => []); stepAttachments.push({ diff --git a/test/reporter-cucumber-html/check-report/passed.test.ts b/test/reporter-cucumber-html/check-report/passed.test.ts index d1385302..d7ceb6e7 100644 --- a/test/reporter-cucumber-html/check-report/passed.test.ts +++ b/test/reporter-cucumber-html/check-report/passed.test.ts @@ -49,7 +49,7 @@ test('Scenario: Scenario with attachments', async ({ page }) => { 'text attachmentsome text', // no space between 'attachment' and 'some' 'image attachment inline', 'image attachment as file', - 'stdoutsome logs', + 'stdout123 some logs', ]); }); diff --git a/test/reporter-cucumber-html/features/steps.ts b/test/reporter-cucumber-html/features/steps.ts index 261ae14f..89287552 100644 --- a/test/reporter-cucumber-html/features/steps.ts +++ b/test/reporter-cucumber-html/features/steps.ts @@ -29,7 +29,7 @@ Then('attach image as file', async ({ $testInfo }) => { }); Then('attach stdout', async () => { - console.log('some logs'); // eslint-disable-line no-console + console.log(123, 'some logs'); // eslint-disable-line no-console // don't test console.error b/c it poisons the output });