Skip to content

Commit

Permalink
reporter: remove color symbols from stdout / stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Apr 4, 2024
1 parent 1d0fa0d commit 3c5073c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/reporter/cucumber/messagesBuilder/AttachmentMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<pw.TestStep, PwAttachment[]>();
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion test/reporter-cucumber-html/check-report/passed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]);
});

Expand Down
2 changes: 1 addition & 1 deletion test/reporter-cucumber-html/features/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down

0 comments on commit 3c5073c

Please sign in to comment.