Removed rewire from frontend unit tests#28635
Conversation
- 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
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
| 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

Why
rewireis a CommonJS-only test tool — it can't operate on ES modules — and is one of the test-side blockers for an eventualghost/coreESM 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.stubon the shared required object where the dependency is already an object —image-dimensionsstubsimageSizeCache.getCachedImageSizeFromUrldirectly. No production change._privateexport seam where the dependency is a module-local object or a bare-functionrequire—templatesexposes its existing_private;canonical-urlandrss/cacheexpose a_privateholder forgetUrl/generateFeed.No
vi.mock/vi.spyOn: the unit suite uses neither, because it runs withisolate: falsewherevi.mockleaks across files.Notes
rewirestays indevDependenciesfor now; other unit + legacy files still use it and are de-rewired in later slices.Testing
test/unit/frontend/lane (139 files / 1880 tests) passes, confirming the stub-on-shared-singleton seams don't leak across files.