feat(test-runner): Prevent loading files not in --test-list#39743
feat(test-runner): Prevent loading files not in --test-list#39743dany-mns wants to merge 1 commit intomicrosoft:mainfrom
Conversation
|
@dany-mns please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
|
@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. |
Summary
This PR modifies
--test-listto 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:testMatchpatternThis 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:testMatchwith only the files referenced in the listFiles 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:
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:
Solution
By restricting file loading to only test-list files, the test runner:
Technical Implementation
loadTestList()to expose the unique file list (1 line added inloadUtils.ts)runTests()to replaceproject.testMatchwhen--test-listis provided (4 lines added inprogram.ts)Test Coverage
Added new test:
--test-list should not load files not in the listFiles Changed
packages/playwright/src/runner/loadUtils.ts- Added.filesproperty toloadTestListreturn valuepackages/playwright/src/program.ts- Use files list to restricttestMatchtests/playwright-test/test-list.spec.ts- Added test for file loading restriction