fix: skip PlaywrightCheck constructs during pw-test [RED-155]#1223
fix: skip PlaywrightCheck constructs during pw-test [RED-155]#1223miliberlin wants to merge 5 commits intomainfrom
Conversation
…RED-155] When pw-test runs, PlaywrightCheck constructs defined in .check.ts files should not be loaded — they interfere with the ad-hoc Playwright test run by adding a second check and clobbering dependency resolution. Two changes in parseProject() when currentCommand === 'pw-test': 1. Filter PlaywrightCheck instances from checklyConfigConstructs 2. Skip loadAllCheckFiles() entirely Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
466f8ed to
ac421b0
Compare
…-hoc check creation Since loadAllCheckFiles() is now skipped for pw-test, the test fixture needs playwrightConfigPath in the config so loadPlaywrightChecks() creates the ad-hoc PlaywrightCheck that triggers the webServer validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Summary of why we need to tweak the config for this test below. I think this is correct since this is how a user would set up the project, but please double-check.
Before our fix, the webServer test worked like this:
- parseProject() runs with --emulate-pw-test
- loadAllCheckFiles() picks up test.check.ts, which calls new PlaywrightCheck(...) with playwrightConfigPath: './playwright.config.ts'
- The PlaywrightCheck constructor runs validateWebServerConfig(), sees webServer in the playwright config, and emits the warning
Our fix adds if (currentCommand !== 'pw-test') around loadAllCheckFiles(), so step 2 never happens — test.check.ts is never loaded, no PlaywrightCheck is created, no warning fires.
But there's a second code path that creates PlaywrightCheck instances: loadPlaywrightChecks(). This function still runs for pw-test. It creates an "ad-hoc" PlaywrightCheck when playwrightConfigPath is set in the checkly config — this is the same path that real users hit when they have checks: { playwrightConfigPath: './playwright.config.ts' } in their checkly.config.ts.
By adding playwrightConfigPath to the fixture's config, the ad-hoc check gets created via loadPlaywrightChecks() instead of via loadAllCheckFiles(). The webServer validation fires on this ad-hoc check, and the test passes.
This also makes the test more realistic — in practice, pw-test users always have playwrightConfigPath in their config (that's how pw-test knows which playwright config to use). The old fixture relied on a .check.ts file to create the PlaywrightCheck, which is exactly the scenario our fix is designed to skip.
|
@ferrandiaz would you have time to check this today? We'd like to close the Polish pw-test project soonish. |
| const ignoreDirectories = ['**/node_modules/**', '**/.git/**', ...ignoreDirectoriesMatch] | ||
|
|
||
| await loadAllCheckFiles(directory, checkMatch, ignoreDirectories) | ||
| if (currentCommand !== 'pw-test') { |
There was a problem hiding this comment.
I don't like this currentCommand thing, especially now that it's being used more. It feels like we're just adding a whole bunch of special cases based on the identity of the caller, which is IMO unpredictable and just ass in general. Instead of the caller identifying itself, it should request specific behavior via a relevant flag.
Maybe we can keep this as is if you need this out soon but I do NOT want to see this become a standard.
There was a problem hiding this comment.
@sorccu I gave replacing currentCommand a shot. Wdyt? The name of the flags can probably be improved, but I think as long as currentCommand exists it will be picked up again and again, better to get it out of the codebase if you don't like it.
Replace caller-identity branching (currentCommand === 'pw-test') with explicit flags: ignoreCheckDefinitions and skipWebServerValidation. Remove Session.currentCommand and Session.includeFlagProvided. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Positive flag name better conveys intent: warn users about webServer config needing additional files when --include isn't provided. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…discovery Consolidate two flags (skipCheckFileLoading, filterPlaywrightFromConfig) into loadPlaywrightChecksOnly. Also skip browser and multi-step check loading under this flag since they get filtered out anyway. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Background
Reported internally by Stefan: when a project has a
PlaywrightCheckconstruct defined in a.check.tsfile,pw-testincorrectly includes it alongside the vanilla Playwright tests. This causespw-testto run two checks — the construct-based check and the ad-hoc one — when it should only run the ad-hoc one:The construct-based check passes (self-contained config/deps), but the ad-hoc
playwright.config.tscheck fails because the construct's bundling context clobbers its dependency resolution.Root cause
parseProject()was not scoped to thepw-testcommand:loadAllCheckFiles()ran for all commands includingpw-test, picking up.check.tsfiles that containnew PlaywrightCheck(...)constructschecklyConfigConstructs(from config file evaluation) were added to the project unfiltered, even forpw-testThis meant
pw-testwould end up with extra PlaywrightCheck instances in the project. Since thecheckFilterkeeps allPlaywrightCheckinstances, both the construct-based check and the ad-hoc check made it into the bundle. The construct's dependency tree interfered with the ad-hoc check's bundling.Changes
Two changes in
parseProject()whencurrentCommand === 'pw-test':checklyConfigConstructsbefore adding to the projectloadAllCheckFiles()entirelyBefore/after (released CLI v7.0.1 vs this fix)
Before:
After:
Test results
Each test project includes a
PlaywrightCheckconstruct in a.check.tsfile, a local project dependency (src/utils/selectors.ts), and an npm devDependency (lodash). The test files import both to verify dependency resolution works correctly..check.tsfileAll three child issues verified fixed. The released CLI (v7.0.1) consistently runs 2 checks (the bug), while the fix correctly runs only 1 ad-hoc check. Both local and npm dependencies resolve correctly with the fix.
Before sessions: RED-122 · RED-119 · RED-118
After sessions: RED-122 · RED-119 · RED-118
🤖 Generated with Claude Code