Skip to content

Removed rewire from frontend unit tests#28635

Closed
9larsons wants to merge 1 commit into
mainfrom
esm-prep/derewire-frontend-tests
Closed

Removed rewire from frontend unit tests#28635
9larsons wants to merge 1 commit into
mainfrom
esm-prep/derewire-frontend-tests

Conversation

@9larsons

Copy link
Copy Markdown
Contributor

Why

rewire is a CommonJS-only test tool — it can't operate on ES modules — and is one of the test-side blockers for an eventual ghost/core ESM migration. This is the first slice of removing it from the unit suite.

What

De-rewires 4 frontend unit tests, replacing rewire's __get__/__set__ with idiomatic alternatives:

  • sinon.stub on the shared required object where the dependency is already an object — image-dimensions stubs imageSizeCache.getCachedImageSizeFromUrl directly. No production change.
  • a small _private export seam where the dependency is a module-local object or a bare-function requiretemplates exposes its existing _private; canonical-url and rss/cache expose a _private holder for getUrl / generateFeed.

No vi.mock / vi.spyOn: the unit suite uses neither, because it runs with isolate: false where vi.mock leaks across files.

Notes

  • No test behaviour changes — all assertions preserved.
  • rewire stays in devDependencies for now; other unit + legacy files still use it and are de-rewired in later slices.

Testing

  • The 4 files pass under Vitest.
  • The full test/unit/frontend/ lane (139 files / 1880 tests) passes, confirming the stub-on-shared-singleton seams don't leak across files.

- rewire blocks the ESM migration and is unused elsewhere in the unit suite, which runs with isolate: false where rewire's per-file module copies don't compose
- replaced __get__/__set__ with sinon stubs on shared objects plus tiny export-for-injection seams (templates _private export, canonical-url module.exports.getUrl, rss/cache module.exports.generateFeed); image-dimensions stubs the existing cachedImageSizeFromUrl singleton with no production change
- seams are behavior-preserving: same modules are required, just routed through module.exports so sinon can stub them
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 25fa604c-0d18-4ca3-8e74-fde13891cc6d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch esm-prep/derewire-frontend-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 16, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit dae05f7

Command Status Duration Result
nx run ghost:test:ci:integration:no-coverage ✅ Succeeded 1m 49s View ↗
nx run ghost:test:ci:integration ✅ Succeeded 1m 9s View ↗
nx run ghost:test:ci:e2e:no-coverage ✅ Succeeded 3m 54s View ↗
nx run ghost:test:ci:e2e ✅ Succeeded 3m 51s View ↗
nx run ghost:test:ci:legacy ✅ Succeeded 2m 18s View ↗
nx build @tryghost/announcement-bar ✅ Succeeded <1s View ↗
nx build @tryghost/portal ✅ Succeeded <1s View ↗
nx build @tryghost/signup-form ✅ Succeeded <1s View ↗
Additional runs (10) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-16 17:11:38 UTC

@9larsons 9larsons closed this Jun 17, 2026
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.

1 participant