Skip to content

Commit 2db5eff

Browse files
authored
chore: pass "live" flag explicitly instead of through env var (#38217)
1 parent d18d7d9 commit 2db5eff

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

packages/playwright-core/src/client/tracing.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type * as channels from '@protocol/channels';
2222

2323
export class Tracing extends ChannelOwner<channels.TracingChannel> implements api.Tracing {
2424
private _includeSources = false;
25+
private _isLive = false;
2526
_tracesDir: string | undefined;
2627
private _stacksId: string | undefined;
2728
private _isTracing = false;
@@ -37,21 +38,22 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
3738
async start(options: { name?: string, title?: string, snapshots?: boolean, screenshots?: boolean, sources?: boolean, _live?: boolean } = {}) {
3839
await this._wrapApiCall(async () => {
3940
this._includeSources = !!options.sources;
41+
this._isLive = !!options._live;
4042
await this._channel.tracingStart({
4143
name: options.name,
4244
snapshots: options.snapshots,
4345
screenshots: options.screenshots,
4446
live: options._live,
4547
});
4648
const { traceName } = await this._channel.tracingStartChunk({ name: options.name, title: options.title });
47-
await this._startCollectingStacks(traceName);
49+
await this._startCollectingStacks(traceName, this._isLive);
4850
});
4951
}
5052

5153
async startChunk(options: { name?: string, title?: string } = {}) {
5254
await this._wrapApiCall(async () => {
5355
const { traceName } = await this._channel.tracingStartChunk(options);
54-
await this._startCollectingStacks(traceName);
56+
await this._startCollectingStacks(traceName, this._isLive);
5557
});
5658
}
5759

@@ -63,12 +65,12 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap
6365
await this._channel.tracingGroupEnd();
6466
}
6567

66-
private async _startCollectingStacks(traceName: string) {
68+
private async _startCollectingStacks(traceName: string, live: boolean) {
6769
if (!this._isTracing) {
6870
this._isTracing = true;
6971
this._connection.setIsTracing(true);
7072
}
71-
const result = await this._connection.localUtils()?.tracingStarted({ tracesDir: this._tracesDir, traceName });
73+
const result = await this._connection.localUtils()?.tracingStarted({ tracesDir: this._tracesDir, traceName, live });
7274
this._stacksId = result?.stacksId;
7375
}
7476

packages/playwright-core/src/protocol/validator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ scheme.LocalUtilsConnectResult = tObject({
317317
scheme.LocalUtilsTracingStartedParams = tObject({
318318
tracesDir: tOptional(tString),
319319
traceName: tString,
320+
live: tOptional(tBoolean),
320321
});
321322
scheme.LocalUtilsTracingStartedResult = tObject({
322323
stacksId: tString,

packages/playwright-core/src/server/localUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export type StackSession = {
3838
writer: Promise<void>;
3939
tmpDir: string | undefined;
4040
callStacks: channels.ClientSideCallMetadata[];
41+
live?: boolean;
4142
};
4243

4344
export async function zip(progress: Progress, stackSessions: Map<string, StackSession>, params: channels.LocalUtilsZipParams): Promise<void> {
@@ -194,7 +195,7 @@ export async function tracingStarted(progress: Progress, stackSessions: Map<stri
194195
if (!params.tracesDir)
195196
tmpDir = await progress.race(fs.promises.mkdtemp(path.join(os.tmpdir(), 'playwright-tracing-')));
196197
const traceStacksFile = path.join(params.tracesDir || tmpDir!, params.traceName + '.stacks');
197-
stackSessions.set(traceStacksFile, { callStacks: [], file: traceStacksFile, writer: Promise.resolve(), tmpDir });
198+
stackSessions.set(traceStacksFile, { callStacks: [], file: traceStacksFile, writer: Promise.resolve(), tmpDir, live: params.live });
198199
return { stacksId: traceStacksFile };
199200
}
200201

@@ -205,7 +206,7 @@ export async function traceDiscarded(progress: Progress, stackSessions: Map<stri
205206
export function addStackToTracingNoReply(stackSessions: Map<string, StackSession>, params: channels.LocalUtilsAddStackToTracingNoReplyParams) {
206207
for (const session of stackSessions.values()) {
207208
session.callStacks.push(params.callData);
208-
if (process.env.PW_LIVE_TRACE_STACKS) {
209+
if (session.live) {
209210
session.writer = session.writer.then(() => {
210211
const buffer = Buffer.from(JSON.stringify(serializeClientSideCallMetadata(session.callStacks)));
211212
return fs.promises.writeFile(session.file, buffer);

packages/playwright/src/runner/testRunner.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,6 @@ export class TestRunner extends EventEmitter<TestRunnerEventMap> {
324324
...(params.updateSourceMethod ? { updateSourceMethod: params.updateSourceMethod } : {}),
325325
...(params.workers ? { workers: params.workers } : {}),
326326
};
327-
if (params.trace === 'on')
328-
process.env.PW_LIVE_TRACE_STACKS = '1';
329-
else
330-
process.env.PW_LIVE_TRACE_STACKS = undefined;
331327

332328
const config = await this._loadConfigOrReportError(new InternalReporter([userReporter]), overrides);
333329
if (!config)

packages/protocol/src/channels.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,9 +533,11 @@ export type LocalUtilsConnectResult = {
533533
export type LocalUtilsTracingStartedParams = {
534534
tracesDir?: string,
535535
traceName: string,
536+
live?: boolean,
536537
};
537538
export type LocalUtilsTracingStartedOptions = {
538539
tracesDir?: string,
540+
live?: boolean,
539541
};
540542
export type LocalUtilsTracingStartedResult = {
541543
stacksId: string,

packages/protocol/src/protocol.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ LocalUtils:
709709
parameters:
710710
tracesDir: string?
711711
traceName: string
712+
live: boolean?
712713
returns:
713714
stacksId: string
714715

tests/mcp/tracing.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ test('check that trace is saved with browser_start_tracing', async ({ startClien
6464
expect(files).toEqual([
6565
'resources',
6666
expect.stringMatching(/trace-\d+\.network/),
67+
expect.stringMatching(/trace-\d+\.stacks/),
6768
expect.stringMatching(/trace-\d+\.trace/),
6869
]);
6970
});
@@ -102,6 +103,7 @@ test('check that trace is saved with browser_start_tracing (no output dir)', asy
102103
expect(files).toEqual([
103104
'resources',
104105
expect.stringMatching(/trace-\d+\.network/),
106+
expect.stringMatching(/trace-\d+\.stacks/),
105107
expect.stringMatching(/trace-\d+\.trace/),
106108
]);
107109
});

0 commit comments

Comments
 (0)