Skip to content

fix: shim require in rstest bundle#440

Merged
9aoy merged 5 commits intomainfrom
shim-require
Aug 5, 2025
Merged

fix: shim require in rstest bundle#440
9aoy merged 5 commits intomainfrom
shim-require

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Aug 4, 2025

Summary

shim require in rstest bundle. fix require is not defined error when fake timers.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings August 4, 2025 08:57
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 a "require is not defined" error when using mock fake timers with Node.js modules by enabling the require shim in the rstest bundle configuration.

  • Adds require shim configuration to enable CommonJS require in ES modules
  • Adds test case to verify fake timers work with node:timers module

Reviewed Changes

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

File Description
packages/core/rslib.config.ts Enables require shim in ESM bundle configuration
tests/fakeTimers/index.test.ts Adds test case using require('node:timers') to verify the fix

const cb = rstest.fn();
const cb1 = rstest.fn();
setTimeout(cb, 100);
setTimeout(cb1, 200);
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

[nitpick] Using require() in a TypeScript test file is inconsistent with the ES module pattern used elsewhere. Consider using import { setTimeout } from 'node:timers' instead, or add a comment explaining why require() is specifically needed for this test case.

Suggested change
setTimeout(cb1, 200);
const cb = rstest.fn();
const cb1 = rstest.fn();
nodeSetTimeout(cb, 100);
nodeSetTimeout(cb1, 200);

Copilot uses AI. Check for mistakes.
@netlify
Copy link
Copy Markdown

netlify bot commented Aug 4, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit b16da61
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/6890a3fcbcb76f0008ea5b6b
😎 Deploy Preview https://deploy-preview-440--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@9aoy 9aoy merged commit 071bb71 into main Aug 5, 2025
16 checks passed
@9aoy 9aoy deleted the shim-require branch August 5, 2025 03:12
@9aoy 9aoy mentioned this pull request Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants