Skip to content

Conversation

9aoy
Copy link
Contributor

@9aoy 9aoy commented Sep 10, 2025

Summary

support use rstest global APIs in external modules.

Related Links

Checklist

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

@Copilot Copilot AI review requested due to automatic review settings September 10, 2025 03:57
Copy link

netlify bot commented Sep 10, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit b9d7831
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/68c0f7562cbf4a000805a9a8
😎 Deploy Preview https://deploy-preview-554--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.

Copy link
Contributor

@Copilot 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 an issue where rstest global APIs weren't accessible when used in external modules (like node_modules). The fix modifies the global API registration mechanism to properly expose rstest functions globally.

  • Renamed getGlobalApi to registerGlobalApi and changed its behavior to register APIs directly on globalThis
  • Moved the global API registration to occur before context creation
  • Added comprehensive e2e tests to verify global APIs work correctly in external modules

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/core/src/runtime/worker/index.ts Modified global API registration to use globalThis and moved registration timing
e2e/runner/test/runner.test.ts Added new test case for global APIs in external modules
e2e/runner/test/fixtures/test-rstest-globals/package.json Test fixture package configuration
e2e/runner/test/fixtures/test-rstest-globals/index.js Test fixture demonstrating global API usage
e2e/runner/test/fixtures/globals.test.ts Test file that imports and uses global APIs

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +17 to 24
const registerGlobalApi = (api: Rstest) => {
return globalApis.reduce<{
[key in keyof Rstest]?: Rstest[key];
}>((apis, key) => {
apis[key] = api[key] as any;
// @ts-expect-error register to global
globalThis[key] = api[key] as any;
return apis;
}, {});
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The function returns an empty object but doesn't populate the apis accumulator. Since the function is now registering globals directly on globalThis, it should either return void or properly populate and return the apis object.

Copilot uses AI. Check for mistakes.

const rstestContext = {
global,
console: global.console,
Error,
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

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

The removal of the spread operator that conditionally included global APIs makes the code cleaner, but the context object now lacks the rstest APIs that were previously included when globals was true. Verify that this doesn't break existing functionality that relies on these APIs being available in the context.

Suggested change
Error,
Error,
...(globals ? api : {}),

Copilot uses AI. Check for mistakes.

@9aoy 9aoy merged commit 74a89c3 into main Sep 10, 2025
16 checks passed
@9aoy 9aoy deleted the global-api branch September 10, 2025 05:12
@9aoy 9aoy mentioned this pull request Sep 10, 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.

1 participant