mirror of
https://github.com/oven-sh/bun
synced 2026-02-13 20:39:05 +00:00
Previously, mock.restore() only reset function spies (spyOn) but had no effect on modules mocked with mock.module(). This was because mock.restore() only called JSMock__resetSpies(), which never touched the virtualModules map or reversed overrideExportValue patches on ESM namespace objects. The fix adds snapshot/restore logic to JSModuleMock: - Before patching ESM exports, snapshot original values into a plain JSObject using WriteBarrier on the existing GC-managed JSModuleMock - On mock.restore(), iterate virtualModules, restore original export values via overrideExportValue, and clear the mock entries - Preserve true originals across re-mocks of the same specifier Key discovery: JSModuleNamespaceObject::getOwnPropertyNames() returns 0 exports for Bun's synthetic namespace objects (empty m_names). The fix uses the mock result object's property names to determine which exports to snapshot from the namespace. Closes #7823