Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Split the test package #39061

Merged
merged 7 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 0 additions & 9 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,6 @@ module.exports = {
rules: {
// does not work with wildcard imports. Mistakes will throw at runtime anyway
'import/named': 'off',
'no-restricted-imports': [
Copy link
Member Author

Choose a reason for hiding this comment

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

No need to do this anymore as package.json's export field controls visibility of exports.

Copy link
Member

Choose a reason for hiding this comment

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

Which linting process is now controlling this? The typescript type checker?

Copy link
Member Author

Choose a reason for hiding this comment

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

Node doesn't allow importing arbitrary files from the package when any subpath exports are defined.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, 👍 that assumes there is at least one Node.js process importing this natively

'error',
{
// Use named import from `test/utils` instead.
// The other files are private.
patterns: ['test/utils/*'],
},
],

'material-ui/disallow-active-element-as-key-event-target': 'error',

// upgraded level from recommended
Expand Down
5 changes: 4 additions & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ module.exports = {
recursive: true,
timeout: (process.env.CIRCLECI === 'true' ? 5 : 2) * 1000, // Circle CI has low-performance CPUs.
reporter: 'dot',
require: [require.resolve('./test/utils/setupBabel'), require.resolve('./test/utils/setupJSDOM')],
require: [
require.resolve('@mui-internal/test-utilities/setupBabel'),
require.resolve('@mui-internal/test-utilities/setupJSDOM'),
],
'watch-ignore': [
// default
'.git',
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@babel/plugin-transform-react-constant-elements": "^7.22.5",
"@babel/preset-typescript": "^7.22.15",
"@mui-internal/docs-utilities": "^1.0.0",
"@mui-internal/test-utilities": "^1.0.0",
"@types/autosuggest-highlight": "^3.2.0",
"@types/chai": "^4.3.5",
"@types/css-mediaquery": "^0.1.2",
Expand All @@ -140,7 +141,6 @@
"playwright": "^1.37.1",
"prettier": "^2.8.8",
"tailwindcss": "^3.3.3",
"test": "5.0.0",
"typescript-to-proptypes": "^5.0.0",
"yargs": "^17.7.2"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/HighlightedCode.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer } from 'test/utils';
import { createRenderer } from '@mui-internal/test-utilities';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import { getDesignTokens } from 'docs/src/modules/brandingTheme';
import HighlightedCode from 'docs/src/modules/components/HighlightedCode';
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
"start": "yarn && yarn docs:dev",
"t": "node test/cli.js",
"test": "yarn eslint && yarn typescript && yarn test:coverage",
"test:coverage": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=text mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}' 'test/utils/**/*.test.{js,ts,tsx}'",
"test:coverage:ci": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=lcov mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}' 'test/utils/**/*.test.{js,ts,tsx}'",
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=html mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}' 'test/utils/**/*.test.{js,ts,tsx}'",
"test:coverage": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=text mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
"test:coverage:ci": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=lcov mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc --reporter=html mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
"test:e2e": "cross-env NODE_ENV=production yarn test:e2e:build && concurrently --success first --kill-others \"yarn test:e2e:run\" \"yarn test:e2e:server\"",
"test:e2e:build": "webpack --config test/e2e/webpack.config.js",
"test:e2e:dev": "concurrently \"yarn test:e2e:build --watch\" \"yarn test:e2e:server\"",
Expand All @@ -66,7 +66,7 @@
"test:regressions:run": "mocha --config test/regressions/.mocharc.js --delay 'test/regressions/**/*.test.js'",
"test:regressions:server": "serve test/regressions -p 5001",
"test:umd": "node packages/mui-material/test/umd/run.js",
"test:unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}' 'test/utils/**/*.test.{js,ts,tsx}'",
"test:unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.{js,ts,tsx}' 'docs/**/*.test.{js,ts,tsx}'",
"test:argos": "node ./scripts/pushArgos.mjs",
"typescript": "lerna run --no-bail --parallel typescript",
"typescript:ci": "lerna run --concurrency 5 --no-bail --no-sort typescript",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ const ruleTester = new eslint.RuleTester({
});
ruleTester.run('disallow-active-element-as-key-event-target', rule, {
valid: [
"import { fireEvent } from 'test/utils';\nfireEvent.keyDown(getByRole('button'), { key: ' ' })",
"import { fireEvent } from 'test/utils';\nfireEvent.keyDown(document.body, { key: 'Esc' })",
"import { fireEvent } from 'test/utils';\nfireEvent.keyUp(document.body, { key: 'Tab' })",
"import { fireEvent } from '@mui-internal/test-utilities';\nfireEvent.keyDown(getByRole('button'), { key: ' ' })",
"import { fireEvent } from '@mui-internal/test-utilities';\nfireEvent.keyDown(document.body, { key: 'Esc' })",
"import { fireEvent } from '@mui-internal/test-utilities';\nfireEvent.keyUp(document.body, { key: 'Tab' })",
],
invalid: [
{
code: "import { fireEvent } from 'test/utils';\nfireEvent.keyUp(document.activeElement, { key: 'LeftArrow' })",
code: "import { fireEvent } from '@mui-internal/test-utilities';\nfireEvent.keyUp(document.activeElement, { key: 'LeftArrow' })",
errors: [
{
message:
Expand All @@ -23,7 +23,7 @@ ruleTester.run('disallow-active-element-as-key-event-target', rule, {
],
},
{
code: "import { fireEvent } from 'test/utils';\nfireEvent.keyDown(document.activeElement, { key: 'DownArrow' })",
code: "import { fireEvent } from '@mui-internal/test-utilities';\nfireEvent.keyDown(document.activeElement, { key: 'DownArrow' })",
errors: [
{
message:
Expand Down Expand Up @@ -54,7 +54,7 @@ ruleTester.run('disallow-active-element-as-key-event-target', rule, {
},
{
// test non-null assertion operator
code: "import { fireEvent } from 'test/utils';\nfireEvent.keyUp(document.activeElement!, { key: 'LeftArrow' })",
code: "import { fireEvent } from '@mui-internal/test-utilities';\nfireEvent.keyUp(document.activeElement!, { key: 'LeftArrow' })",
errors: [
{
message:
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
},
"devDependencies": {
"@mui/material": "^5.14.10",
"@mui-internal/test-utilities": "^1.0.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/chai": "^4.3.5",
Expand All @@ -63,8 +64,7 @@
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sinon": "^15.2.0",
"test": "^5.0.0"
"sinon": "^15.2.0"
},
"peerDependencies": {
"@types/react": "^17.0.0 || ^18.0.0",
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createRenderer, createMount, describeConformanceUnstyled } from 'test/utils';
import {
createRenderer,
createMount,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { Badge, badgeClasses as classes } from '@mui/base/Badge';

describe('<Badge />', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Button/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
createRenderer,
describeConformanceUnstyled,
fireEvent,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { expect } from 'chai';
import { spy } from 'sinon';
import { Button, buttonClasses } from '@mui/base/Button';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { expect } from 'chai';
import { spy } from 'sinon';
import { act, createRenderer, fireEvent, fireDiscreteEvent, screen } from 'test/utils';
import {
act,
createRenderer,
fireEvent,
fireDiscreteEvent,
screen,
} from '@mui-internal/test-utilities';
import { Portal } from '@mui/base/Portal';
import { ClickAwayListener } from '@mui/base/ClickAwayListener';

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Dropdown/Dropdown.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { act, createRenderer } from 'test/utils';
import { act, createRenderer } from '@mui-internal/test-utilities';
import { Dropdown } from '@mui/base/Dropdown';
import { DropdownContext } from '@mui/base/useDropdown';
import { MenuButton } from '@mui/base/MenuButton';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/FocusTrap/FocusTrap.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { expect } from 'chai';
import { act, createRenderer, screen } from 'test/utils';
import { act, createRenderer, screen } from '@mui-internal/test-utilities';
import { FocusTrap } from '@mui/base/FocusTrap';
import { Portal } from '@mui/base/Portal';

Expand Down
7 changes: 6 additions & 1 deletion packages/mui-base/src/FormControl/FormControl.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { createMount, createRenderer, describeConformanceUnstyled, fireEvent } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
fireEvent,
} from '@mui-internal/test-utilities';
import { FormControl, formControlClasses, useFormControlContext } from '@mui/base/FormControl';

describe('<FormControl />', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Input/Input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
describeConformanceUnstyled,
fireEvent,
screen,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { expect } from 'chai';
import { spy } from 'sinon';
import { Input, inputClasses } from '@mui/base/Input';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
describeConformanceUnstyled,
fireEvent,
act,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { Menu, menuClasses } from '@mui/base/Menu';
import { MenuItem } from '@mui/base/MenuItem';
import { DropdownContext, DropdownContextValue } from '@mui/base/useDropdown';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/MenuButton/MenuButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
createRenderer,
describeConformanceUnstyled,
fireEvent,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { MenuButton, menuButtonClasses } from '@mui/base/MenuButton';
import { DropdownContext, DropdownContextValue, DropdownActionTypes } from '@mui/base/useDropdown';

Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/MenuItem/MenuItem.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { MenuItem, menuItemClasses } from '@mui/base/MenuItem';
import { MenuProvider } from '@mui/base/useMenu';

Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { Modal, modalClasses as classes, ModalRootSlotProps } from '@mui/base/Modal';

describe('<Modal />', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/NoSsr/NoSsr.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer } from 'test/utils';
import { createRenderer } from '@mui-internal/test-utilities';
import { NoSsr } from '@mui/base/NoSsr';

describe('<NoSsr />', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/Option/Option.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { Option, optionClasses } from '@mui/base/Option';
import { SelectProvider } from '../useSelect/SelectProvider';

Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/OptionGroup/OptionGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { OptionGroup, optionGroupClasses } from '@mui/base/OptionGroup';

describe('<OptionGroup />', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/mui-base/src/Popper/Popper.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as React from 'react';
import { expect } from 'chai';
import { createRenderer, createMount, describeConformanceUnstyled, screen } from 'test/utils';
import {
createRenderer,
createMount,
describeConformanceUnstyled,
screen,
} from '@mui-internal/test-utilities';
import { Popper, popperClasses } from '@mui/base/Popper';

describe('<Popper />', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Portal/Portal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { createRenderer } from 'test/utils';
import { createRenderer } from '@mui-internal/test-utilities';
import { Portal, PortalProps } from '@mui/base/Portal';

describe('<Portal />', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Select/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
userEvent,
act,
screen,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { Select, SelectListboxSlotProps, selectClasses } from '@mui/base/Select';
import { useOption, SelectOption } from '@mui/base/useOption';
import { Option, OptionProps, optionClasses } from '@mui/base/Option';
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Slider/Slider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
describeConformanceUnstyled,
fireEvent,
screen,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import {
Slider,
sliderClasses as classes,
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Snackbar/Snackbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
createMount,
describeConformanceUnstyled,
fireEvent,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { Snackbar, snackbarClasses as classes } from '@mui/base/Snackbar';

describe('<Snackbar />', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/Switch/Switch.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { expect } from 'chai';
import { Switch, SwitchOwnerState, switchClasses } from '@mui/base/Switch';

Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/Tab/Tab.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { Tab, tabClasses } from '@mui/base/Tab';
import { TabsListProvider, TabsListProviderValue } from '../useTabsList';
import { TabsContext } from '../Tabs';
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/TabPanel/TabPanel.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { TabPanel, tabPanelClasses } from '@mui/base/TabPanel';
import { TabsProvider, TabsProviderValue } from '../useTabs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import PropTypes from 'prop-types';
import { describeConformanceUnstyled, fireEvent, createRenderer, createMount } from 'test/utils';
import {
describeConformanceUnstyled,
fireEvent,
createRenderer,
createMount,
} from '@mui-internal/test-utilities';
import TableFooter from '@mui/material/TableFooter';
import TableRow from '@mui/material/TableRow';
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-base/src/Tabs/Tabs.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
fireEvent,
screen,
createMount,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { Tab } from '@mui/base/Tab';
import { Tabs, tabsClasses as classes, TabsProps } from '@mui/base/Tabs';
import { TabsList } from '@mui/base/TabsList';
Expand Down
6 changes: 5 additions & 1 deletion packages/mui-base/src/TabsList/TabsList.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { createMount, createRenderer, describeConformanceUnstyled } from 'test/utils';
import {
createMount,
createRenderer,
describeConformanceUnstyled,
} from '@mui-internal/test-utilities';
import { TabsContext } from '@mui/base/Tabs';
import { TabsList, tabsListClasses } from '@mui/base/TabsList';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
createRenderer,
fireEvent,
strictModeDoubleLoggingSuppressed,
} from 'test/utils';
} from '@mui-internal/test-utilities';
import { TextareaAutosize } from '@mui/base/TextareaAutosize';

function getStyleValue(value: string) {
Expand Down
Loading