fix(reporter): properly indent multiline attachments (#20847)

Text attachments were only indented on the first line.
This commit is contained in:
Joel Einbinder 2023-02-13 13:28:34 -05:00 committed by GitHub
parent e9ca483666
commit 997dfa9274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -285,7 +285,8 @@ export function formatFailure(config: FullConfig, test: TestCase, options: {inde
let text = attachment.body.toString();
if (text.length > 300)
text = text.slice(0, 300) + '...';
resultLines.push(colors.cyan(` ${text}`));
for (const line of text.split('\n'))
resultLines.push(colors.cyan(` ${line}`));
}
}
resultLines.push(colors.cyan(separator(' ')));

View File

@ -278,3 +278,26 @@ test(`testInfo.attach throw if name is not string`, async ({ runInlineTest }) =>
expect(result.output).toContain('"name" should be string.');
});
test('render text attachment with multiple lines', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test('one', async ({}, testInfo) => {
testInfo.attachments.push({
name: 'attachment',
body: Buffer.from('First line\\nSecond line\\nThird line'),
contentType: 'text/plain'
});
expect(1).toBe(0);
});
`,
}, { reporter: 'line' });
const text = result.output;
expect(text).toContain(' attachment #1: attachment (text/plain) ─────────────────────────────────────────────────────────');
expect(text).toContain(' First line');
expect(text).toContain(' Second line');
expect(text).toContain(' Third line');
expect(text).toContain(' ────────────────────────────────────────────────────────────────────────────────────────────────');
expect(result.exitCode).toBe(1);
});