Skip to content

chore(repo): cover subdir and dependency watcher rebuilds#459

Merged
shellscape merged 4 commits into
mainfrom
charlie/smoke-v2-watcher-cases-458
Jun 4, 2026
Merged

chore(repo): cover subdir and dependency watcher rebuilds#459
shellscape merged 4 commits into
mainfrom
charlie/smoke-v2-watcher-cases-458

Conversation

@charliecreates
Copy link
Copy Markdown
Contributor

@charliecreates charliecreates Bot commented Jun 4, 2026

Summary

  • add a watcher smoke case for editing a template in a subdirectory (fixtures/templates/props/preview-props.tsx)
  • add a watcher smoke case for editing an imported dependency (fixtures/components/text.tsx) and verifying template rebuild output
  • keep watcher assertions deterministic by waiting for preview build output before validating iframe HTML

Refs #458

Greptile Summary

This PR extends the watcher smoke test with two new steps: editing a template in a subdirectory (preview-props.tsx, batmanrobin) and editing an imported dependency (text.tsx, component testcomponent test updated) to verify downstream template rebuilds. The test is refactored from a single hard-coded block into a data-driven loop over a watcherCases array, and writeFile is replaced with an open/writeFile/truncate sequence that avoids the extra bytes left over when shorter content overwrites a larger file.

  • Adds two new WatcherCase entries and loops over all three cases inside test.step, with waitForPreviewBuild providing a deterministic fence before each iframe assertion, removing the brittle reloadPreview retry loop.
  • replaceFileContents opens the file in r+ mode, writes the new content, then calls truncate(Buffer.byteLength(content, 'utf8')) to strip any trailing bytes from a shorter replacement — correctly handling both shrink and growth cases.
  • The finally block restores the original file and waits for the preview build to settle before the next step mutates a different file.

Confidence Score: 4/5

Safe to merge once the open fixture-string issue in the dependency watcher case is resolved; the rest of the refactor is well-structured.

The dependency watcher case uses beforeContent 'component test' and afterContent 'component test updated', where the before value is a strict prefix of the after value. This relationship makes the pre-condition guard, the finally settle wait, and the restore logic unreliable for that step. The two new cases are the core contribution of the PR, so this affects the test's ability to reliably verify the behaviour it was written to exercise.

test/smoke-v2/tests/smoke-v2.test.ts — specifically the beforeContent/afterContent values in the third WatcherCase entry and the corresponding fixture file fixtures/components/text.tsx.

Important Files Changed

Filename Overview
test/smoke-v2/tests/smoke-v2.test.ts Watcher test refactored into a data-driven loop over three WatcherCase entries; replaceFileContents and waitForPreviewBuild helpers added. The beforeContent/afterContent values for the dependency watcher case (case 3) are substrings of each other, leaving guards and the finally-block settle wait ineffective for that step.

Sequence Diagram

sequenceDiagram
    participant T as Test (watcher step)
    participant FS as Filesystem
    participant W as File Watcher
    participant B as Preview Build (*.js)
    participant P as Playwright Page

    T->>P: page.goto(getTemplateUrl(templateSlug))
    T->>P: assert iframe srcdoc contains beforeContent
    T->>FS: replaceFileContents(targetFile, contents.replace(before, after))
    FS-->>W: file change event
    W->>B: rebuild previewBuildFile
    T->>B: waitForPreviewBuild(previewBuildFile, afterContent) [poll 60s]
    B-->>T: afterContent found
    T->>P: assert iframe srcdoc contains afterContent (HMR update)
    Note over T,P: optional snapshot if snapshotName set
    T->>FS: replaceFileContents(targetFile, contents) [finally: restore]
    FS-->>W: file change event
    W->>B: rebuild previewBuildFile
    T->>B: waitForPreviewBuild(previewBuildFile, beforeContent) [finally: settle]
Loading

Reviews (4): Last reviewed commit: "test(smoke-v2): assert watcher updates w..." | Re-trigger Greptile

Comment thread test/smoke-v2/tests/smoke-v2.test.ts
@shellscape shellscape changed the title test(smoke-v2): cover subdir and dependency watcher rebuilds chore(repo): cover subdir and dependency watcher rebuilds Jun 4, 2026
@shellscape shellscape merged commit 1fd4745 into main Jun 4, 2026
20 of 21 checks passed
@shellscape shellscape deleted the charlie/smoke-v2-watcher-cases-458 branch June 4, 2026 20:04
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.

2 participants