WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@Janpot
Copy link
Member

@Janpot Janpot commented Dec 4, 2025

Makes it possible to iterate faster on this module, the goal is to thin it out and remove unnecessary wrapper APIs.

Had to make a bunch of updates as well, most notable

  • emotion wrapper is now optional and can be initialized when calling setupVitest. This allows us to make these emotion peer dependencies optional too
  • Projects will need to import setupVitest and call the function. We can't rely on module side effects because we use isolate:false and that caches modules imported by the setup script between suites
  • Updated toErrorDev to handle both sync and async functions. (There was a broken test in X relying on this)

Integrations:

@oliviertassinari oliviertassinari temporarily deployed to test-utils - mui-tools-public PR #927 December 4, 2025 11:59 — with Render Destroyed
@Janpot Janpot added the scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd). label Dec 4, 2025
@mui-bot
Copy link

mui-bot commented Dec 4, 2025

Bundle size report

Bundle Parsed size Gzip size
@base-ui-components/react 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@Janpot Janpot requested review from a team and michaldudak December 4, 2025 15:58
Copy link
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 introduces the @mui/internal-test-utils package to the code-infra repository, consolidating testing utilities to enable faster iteration and development. The package provides a comprehensive suite of test utilities including renderers, matchers, conformance testing, and helper functions for React component testing.

Key Changes

  • New test-utils package with complete TypeScript and Vitest configuration
  • Custom chai matchers for accessibility, focus, and style assertions
  • Conformance testing framework for component consistency
  • React Testing Library wrapper with enhanced functionality

Reviewed changes

Copilot reviewed 22 out of 23 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
packages/test-utils/package.json Package definition with dependencies and exports for the new test utilities
packages/test-utils/tsconfig.json TypeScript configuration for the test-utils package
packages/test-utils/tsconfig.build.json Build-specific TypeScript configuration
packages/test-utils/vitest.config.mts Vitest test configuration with jsdom environment setup
packages/test-utils/src/index.ts Main entry point exporting all test utilities
packages/test-utils/src/setupVitest.ts Vitest setup with console error/warning suppression
packages/test-utils/src/setupVitestBrowser.ts Browser environment setup with Touch API polyfill
packages/test-utils/src/initMatchers.ts Initializes chai matchers for tests
packages/test-utils/src/initMatchers.test.js Test suite for custom error/warning matchers
packages/test-utils/src/initPlaywrightMatchers.ts Playwright-specific matchers for browser testing
packages/test-utils/src/chaiPlugin.ts Custom chai assertions for accessibility and styling
packages/test-utils/src/chai.types.ts TypeScript type definitions for custom chai matchers
packages/test-utils/src/createRenderer.tsx Enhanced React Testing Library renderer with emotion cache
packages/test-utils/src/createRenderer.test.jsx Tests for the custom renderer functionality
packages/test-utils/src/createDescribe.ts Utility for creating describe blocks with skip/only support
packages/test-utils/src/describeConformance.tsx Comprehensive conformance testing framework for components
packages/test-utils/src/components.tsx Test helper components (ErrorBoundary, RenderCounter)
packages/test-utils/src/focusVisible.ts Focus management utilities for testing
packages/test-utils/src/flushMicrotasks.ts Async utility for flushing microtasks
packages/test-utils/src/fireDiscreteEvent.ts Discrete event firing utilities for React 17/18 compatibility
packages/test-utils/src/env.ts Environment detection utilities
packages/code-infra/src/eslint/material-ui/config.mjs ESLint configuration update to support .jsx extension

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 12, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 12, 2025
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Dec 15, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Dec 15, 2025
@@ -0,0 +1,20 @@
# On update, sync references where "#stable-snapshot" is mentioned in the codebase.
[stable]
baseline widely available
Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed we were shipping regenerator runtime because of a missing browserslistrc.

@brijeshb42 Would it be possible to have a more modern default when browserslistrc is missing?

Copy link
Contributor

Choose a reason for hiding this comment

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

We could add that, or fail directly asking to create a browserlistrc file if it doesn't exist. We shouldn't assume the supported browsers IMO.

Copy link
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

Copilot reviewed 23 out of 25 changed files in this pull request and generated 4 comments.

emotion: false,
};

export const config: Configuration = defaultConfig;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be readonly?

@@ -0,0 +1,13 @@
export interface Configuration {
emotion: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Should we document the usage of the prop?

Suggested change
emotion: boolean;
/**
* The emotion wrapper is optional.
* If you package uses emotion, install ... and set this to true.
*/
emotion: boolean;

skip: (...args: P) => void;
only: (...args: P) => void;
};
export default <P extends any[]>(
Copy link
Member

Choose a reason for hiding this comment

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

Can we document this function so if someone who is thinking of using it understands possible drawbacks?

I understand it is used in many places in order to hide complexity. But it makes testing errors more opaque and harder to understand.


export type ClockConfig = undefined | number | Date;

function createClock(
Copy link
Member

Choose a reason for hiding this comment

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

In X I've moved all tests that used fake clock from this implementation to the actual vi.useFakeTimers/vi.vi.setSystemTime as this was creating a lot of unnecessary errors.

Since the createRenderer is usually called once for each file, it then became a flag that changed all the tests in a file to use fake timers or not.

When used in conjunction with createDescribe, which could have a lot of tests inside, it created a mess in which some components were being tested with fake timers, while other weren't.

I would be in favour of completely removing it as there are only about 18 uses in material-ui

import * as ReactDOMServer from 'react-dom/server';
import { useFakeTimers } from 'sinon';
import { beforeEach, afterEach, beforeAll, vi } from 'vitest';
import type { EmotionCache } from '@emotion/cache';
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this causes issues if emotion is not installed?

return originalFireEventKeyUp(element, options);
};

export function fireTouchChangedEvent(
Copy link
Member

Choose a reason for hiding this comment

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

There is a lot going on on this file that could be split into different files, but we can do it in a different pass

* @param {() => void} callback
* @returns {void}
*/
function withMissingActWarningsIgnored(callback: () => void) {
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't we remove the implementation in this file altogether?


chai.use(chaiPlugin);

if (failOnConsoleEnabed) {
Copy link
Member

Choose a reason for hiding this comment

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

typo

Suggested change
if (failOnConsoleEnabed) {
if (failOnConsoleEnabled) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: code-infra Involves the code-infra product (https://www.notion.so/mui-org/5562c14178aa42af97bc1fa5114000cd).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants