Skip to content

Commit b06237b

Browse files
test: add coverage for __non_webpack_require__ branch
Adds a test that simulates a webpack environment by defining __non_webpack_require__ globally, ensuring the branch that uses webpack's native require bypass is covered. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6927c50 commit b06237b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test/timezone_test.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,3 +761,31 @@ describe("Timezone fallback behavior (when date-fns-tz is not installed)", () =>
761761
consoleSpy.mockRestore();
762762
});
763763
});
764+
765+
describe("Webpack __non_webpack_require__ support", () => {
766+
beforeEach(() => {
767+
__resetDateFnsTzCache();
768+
});
769+
770+
afterEach(() => {
771+
// Clean up the global
772+
// @ts-expect-error - cleaning up test global
773+
delete globalThis.__non_webpack_require__;
774+
__resetDateFnsTzCache();
775+
});
776+
777+
it("should use __non_webpack_require__ when available in webpack environment", () => {
778+
const testDate = new Date("2024-06-15T12:00:00Z");
779+
780+
// Simulate webpack environment by defining __non_webpack_require__
781+
// @ts-expect-error - simulating webpack global
782+
globalThis.__non_webpack_require__ = require;
783+
784+
// This should use __non_webpack_require__ and successfully load date-fns-tz
785+
const result = toZonedTime(testDate, "America/New_York");
786+
787+
// Should convert the date (not return original), proving date-fns-tz loaded
788+
expect(result).toBeInstanceOf(Date);
789+
expect(result.getHours()).toBe(8); // 12:00 UTC = 08:00 EDT
790+
});
791+
});

0 commit comments

Comments
 (0)