Skip to content

feat: support testEnvironment.options#816

Merged
9aoy merged 7 commits intomainfrom
testEnvironmentOptions
Dec 30, 2025
Merged

feat: support testEnvironment.options#816
9aoy merged 7 commits intomainfrom
testEnvironmentOptions

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Dec 30, 2025

Summary

Support pass options to the test environment via testEnvironment.options configuration. This is useful for configuring jsdom or happy-dom. For example, you can set the url for jsdom:

import { defineConfig } from '@rstest/core';

export default defineConfig({
  testEnvironment: {
    name: 'jsdom',
    options: {
      // jsdom-specific options
      url: 'https://example.com',
    },
  },
});

#813

Related Links

Checklist

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

Copilot AI review requested due to automatic review settings December 30, 2025 05:09
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 30, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit 7df3fd6
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/69536c5e5ec4b20008597c41
😎 Deploy Preview https://deploy-preview-816--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
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 adds support for passing configuration options to test environments through a new testEnvironment.options field. This enables users to configure environment-specific settings for jsdom and happy-dom, such as setting the URL or other constructor parameters.

Key changes:

  • Extended testEnvironment config to accept both a string or an object with name and options fields
  • Updated runtime worker to pass options to environment setup functions
  • Added comprehensive documentation in both English and Chinese with usage examples

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/src/types/config.ts Added EnvironmentName and EnvironmentWithOptions types to support the new configuration format
packages/core/src/types/environment.ts Minor formatting changes to interface definitions
packages/core/src/config.ts Added normalization logic to convert string-based testEnvironment to object format
packages/core/src/runtime/worker/index.ts Updated environment setup calls to pass options from configuration
packages/core/src/runtime/worker/env/jsdom.ts Modified to accept options directly instead of nested jsdom property
packages/core/src/runtime/worker/env/happyDom.ts Updated to accept options directly with default parameter handling
packages/core/src/core/plugins/external.ts Updated to access testEnvironment.name instead of string value
packages/core/src/core/plugins/basic.ts Updated to access testEnvironment.name instead of string value
website/docs/en/config/test/test-environment.mdx Added documentation for environment options feature
website/docs/zh/config/test/test-environment.mdx Added Chinese translation of environment options documentation
e2e/dom/index.test.ts Added test case for custom environment options with jsdom
e2e/dom/fixtures/test/envOptions.test.tsx New test file to verify custom URL option works correctly
e2e/dom/fixtures/rstest.envOptions.config.ts New config file demonstrating environment options usage
e2e/dom/utils.ts Updated to make testEnvironment parameter optional
Comments suppressed due to low confidence (1)

e2e/dom/index.test.ts:57

  • Test coverage for custom environment options is only added for jsdom but not for happy-dom. Consider adding a similar test for happy-dom to ensure consistent test coverage for the new feature across both environments.
describe('happy-dom', () => {
  it('should run test correctly', async () => {
    const { expectExecSuccess } = await runCli(appFilters, 'happy-dom');
    await expectExecSuccess();
  });

  it('should load node built-in modules correctly', async () => {
    const { expectExecSuccess } = await runCli('test/node', 'happy-dom');
    await expectExecSuccess();
  });

  it('should run test correctly with custom externals', async () => {
    const { expectExecSuccess } = await runCli(appFilters, 'happy-dom', {
      args: externalConfigArgs,
    });
    await expectExecSuccess();
  });

  it('should run test correctly with jest-dom', async () => {
    const { expectExecSuccess } = await runCli(jestDomFilters, 'happy-dom');
    await expectExecSuccess();
  });
});

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

9aoy and others added 6 commits December 30, 2025 13:14
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@9aoy 9aoy merged commit dfa66d0 into main Dec 30, 2025
16 checks passed
@9aoy 9aoy deleted the testEnvironmentOptions branch December 30, 2025 07:28
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