Skip to content

feat(test-runner): Prevent loading files not in --test-list - #39743

Closed
danym (dany-mns) wants to merge 1 commit into
microsoft:mainfrom
dany-mns:feat/test-list-only-specified-files
Closed

danym (dany-mns) wants to merge 1 commit into
microsoft:mainfrom
dany-mns:feat/test-list-only-specified-files

Conversation

@dany-mns

Copy link
Copy Markdown

Summary

This PR modifies --test-list to restrict file loading to only the files referenced in the test list, preventing Playwright from loading and evaluating files that aren't part of the current test run.

Before this change

When using --test-list, Playwright would:

  1. Load ALL files matching testMatch pattern
  2. Evaluate all test files (executing top-level code)
  3. Filter which tests to run based on the test list

This caused crashes when test files not in the list had syntax errors, missing dependencies, or used deprecated APIs (e.g., bare describe() from v1 syntax).

After this change

When using --test-list, Playwright now:

  1. Reads the test list file early
  2. Replaces testMatch with only the files referenced in the list
  3. Loads ONLY those files
  4. Filters which tests to run within those files

Files not referenced in the test list are never loaded or evaluated.

Motivation

Problem: Crashes from unrelated broken files

In large monorepos with thousands of tests, it's common to have:

  • Legacy test files being migrated (e.g., v1 → v2 syntax)
  • Experimental tests with missing dependencies
  • Archived tests with deprecated APIs

When running a subset of tests via --test-list, these unrelated broken files would cause the entire test run to crash during file loading, even though they weren't being tested.

Example crash scenario:

# test-list.txt contains only:
tests/good/feature-a.spec.ts

# But broken file exists:
tests/archived/old-test.spec.ts
  describe('broken', () => { ... })  # ❌ v1 syntax crashes v2 runner

# Result: Entire run crashes with "describe is not defined"

Solution

By restricting file loading to only test-list files, the test runner:

  • ✅ Ignores broken files outside the test list
  • ✅ Runs faster (loads fewer files)
  • ✅ Enables gradual migration workflows
  • ✅ Allows archiving broken tests without blocking CI

Technical Implementation

  • Modified loadTestList() to expose the unique file list (1 line added in loadUtils.ts)
  • Modified runTests() to replace project.testMatch when --test-list is provided (4 lines added in program.ts)
  • No changes to existing callers (backward compatible)

Test Coverage

Added new test: --test-list should not load files not in the list

  • Verifies files with invalid syntax are not loaded when not in test-list
  • All 11 test-list tests passing

Files Changed

  • packages/playwright/src/runner/loadUtils.ts - Added .files property to loadTestList return value
  • packages/playwright/src/program.ts - Use files list to restrict testMatch
  • tests/playwright-test/test-list.spec.ts - Added test for file loading restriction

@dgozman

Copy link
Copy Markdown
Collaborator

danym (@dany-mns) Thank you for the PR! I don't think this is the right implementation for the feature - we should not load test list twice, and we should account for test list files somewhere in the loadUtils instead of overwriting testMatch. Also, please file an issue before sending a PR, according to the contributing guide.

@dgozman

Copy link
Copy Markdown
Collaborator

Closing as stale. See also #39901.

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.

3 participants