Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/playwright/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ import type { TestCase } from './common/test';
const PLAYWRIGHT_TEST_PATH = path.join(__dirname, '..');
const PLAYWRIGHT_CORE_PATH = path.dirname(require.resolve('playwright-core/package.json'));

export function filterStackTrace(e: Error): { message: string, stack: string, cause?: ReturnType<typeof filterStackTrace> } {
export function filterStackTrace(e: Error): { message: string, stack: string, cause?: ReturnType<typeof filterStackTrace>, errors?: ReturnType<typeof filterStackTrace>[] } {
const name = e.name ? e.name + ': ' : '';
const cause = e.cause instanceof Error ? filterStackTrace(e.cause) : undefined;
const errors = e instanceof AggregateError
? e.errors.filter(error => error instanceof Error).map(error => filterStackTrace(error))
: undefined;

if (process.env.PWDEBUGIMPL)
return { message: name + e.message, stack: e.stack || '', cause };
return { message: name + e.message, stack: e.stack || '', cause, errors };

const stackLines = stringifyStackFrames(filteredStackTrace(e.stack?.split('\n') || []));
return {
message: name + e.message,
stack: `${name}${e.message}${stackLines.map(line => '\n' + line).join('')}`,
cause,
errors,
};
}

Expand Down
21 changes: 21 additions & 0 deletions tests/playwright-test/reporter-base.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ for (const useIntermediateMergeReport of [false, true] as const) {
expect(result.output).toContain('afterAll executed successfully');
});

test('should print AggregateError nested errors', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';

test('foobar', async () => {
throw new AggregateError([
new Error('inner-message-1'),
new Error('inner-message-2'),
], 'aggregate-message');
});
`
});

expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
expect(result.output).toContain('AggregateError: aggregate-message');
expect(result.output).toContain('inner-message-1');
expect(result.output).toContain('inner-message-2');
});

test('should print codeframe from a helper', async ({ runInlineTest }) => {
const result = await runInlineTest({
'helper.ts': `
Expand Down