Skip to content

feat(core): support custom test environments#1287

Open
9aoy wants to merge 5 commits into
mainfrom
feat/custom-test-environment
Open

feat(core): support custom test environments#1287
9aoy wants to merge 5 commits into
mainfrom
feat/custom-test-environment

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented May 20, 2026

Summary

This PR adds config-level custom test environment support to @rstest/core, so projects are no longer limited to the built-in node, jsdom, and happy-dom environments. It allows loading environment objects from local JavaScript files or rstest-environment-* packages, exports builtinEnvironments and TestEnvironment types for user extension, clarifies when to use custom environments versus setupFiles, and adds unit and e2e coverage for builtin wrappers, named exports, and package fallback resolution.

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

/** @type {import('@rstest/core').TestEnvironment<typeof globalThis, { marker: string }>} */
const environment = {
  name: 'custom-jsdom',
  async setup(global, options) {
    const base = await builtinEnvironments.jsdom.setup(global, {
      url: 'https://example.com',
    });

    global.__MARKER__ = options.marker;

    return {
      async teardown() {
        delete global.__MARKER__;
        await base.teardown();
      },
    };
  },
};

export default environment;
import { defineConfig } from '@rstest/core';

export default defineConfig({
  testEnvironment: {
    name: './my-environment.mjs',
    options: {
      marker: 'custom-marker',
    },
  },
});

Checklist

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

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44254466e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/runtime/worker/testEnvironment.ts Outdated
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 20, 2026

Rsdoctor Bundle Diff Analysis

Found 12 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 3.7 KB 0
adapter-rslib 24.7 KB 0
adapter-rspack 7.8 KB 0
browser 2.0 MB 0
browser-react 3.7 KB 0
browser-ui 810.6 KB 0
coverage-istanbul 9.6 KB 0
core/browser 970.1 KB 0
core/loaders 869.0 B 0
core/main 1.7 MB +2.5 KB (0.1%)
vscode/extension 26.9 MB 0
vscode/worker 14.4 KB 0
📋 Detailed Reports (Click to expand)

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: 7938535556 | PR: #1286

Metric Current Baseline Change
📊 Total Size 1.7 MB 1.7 MB +2.5 KB (0.1%)
📄 JavaScript 1.6 MB 1.6 MB +2.5 KB (0.2%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 81.6 KB 81.6 KB 0

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 20, 2026

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1fa7ba8
Status: ✅  Deploy successful!
Preview URL: https://01f64faf.rstest.pages.dev
Branch Preview URL: https://feat-custom-test-environment.rstest.pages.dev

View logs

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1fa7ba855e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/types/config.ts
Comment thread packages/core/src/runtime/worker/testEnvironment.ts Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d76a0cdf02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/core/src/runtime/worker/testEnvironment.ts Outdated
Comment thread e2e/dom/fixtures/rstest.packageEnvironment.config.mts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant