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
5 changes: 4 additions & 1 deletion packages/playwright/src/reporters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ class HtmlReporter implements ReporterV2 {
await showHTMLReport(this._outputFolder, this._host, this._port, singleTestId);
} else if (this._options._mode === 'test' && !!process.stdin.isTTY) {
const packageManagerCommand = getPackageManagerExecCommand();
const relativeReportPath = this._outputFolder === standaloneDefaultFolder() ? '' : ' ' + path.relative(process.cwd(), this._outputFolder);
// npm sets INIT_CWD to "the full path you were in when you ran npm run".
const invocationDir = process.env.INIT_CWD || process.cwd();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment where INIT_CWD can come from

const isDefaultFolder = invocationDir === process.cwd() && this._outputFolder === standaloneDefaultFolder();
const relativeReportPath = isDefaultFolder ? '' : ' ' + (path.relative(invocationDir, this._outputFolder) || '.');
const hostArg = this._host ? ` --host ${this._host}` : '';
const portArg = this._port ? ` --port ${this._port}` : '';
writeLine('');
Expand Down
32 changes: 32 additions & 0 deletions tests/playwright-test/reporter-html.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3793,6 +3793,38 @@ test('should support merge files option', async ({ runInlineTest, showReport, pa
`);
});

test('should print show-report command without path when invoked from the report dir', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'playwright.config.ts': `
process.stdin.isTTY = true;
export default { reporter: 'html' };
`,
'a.test.js': `
import { test } from '@playwright/test';
test('passes', () => {});
`,
}, {}, { PLAYWRIGHT_HTML_OPEN: 'never', INIT_CWD: testInfo.outputPath() });
expect(result.exitCode).toBe(0);
expect(result.output).toContain('To open last HTML report run:');
expect(result.output).toMatch(/npx playwright show-report\n/);
});

test('should print show-report command with path relative to npm invocation dir', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'sub/package.json': `{ "name": "sub" }`,
'sub/playwright.config.ts': `
process.stdin.isTTY = true;
export default { reporter: 'html' };
`,
'sub/a.test.js': `
import { test } from '@playwright/test';
test('passes', () => {});
`,
}, {}, { PLAYWRIGHT_HTML_OPEN: 'never', INIT_CWD: testInfo.outputPath() }, { cwd: 'sub' });
expect(result.exitCode).toBe(0);
expect(result.output).toContain(`npx playwright show-report ${path.join('sub', 'playwright-report')}\n`);
});

test.describe('show-report .zip support', () => {
test('should serve a zipped report', async ({ runInlineTest, childProcess, findFreePort, page }, testInfo) => {
await runInlineTest({
Expand Down
Loading