Skip to content

fix(test-runner): report Worker Cleanup step for passing tests#39746

Closed
vazidmansuri005 wants to merge 1 commit intomicrosoft:mainfrom
vazidmansuri005:fix/worker-cleanup-reporting
Closed

fix(test-runner): report Worker Cleanup step for passing tests#39746
vazidmansuri005 wants to merge 1 commit intomicrosoft:mainfrom
vazidmansuri005:fix/worker-cleanup-reporting

Conversation

@vazidmansuri005
Copy link
Contributor

@vazidmansuri005 vazidmansuri005 commented Mar 18, 2026

Fixes #38350

Problem

The Worker Cleanup step (which includes fixture teardown timing) was only reported in result.steps when a test failed. For passing tests, this data was omitted from the onTestEnd reporter callback, making it impossible for custom reporters to identify slow fixture teardowns in successful runs.

Root cause: In workerMain.ts, the Worker Cleanup step was gated behind if (this._isStopped), which is only set to true on test failure. For passing tests, fixture teardown happened later in gracefullyClose() using a fake TestInfo with no-op step callbacks — so no step data was ever reported.

Fix

Extended the condition from:

if (this._isStopped) {

to:

if (this._isStopped || !nextTest) {

When nextTest is undefined (last test in the group), the Worker Cleanup step now runs and reports timing data as part of that test's result.

Performance guard: Worker fixture teardown (teardownScope('worker')) is only performed when this._isStopped is true (worker is actually shutting down). When !nextTest triggers the cleanup on a passing test, only test-scoped fixtures and afterAll hooks are processed (both no-ops at that point). This preserves worker fixture reuse across test groups — the browser is not restarted between files.

// Only teardown worker fixtures when the worker is actually stopping.
if (this._isStopped) {
  await this._fixtureRunner.teardownScope('worker', testInfo, { type: 'teardown', slot: teardownSlot });
}

Test plan

  • Added new test: should report worker cleanup step for passing test
  • Updated existing test expectations in test-step.spec.ts to include the now-reported Worker Cleanup step
  • All 43 tests in test-step.spec.ts pass
  • reporter.spec.ts (32 pass), playwright.trace.spec.ts (45 pass), playwright.connect.spec.ts (5 pass)
  • Lint clean

Previously, the Worker Cleanup step (which includes worker-scoped
fixture teardown timing) was only reported when a test failed. This
made it impossible for custom reporters to identify slow worker
fixture teardowns in successful runs.

The fix extends the condition that triggers the Worker Cleanup step
to also run when the current test is the last in its group
(!nextTest), not just when the worker is stopping due to failure.
This ensures cleanup timing data is always available in
result.steps via the onTestEnd reporter callback.

Fixes microsoft#38350
@vazidmansuri005 vazidmansuri005 force-pushed the fix/worker-cleanup-reporting branch from 838b57f to 7180702 Compare March 18, 2026 11:45
@pavelfeldman
Copy link
Member

Looks like AI generated blob

@vazidmansuri005
Copy link
Contributor Author

Looks like AI generated blob

Hi @pavelfeldman, fair point — the test file changes looked like a bulk edit and I understand why that raised a flag.

The actual code change in workerMain.ts is small (extending if (this._isStopped) to if (this._isStopped || !nextTest) to trigger Worker Cleanup on the last test in a group). The
large number of test updates was a side effect of the new step appearing in every test's output that previously didn't include it.

Would you be open to guidance on the preferred approach here — should I resubmit with only targeted new tests and accept that existing tests need updating, or is there a better way
to structure the fix? Happy to rework it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: [Reporter API] Report "Worker Cleanup" data in successful run

2 participants