fix(console): make format console message w/o args (#26620)

Fixes https://github.com/microsoft/playwright/issues/26600
This commit is contained in:
Pavel Feldman 2023-08-22 14:29:35 -07:00 committed by GitHub
parent 5646875e5c
commit 65aa062ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -106,7 +106,7 @@ export const ConsoleTab: React.FunctionComponent<{
const { browserMessage, browserError, nodeMessage } = entry;
if (browserMessage) {
const text = browserMessage.args ? format(browserMessage.args) : browserMessage.text;
const text = browserMessage.args && browserMessage.args.length ? format(browserMessage.args) : browserMessage.text;
const url = browserMessage.location.url;
const filename = url ? url.substring(url.lastIndexOf('/') + 1) : '<anonymous>';
locationText = `${filename}:${browserMessage.location.lineNumber}`;

View File

@ -117,13 +117,14 @@ test('should format console messages in page', async ({ runUITest }, testInfo) =
'a.spec.ts': `
import { test, expect } from '@playwright/test';
test('print', async ({ page }) => {
await page.evaluate(() => {
await page.evaluate(async () => {
console.log('Object %O', { a: 1 });
console.log('Date %o', new Date());
console.log('Regex %o', /a/);
console.log('Number %f', -0, 'one', 2);
console.log('Download the %cReact DevTools%c for a better development experience: %chttps://fb.me/react-devtools', 'font-weight:bold;color:red;outline:blue', '', 'color: blue; text-decoration: underline');
console.log('Array', 'of', 'values');
await fetch('http://localhost:9889');
});
});
`,
@ -139,6 +140,7 @@ test('should format console messages in page', async ({ runUITest }, testInfo) =
'Number 0 one 2',
'Download the React DevTools for a better development experience: https://fb.me/react-devtools',
'Array of values',
'Failed to load resource: net::ERR_CONNECTION_REFUSED',
]);
const label = page.getByText('React DevTools');