Skip to content

Commit c6360e7

Browse files
committed
cherry-pick(#9908): feat(html): render warning message when served off file://
1 parent 161ff90 commit c6360e7

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

packages/playwright-core/src/cli/cli.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,25 @@ if (!process.env.PW_CLI_TARGET_LANG) {
248248
require(playwrightTestPackagePath).addTestCommand(program);
249249
require(playwrightTestPackagePath).addShowReportCommand(program);
250250
} else {
251-
const command = program.command('test').allowUnknownOption(true);
252-
command.description('Run tests with Playwright Test. Available in @playwright/test package.');
253-
command.action(async () => {
254-
console.error('Please install @playwright/test package to use Playwright Test.');
255-
console.error(' npm install -D @playwright/test');
256-
process.exit(1);
257-
});
251+
{
252+
const command = program.command('test').allowUnknownOption(true);
253+
command.description('Run tests with Playwright Test. Available in @playwright/test package.');
254+
command.action(async () => {
255+
console.error('Please install @playwright/test package to use Playwright Test.');
256+
console.error(' npm install -D @playwright/test');
257+
process.exit(1);
258+
});
259+
}
260+
261+
{
262+
const command = program.command('show-report').allowUnknownOption(true);
263+
command.description('Show Playwright Test HTML report. Available in @playwright/test package.');
264+
command.action(async () => {
265+
console.error('Please install @playwright/test package to use Playwright Test.');
266+
console.error(' npm install -D @playwright/test');
267+
process.exit(1);
268+
});
269+
}
258270
}
259271
}
260272

packages/playwright-core/src/web/htmlReport/htmlReport.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,24 @@ a.no-decorations {
466466
}
467467
}
468468

469+
.needs-server-message {
470+
max-width: 500px;
471+
margin: auto;
472+
height: 100%;
473+
display: flex;
474+
flex-direction: column;
475+
justify-content: center;
476+
}
477+
478+
.bash-snippet {
479+
margin-top: 10px;
480+
font-family: monospace;
481+
background: var(--color-fg-default);
482+
color: var(--color-canvas-default);
483+
border-radius: 6px;
484+
padding: 20px;
485+
}
486+
469487
@media only screen and (max-width: 600px) {
470488
.chip-header {
471489
border-radius: 0 !important;

packages/playwright-core/src/web/htmlReport/htmlReport.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export const Report: React.FC = () => {
4242
})();
4343
}, [report, expandedFiles]);
4444

45+
if (window.location.protocol === 'file:') {
46+
return <div className='needs-server-message'>
47+
Playwright report needs to be served as a web page. Consider the following options to view it locally:
48+
<div className='bash-snippet'>npx node-static playwright-report</div>
49+
<div className='bash-snippet'>cd playwright-report &amp;&amp; python -m SimpleHTTPServer</div>
50+
</div>;
51+
}
52+
4553
return <div className='vbox columns'>
4654
{!fetchError && <div className='flow-container'>
4755
<Route params=''>

0 commit comments

Comments
 (0)