mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-08 12:28:46 +03:00
fix(trace-viewer): exit if given trace.zip does not exist (#30222)
This commit is contained in:
parent
010bc29a3c
commit
43745210a5
@ -53,21 +53,17 @@ export type TraceViewerAppOptions = {
|
|||||||
persistentContextOptions?: Parameters<BrowserType['launchPersistentContext']>[2];
|
persistentContextOptions?: Parameters<BrowserType['launchPersistentContext']>[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
async function validateTraceUrls(traceUrls: string[]) {
|
function validateTraceUrls(traceUrls: string[]) {
|
||||||
for (const traceUrl of traceUrls) {
|
for (const traceUrl of traceUrls) {
|
||||||
let traceFile = traceUrl;
|
let traceFile = traceUrl;
|
||||||
// If .json is requested, we'll synthesize it.
|
// If .json is requested, we'll synthesize it.
|
||||||
if (traceUrl.endsWith('.json'))
|
if (traceUrl.endsWith('.json'))
|
||||||
traceFile = traceUrl.substring(0, traceUrl.length - '.json'.length);
|
traceFile = traceUrl.substring(0, traceUrl.length - '.json'.length);
|
||||||
|
|
||||||
if (!traceUrl.startsWith('http://') && !traceUrl.startsWith('https://') && !fs.existsSync(traceFile) && !fs.existsSync(traceFile + '.trace')) {
|
if (!traceUrl.startsWith('http://') && !traceUrl.startsWith('https://') && !fs.existsSync(traceFile) && !fs.existsSync(traceFile + '.trace'))
|
||||||
// eslint-disable-next-line no-console
|
throw new Error(`Trace file ${traceUrl} does not exist!`);
|
||||||
console.error(`Trace file ${traceUrl} does not exist!`);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function startTraceViewerServer(options?: TraceViewerServerOptions): Promise<HttpServer> {
|
export async function startTraceViewerServer(options?: TraceViewerServerOptions): Promise<HttpServer> {
|
||||||
const server = new HttpServer();
|
const server = new HttpServer();
|
||||||
@ -146,8 +142,7 @@ export async function installRootRedirect(server: HttpServer, traceUrls: string[
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runTraceViewerApp(traceUrls: string[], browserName: string, options: TraceViewerServerOptions & { headless?: boolean }, exitOnClose?: boolean) {
|
export async function runTraceViewerApp(traceUrls: string[], browserName: string, options: TraceViewerServerOptions & { headless?: boolean }, exitOnClose?: boolean) {
|
||||||
if (!validateTraceUrls(traceUrls))
|
validateTraceUrls(traceUrls);
|
||||||
return;
|
|
||||||
const server = await startTraceViewerServer(options);
|
const server = await startTraceViewerServer(options);
|
||||||
await installRootRedirect(server, traceUrls, options);
|
await installRootRedirect(server, traceUrls, options);
|
||||||
const page = await openTraceViewerApp(server.urlPrefix(), browserName, options);
|
const page = await openTraceViewerApp(server.urlPrefix(), browserName, options);
|
||||||
@ -157,8 +152,7 @@ export async function runTraceViewerApp(traceUrls: string[], browserName: string
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runTraceInBrowser(traceUrls: string[], options: TraceViewerServerOptions) {
|
export async function runTraceInBrowser(traceUrls: string[], options: TraceViewerServerOptions) {
|
||||||
if (!validateTraceUrls(traceUrls))
|
validateTraceUrls(traceUrls);
|
||||||
return;
|
|
||||||
const server = await startTraceViewerServer(options);
|
const server = await startTraceViewerServer(options);
|
||||||
await installRootRedirect(server, traceUrls, options);
|
await installRootRedirect(server, traceUrls, options);
|
||||||
await openTraceInBrowser(server.urlPrefix());
|
await openTraceInBrowser(server.urlPrefix());
|
||||||
|
@ -58,4 +58,14 @@ test('cli should work', async ({ exec, tmpWorkspace }) => {
|
|||||||
await exec('npx playwright screenshot about:blank two.png');
|
await exec('npx playwright screenshot about:blank two.png');
|
||||||
await fs.promises.stat(path.join(tmpWorkspace, 'two.png'));
|
await fs.promises.stat(path.join(tmpWorkspace, 'two.png'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await test.step('show-trace', async () => {
|
||||||
|
const result = await exec('npx playwright show-trace i-do-not-exist.zip', { expectToExitWithError: true });
|
||||||
|
expect(result).toContain(`Trace file i-do-not-exist.zip does not exist`);
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step('show-report', async () => {
|
||||||
|
const result = await exec('npx playwright show-report', { expectToExitWithError: true });
|
||||||
|
expect(result).toContain(`No report found at "${path.join(fs.realpathSync(tmpWorkspace), 'playwright-report')}"`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user