Skip to content

Fix template example sync when using --update-snapshots#231

Open
iclanton wants to merge 4 commits intoSharePoint:mainfrom
iclanton:fix-template-example-sync
Open

Fix template example sync when using --update-snapshots#231
iclanton wants to merge 4 commits intoSharePoint:mainfrom
iclanton:fix-template-example-sync

Conversation

@iclanton
Copy link
Copy Markdown
Contributor

@iclanton iclanton commented Apr 3, 2026

Description

Fixes a bug in tests/spfx-template-test where running heft test --update-snapshots did not correctly sync removed files from template output back to the examples directory.

Previously, update mode scaffolded directly into the examples directory, which meant files removed from a template were left behind as stale files. The fix scaffolds to a temp directory (same as normal mode) and then syncs the result to the examples directory — copying new/modified files and deleting files no longer produced by the template — while leaving gitignored paths (e.g. node_modules, lib) untouched.

Normal mode (without --update-snapshots) already correctly detected all three change types (added, modified, removed) via file list and content comparison; this was only a bug in update mode.

Also includes refactors: async generator for directory traversal, module-level filter constants, and Async.forEachAsync for concurrent file I/O.

How was this tested?

Modified a file in an example project and renamed a different file (covering modification, deletion, and addition). heft test failed as expected for all three change types, and heft test -u correctly restored the examples directory.

Type of change

  • Bug fix

iclanton and others added 3 commits April 3, 2026 00:25
In UPDATE_MODE, scaffold to temp dir then sync to examples: copy
new/modified files and delete removed files using the same filter
logic. Previously, scaffolding directly into the examples directory
left stale files behind when template files were removed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…el reads

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 3, 2026 15:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes snapshot update behavior in tests/spfx-template-test so that heft test --update-snapshots no longer leaves stale files behind when templates remove files, by scaffolding into a temp directory and syncing results back into examples/.

Changes:

  • Always scaffold templates into a temp output folder (instead of sometimes scaffolding directly into examples/).
  • In --update-snapshots mode, sync temp output to examples/ by copying scaffolded files and deleting files no longer produced.
  • Refactor directory traversal/comparison helpers (async generator traversal, centralized ignore filtering, concurrent I/O via Async.forEachAsync).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/spfx-template-test/src/tests/templates.test.ts Implements temp-dir scaffolding + update-mode sync logic; refactors traversal/filtering and parallelizes I/O.
tests/spfx-template-test/src/tests/constants.ts Adds PROJECT_ROOT for package-local temp output pathing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Fixes a crash when running with --update-snapshots for a template that
has no corresponding example directory yet (new template being added).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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