Skip to content
Merged
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
4 changes: 2 additions & 2 deletions packages/playwright-core/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
!lib/**/*.png
!lib/**/*.svg
!lib/**/*.ttf
!lib/**/*.json
!lib/skill/**/*.md
!lib/utilsBundleImpl/xdg-open
!lib/**/manifest.webmanifest
# Exclude injected files. A preprocessed version of these is included via lib/generated.
Expand Down Expand Up @@ -37,6 +39,4 @@ lib/**/injected/
!NOTICE
# Include browser descriptors.
!browsers.json
# Include generated devices descriptors
!deviceDescriptorsSource.json
!ThirdPartyNotices.txt
4 changes: 3 additions & 1 deletion packages/playwright/src/errorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import path from 'path';

import { parseErrorStack, stripAnsiEscapes } from 'playwright-core/lib/utils';

import { relativeFilePath } from './util';

import type { TestInfoError } from '../types/test';

const fixTestInstructions = `# Instructions
Expand Down Expand Up @@ -46,7 +48,7 @@ export function buildErrorContext(options: {
'# Test info',
'',
`- Name: ${titlePath.join(' >> ')}`,
`- Location: ${location.file}:${location.line}:${location.column}`,
`- Location: ${relativeFilePath(location.file)}:${location.line}:${location.column}`,
];

if (meaningfulErrors.length) {
Expand Down
21 changes: 21 additions & 0 deletions tests/playwright-test/playwright.artifacts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,27 @@ test('should work with trace: retain-on-failure-and-retries', async ({ runInline
]);
});

test('error-context should use relative path in location', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('fail', async ({ page }) => {
expect(1).toBe(2);
});
`,
}, { workers: 1 });

expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);

const errorContextPath = testInfo.outputPath('test-results', 'a-fail', 'error-context.md');
const content = fs.readFileSync(errorContextPath, 'utf8');
const locationLine = content.split('\n').find(line => line.startsWith('- Location:'))!;
expect(locationLine).toBeTruthy();
// Location should be a relative path, not absolute.
expect(locationLine).toContain('- Location: a.spec.ts:');
});

test('should take screenshot when page is closed in afterEach', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
Expand Down
Loading