fix(trace viewer): updating default traceStorageDir value (#4962)

fix(trace viewer): updating default traceStorageDir value

When `npx playwright show-trace <tracePath>` command is executed, without providing the `resources` optional parameter, the function expected the `traceStorageDir` default value to be the same directory as in which the tracePath resides. This change updates it to the `dirname(tracePath)/trace-resources` if it exists. Such a directory hirerachy is the default that is created when running the tracer in Playwright.
This commit is contained in:
Dominik Deren 2021-01-11 22:36:35 +01:00 committed by GitHub
parent 56f012043b
commit bf64fedd88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -137,15 +137,13 @@ export async function showTraceViewer(traceStorageDir: string | undefined, trace
if (!fs.existsSync(tracePath)) if (!fs.existsSync(tracePath))
throw new Error(`${tracePath} does not exist`); throw new Error(`${tracePath} does not exist`);
let files: string[]; const files: string[] = fs.statSync(tracePath).isFile() ? [tracePath] : collectFiles(tracePath);
if (fs.statSync(tracePath).isFile()) {
files = [tracePath]; if (!traceStorageDir) {
if (!traceStorageDir) traceStorageDir = fs.statSync(tracePath).isFile() ? path.dirname(tracePath) : tracePath;
traceStorageDir = path.dirname(tracePath);
} else { if (fs.existsSync(traceStorageDir + '/trace-resources'))
files = collectFiles(tracePath); traceStorageDir = traceStorageDir + '/trace-resources';
if (!traceStorageDir)
traceStorageDir = tracePath;
} }
const traceViewer = new TraceViewer(traceStorageDir); const traceViewer = new TraceViewer(traceStorageDir);