[BUG]: --last-failed silently drops all tests when using project dependencies
Bug description
--last-failed silently results in "No tests found" when the config uses project dependencies. Tests from dependency projects are never checked against the --last-failed filter and are excluded entirely.
Reproduction
playwright.config.ts:
export default defineConfig({
testDir: '.',
projects: [
{
name: 'default',
testIgnore: /setup/,
},
{
name: 'sequential',
testMatch: /setup/,
dependencies: ['default'],
},
],
});
Steps:
- Run tests — some in the
defaultproject fail - Run
npx playwright test --last-failed - Result:
Error: No tests found— even though.last-run.jsoncontains valid failed test IDs
Root cause
In runner/loadUtils.js, the postShardTestFilters (used by --last-failed) is applied on line 173-174, but dependency projects are only added to rootSuite later on line 179-180:
// Line 145-151: Only "top-level" projects are added to rootSuite
const projectClosure = buildProjectsClosure([...filteredProjectSuites.keys()], ...);
for (const [project, type] of projectClosure) {
if (type === "top-level") {
rootSuite._addSuite(buildProjectSuite(project, ...));
}
}
// Line 173-174: postShardTestFilters runs — but rootSuite only has top-level projects
if (config.postShardTestFilters.length)
filterTestsRemoveEmptySuites(rootSuite, (test) => config.postShardTestFilters.every((filter) => filter(test)));
// Line 177-183: Dependency projects are added AFTER the filter already ran
const projectClosure2 = new Map(buildProjectsClosure(rootSuite.suites.map(...)));
for (const [project, level] of projectClosure2.entries()) {
if (level === "dependency")
rootSuite._prependSuite(buildProjectSuite(project, projectSuites.get(project)));
}
When default is a dependency of sequential:
- Only
sequentialtests are inrootSuitewhenpostShardTestFiltersruns - The failed test IDs (from
defaultproject) don't match anysequentialtest IDs - All
sequentialtests are filtered out → "No tests found" defaultproject tests are added afterward but were never filtered — they just get added in full (but since all top-level tests were removed, the suite is empty)
Confirmed via instrumentation
Added debug logging to LastRunReporter.filterLastFailed():
[DEBUG] failedTestIds: ["44ee58bcb63fdfc96a27-8cbdbefff5ceb59d5a64", ...]
[DEBUG] no match: test.id=c540d76cbc29c39320a1-39d5ca1a35c64343e96a title=Toggle visible in header
The 44ee58bc... prefix = default project's file hash. The c540d76c... prefix = sequential project's file hash. Only sequential tests are checked; default tests are never seen by the filter.
Expected behavior
--last-failed should filter tests from ALL projects (including dependencies), not just top-level projects.
Suggested fix
Move the postShardTestFilters application to after dependency projects are added to rootSuite, or apply the filter to all project suites before the closure is built.
Version
- Playwright: 1.58.2
- OS: Windows 10
- Node.js: 24.14.0
I can take this if the team still wants it handled as a community contribution.
I noticed the earlier PR for this issue was closed because it was opened before maintainer approval/assignment, so I will not open another PR unless this is assigned or explicitly approved.
The narrow plan I would follow:
- add a runner regression where
--last-failedselects a failed test from a dependency project - keep dependency-project inclusion scoped to the last-failed filter path
- avoid changing normal dependency ordering or shard behavior outside that case
Happy to work through it if that direction matches what maintainers want.
@mturac Thank you for your interest in this one.
I am not sure what the right behavior should be. So far, playwright maintains invariant that all dependencies are running whenever a top-level test runs. If we apply --last-failed filter to the dependency project, we'll break the all part of the invariant.
It seems like we should have a better strategy here, and perhaps find the set of "last-failed" tests that are not a (possibly indirect) dependency of some other "last-failed" test, and filter to those ones. That will automatically include all dependencies after. That said, we probably need to filter projects by "last-failed" at the start, so that "default" project from the example above becomes a top-level project rather than a dependency.
Overall, this is not that straightfoward. I'd recommend to come up with some test scenarios where various subsets of dep/top-level tests fail and understand the desired behavior. Only then we can proceed to the implementation.
Thanks, that makes sense. I agree that the simple “apply --last-failed to dependency projects too” shape is not right if it means dependency projects stop running all of their tests when they are pulled in by a selected top-level project.
I’ll step back and start with behavior scenarios before touching the implementation. The matrix I’m going to validate is roughly:
-
Only a top-level project test failed
appdepends onsetup- last failed:
app/test-1 - expected: run all
setuptests, then onlyapp/test-1
-
Only a dependency project test failed
appdepends onsetup- last failed:
setup/test-1 - expected: treat
setupas the selected top-level project for this run, sosetup/test-1can run instead of producing “No tests found”
-
Both dependency and top-level tests failed
appdepends onsetup- last failed:
setup/test-1,app/test-1 - expected: select
app/test-1as the top-level failure and include allsetuptests as dependencies; do not separately filtersetupdown tosetup/test-1
-
Transitive dependencies
appdepends onseed,seeddepends onsetup- last failed only in
seed: run allsetuptests, then the failedseedtests - last failed in
setupandapp: run allsetup/seeddependency tests, then the failedapptests
-
Multiple selected top-level projects sharing a dependency
chromiumandfirefoxboth depend onsetup- last failed: one test in each browser project
- expected: run
setuponce as an unfiltered dependency, then the failed browser tests
So the rule I’ll try to encode in tests first is: choose the last-failed project/test entries that are not already covered by another selected last-failed project through the dependency graph; then let the normal dependency closure add dependencies unfiltered. If a failed test is only in what is normally a dependency project, that project can become a selected top-level project for this --last-failed run.
If this matches your expectations, I’ll turn these into focused regression tests first and only then look at the implementation shape.
@mturac Sounds like a good plan. I agree with the disposition on all the cases.
I would challenge this disposition and try to make things simpler. I would document --last-failed as only working for the top-level project.