Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions packages/playwright-core/src/client/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type * as channels from '@protocol/channels';

export class Tracing extends ChannelOwner<channels.TracingChannel> implements api.Tracing {
private _includeSources = false;
private _additionalSources = new Set<string>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should clean it up in stop/stopChunk.

private _isLive = false;
_tracesDir: string | undefined;
private _stacksId: string | undefined;
Expand Down Expand Up @@ -58,6 +59,8 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
}

async group(name: string, options: { location?: { file: string, line?: number, column?: number } } = {}) {
if (options.location)
this._additionalSources.add(options.location.file);
await this._channel.tracingGroup({ name, location: options.location });
}

Expand Down Expand Up @@ -106,7 +109,7 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap

if (isLocal) {
const result = await this._channel.tracingStopChunk({ mode: 'entries' });
await localUtils.zip({ zipFile: filePath, entries: result.entries!, mode: 'write', stacksId: this._stacksId, includeSources: this._includeSources });
await localUtils.zip({ zipFile: filePath, entries: result.entries!, mode: 'write', stacksId: this._stacksId, includeSources: this._includeSources, additionalSources: [...this._additionalSources] });
return;
}

Expand All @@ -124,7 +127,7 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
await artifact.saveAs(filePath);
await artifact.delete();

await localUtils.zip({ zipFile: filePath, entries: [], mode: 'append', stacksId: this._stacksId, includeSources: this._includeSources });
await localUtils.zip({ zipFile: filePath, entries: [], mode: 'append', stacksId: this._stacksId, includeSources: this._includeSources, additionalSources: [...this._additionalSources] });
}

_resetStackCounter() {
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ scheme.LocalUtilsZipParams = tObject({
stacksId: tOptional(tString),
mode: tEnum(['write', 'append']),
includeSources: tBoolean,
additionalSources: tArray(tString),
});
scheme.LocalUtilsZipResult = tOptional(tObject({}));
scheme.LocalUtilsHarOpenParams = tObject({
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/localUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export async function zip(progress: Progress, stackSessions: Map<string, StackSe

// Collect sources from stacks.
if (params.includeSources) {
const sourceFiles = new Set<string>();
const sourceFiles = new Set<string>(params.additionalSources);
for (const { stack } of stackSession?.callStacks || []) {
if (!stack)
continue;
for (const { file } of stack)
sourceFiles.add(file);
}
for (const sourceFile of sourceFiles)
addFile(sourceFile, 'resources/src@' + await calculateSha1(sourceFile) + '.txt');
addFile(sourceFile, 'resources/src@' + calculateSha1(sourceFile) + '.txt');
}

if (params.mode === 'write') {
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/src/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ export type LocalUtilsZipParams = {
stacksId?: string,
mode: 'write' | 'append',
includeSources: boolean,
additionalSources: string[],
};
export type LocalUtilsZipOptions = {
stacksId?: string,
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ LocalUtils:
- write
- append
includeSources: boolean
additionalSources:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Forgot to say - make this one optional please.

type: array
items: string

harOpen:
internal: true
Expand Down
14 changes: 14 additions & 0 deletions tests/library/trace-viewer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ test('should open trace viewer on specific host', async ({ showTraceViewer }, te

test('should show tracing.group in the action list with location', async ({ runAndTrace, page, context }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/36483' });
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/39302' });

const sourceFile = test.info().outputPath('source.js');
await fs.promises.writeFile(sourceFile, 'buddy beaver');

const traceViewer = await test.step('create trace with groups', async () => {
await page.context().tracing.group('ignored group');
Expand All @@ -125,15 +129,21 @@ test('should show tracing.group in the action list with location', async ({ runA
await context.tracing.group('inner group 2');
await expect(page.getByText('Hello')).toBeVisible();
await context.tracing.groupEnd();
await context.tracing.group('inner group 3', { location: { file: sourceFile, line: 1, column: 1 } });
await expect(page.getByText('Hello')).toBeVisible();
await context.tracing.groupEnd();
await context.tracing.groupEnd();
});
});

await fs.promises.rm(sourceFile);

await expect(traceViewer.actionTitles).toHaveText([
/outer group/,
/Navigate/,
/inner group 1 {{ eager_beaver }}/,
/inner group 2/,
/inner group 3/,
/toBeVisible/,
]);

Expand All @@ -145,12 +155,16 @@ test('should show tracing.group in the action list with location', async ({ runA
/inner group 1 {{ eager_beaver }}/,
/Click.*locator/,
/inner group 2/,
/inner group 3/,
]);
await traceViewer.showSourceTab();
await expect(traceViewer.sourceCodeTab.locator('.source-line-running')).toHaveText(/DO NOT TOUCH THIS LINE/);

await traceViewer.selectAction('inner group 2');
await expect(traceViewer.sourceCodeTab.locator('.source-line-running')).toContainText("await context.tracing.group('inner group 2');");

await traceViewer.selectAction('inner group 3');
await expect(traceViewer.sourceCodeTab.locator('.source-line-running')).toContainText('buddy beaver');
});

test('should open simple trace viewer', async ({ showTraceViewer }) => {
Expand Down
Loading