Skip to content
Closed
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
6 changes: 4 additions & 2 deletions packages/playwright/src/common/testType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ export class TestTypeImpl {
const testInfo = currentTestInfo();
if (!testInfo)
throw new Error(`test.step() can only be called from a test`);
await testInfo._onUserStepBegin?.(title);
if (testInfo._onUserStepBegin)
await testInfo._onUserStepBegin?.(title);
const step = testInfo._addStep({ category: 'test.step', title, location: options.location, box: options.box });
return await currentZone().with('stepZone', step).run(async () => {
try {
Expand All @@ -299,7 +300,8 @@ export class TestTypeImpl {
step.complete({ error });
throw error;
} finally {
await testInfo._onUserStepEnd?.();
if (testInfo._onUserStepEnd)
await testInfo._onUserStepEnd?.();
}
});
}
Expand Down
42 changes: 42 additions & 0 deletions tests/playwright-test/test-step.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1826,3 +1826,45 @@ fixture | Fixture "context"
pw:api | Close context
`);
});

test('should return all called files inside stack trace', async ({ runInlineTest }) => {
const result = await runInlineTest({
'reporter.ts': stepIndentReporter,
'playwright.config.ts': `
module.exports = {
reporter: [['./reporter']],
};
`,
'a.test.ts': `
import { test } from '@playwright/test'
import { foo } from './b.model';

test('has title', async ({ page }) => {
await test.step('multiple check', async () => {
await Promise.all([
foo(page),
foo(page),
])
})
});
`,
'b.model.ts': `
import test, { expect, Page } from "@playwright/test";

export const foo = async (page: Page) => {
await test.step('Check color', async () => {
await Promise.all([
await test.step('check1', async () => expect(page.locator('body')).toHaveCSS('color', 'fffffff', { timeout: 50 })),
await test.step('check2', async () => expect(page.locator('body')).toHaveCSS('color', 'fffffff', { timeout: 50 })),
])
});
}
`,
}, { reporter: '', workers: 1 });

const message = result.results[0].errors[0].message;

expect(message).toMatch(new RegExp(`a.test.ts:6:20`));
expect(message).toMatch(new RegExp(`a.test.ts:8:16`));
expect(message).toMatch(new RegExp(`at foo (.*?)\/b\.model\.ts:5:24`));
});