From f0a0255138f7ca49d1ef270f95945823140cc61e Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 13 Jan 2019 01:14:29 +0300 Subject: [PATCH 1/3] Replace warning with tiny-warning - esm support - not stuck with mirroring facebook internals once in a year - jss v10 already migrated to it so size improvement will come in mui v4 - tiny-warning is really console.warn; red wall in console is scary --- .../modules/components/AppTableOfContents.js | 2 +- docs/src/modules/components/MarkdownDocs.js | 2 +- docs/src/modules/utils/helpers.js | 2 +- modules/waterfall/metric.js | 2 +- packages/material-ui-lab/package.json | 3 +- .../src/SpeedDial/SpeedDial.js | 2 +- packages/material-ui-styles/package.json | 2 +- .../material-ui-styles/src/StylesProvider.js | 2 +- .../material-ui-styles/src/ThemeProvider.js | 2 +- .../src/createGenerateClassName.js | 2 +- .../src/getStylesCreator.js | 2 +- .../material-ui-styles/src/indexCounter.js | 2 +- .../material-ui-styles/src/mergeClasses.js | 2 +- packages/material-ui-styles/src/withStyles.js | 2 +- packages/material-ui-system/package.json | 2 +- .../material-ui-system/src/breakpoints.js | 2 +- packages/material-ui-system/src/spacing.js | 2 +- .../material-ui-system/src/spacing.test.js | 20 ++++---- packages/material-ui/.size-snapshot.json | 6 +-- packages/material-ui/package.json | 2 +- .../src/BottomNavigation/BottomNavigation.js | 2 +- .../src/ButtonBase/focusVisible.js | 2 +- .../material-ui/src/CardMedia/CardMedia.js | 2 +- packages/material-ui/src/Chip/Chip.js | 2 +- .../src/ExpansionPanel/ExpansionPanel.js | 2 +- packages/material-ui/src/GridList/GridList.js | 2 +- packages/material-ui/src/Hidden/HiddenCss.js | 2 +- .../material-ui/src/InputBase/InputBase.js | 2 +- .../src/LinearProgress/LinearProgress.js | 2 +- .../src/LinearProgress/LinearProgress.test.js | 16 +++---- packages/material-ui/src/MenuList/MenuList.js | 2 +- packages/material-ui/src/Modal/Modal.js | 2 +- packages/material-ui/src/Modal/Modal.test.js | 10 ++-- packages/material-ui/src/Paper/Paper.js | 2 +- packages/material-ui/src/Popover/Popover.js | 2 +- .../material-ui/src/RadioGroup/RadioGroup.js | 2 +- .../material-ui/src/Select/SelectInput.js | 2 +- packages/material-ui/src/Step/Step.js | 2 +- .../src/StepContent/StepContent.js | 2 +- packages/material-ui/src/Tabs/Tabs.js | 2 +- packages/material-ui/src/Tabs/Tabs.test.js | 16 +++---- .../material-ui/src/TextField/TextField.js | 2 +- packages/material-ui/src/Tooltip/Tooltip.js | 2 +- .../material-ui/src/Tooltip/Tooltip.test.js | 12 ++--- .../src/styles/MuiThemeProvider.js | 2 +- .../src/styles/colorManipulator.js | 2 +- .../src/styles/colorManipulator.test.js | 14 +++--- .../src/styles/createGenerateClassName.js | 2 +- .../material-ui/src/styles/createMuiTheme.js | 2 +- .../src/styles/createMuiTheme.test.js | 14 +++--- .../material-ui/src/styles/createPalette.js | 2 +- .../src/styles/createPalette.test.js | 12 ++--- .../src/styles/createTypography.js | 2 +- .../src/styles/createTypography.test.js | 12 ++--- .../src/styles/getStylesCreator.js | 2 +- .../src/styles/getStylesCreator.test.js | 10 ++-- .../material-ui/src/styles/mergeClasses.js | 2 +- .../material-ui/src/styles/transitions.js | 2 +- .../src/styles/transitions.test.js | 36 +++++++------- packages/material-ui/src/styles/withStyles.js | 2 +- .../material-ui/src/styles/withStyles.test.js | 18 +++---- packages/material-ui/src/utils/helpers.js | 2 +- test/utils/consoleWarnMock.js | 48 +++++++++++++++++++ test/utils/consoleWarnMock.test.js | 38 +++++++++++++++ yarn.lock | 23 ++++++--- 65 files changed, 251 insertions(+), 153 deletions(-) create mode 100644 test/utils/consoleWarnMock.js create mode 100644 test/utils/consoleWarnMock.test.js diff --git a/docs/src/modules/components/AppTableOfContents.js b/docs/src/modules/components/AppTableOfContents.js index cf2ef3f4a2ce81..2335138e235d20 100644 --- a/docs/src/modules/components/AppTableOfContents.js +++ b/docs/src/modules/components/AppTableOfContents.js @@ -3,7 +3,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import marked from 'marked'; -import warning from 'warning'; +import warning from 'tiny-warning'; import throttle from 'lodash/throttle'; import EventListener from 'react-event-listener'; import { withStyles } from '@material-ui/core/styles'; diff --git a/docs/src/modules/components/MarkdownDocs.js b/docs/src/modules/components/MarkdownDocs.js index 8379ebe3a853af..dec7b97512d50a 100644 --- a/docs/src/modules/components/MarkdownDocs.js +++ b/docs/src/modules/components/MarkdownDocs.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { connect } from 'react-redux'; import compose from 'recompose/compose'; import { withStyles } from '@material-ui/core/styles'; diff --git a/docs/src/modules/utils/helpers.js b/docs/src/modules/utils/helpers.js index 7c8d4004855d82..a5ff3fa452d819 100644 --- a/docs/src/modules/utils/helpers.js +++ b/docs/src/modules/utils/helpers.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import upperFirst from 'lodash/upperFirst'; import camelCase from 'lodash/camelCase'; diff --git a/modules/waterfall/metric.js b/modules/waterfall/metric.js index c01482242b98e9..5bdd6b9db61b16 100644 --- a/modules/waterfall/metric.js +++ b/modules/waterfall/metric.js @@ -1,6 +1,6 @@ // The API is inspired by console.time // The implementation is isomorphic. -import warning from 'warning'; +import warning from 'tiny-warning'; const times = new Map(); diff --git a/packages/material-ui-lab/package.json b/packages/material-ui-lab/package.json index eb8c8d7f93b4ab..c17e75a27f271e 100644 --- a/packages/material-ui-lab/package.json +++ b/packages/material-ui-lab/package.json @@ -42,7 +42,8 @@ "@material-ui/utils": "^3.0.0-alpha.2", "classnames": "^2.2.5", "keycode": "^2.1.9", - "prop-types": "^15.6.0" + "prop-types": "^15.6.0", + "tiny-warning": "^1.0.2" }, "devDependencies": {}, "sideEffects": false, diff --git a/packages/material-ui-lab/src/SpeedDial/SpeedDial.js b/packages/material-ui-lab/src/SpeedDial/SpeedDial.js index 7878c6a9d4090f..a0fa8858800ccb 100644 --- a/packages/material-ui-lab/src/SpeedDial/SpeedDial.js +++ b/packages/material-ui-lab/src/SpeedDial/SpeedDial.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import keycode from 'keycode'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { componentPropType } from '@material-ui/utils'; import { withStyles } from '@material-ui/core/styles'; import Zoom from '@material-ui/core/Zoom'; diff --git a/packages/material-ui-styles/package.json b/packages/material-ui-styles/package.json index b18aa9879337d7..92ecad290f2f2e 100644 --- a/packages/material-ui-styles/package.json +++ b/packages/material-ui-styles/package.json @@ -51,7 +51,7 @@ "jss-plugin-rule-value-function": "^10.0.0-alpha.7", "jss-plugin-vendor-prefixer": "^10.0.0-alpha.7", "prop-types": "^15.6.0", - "warning": "^4.0.1" + "tiny-warning": "^1.0.2" }, "sideEffects": false, "publishConfig": { diff --git a/packages/material-ui-styles/src/StylesProvider.js b/packages/material-ui-styles/src/StylesProvider.js index be6c6f864673af..1e940be968e940 100644 --- a/packages/material-ui-styles/src/StylesProvider.js +++ b/packages/material-ui-styles/src/StylesProvider.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { exactProp } from '@material-ui/utils'; import createGenerateClassName from './createGenerateClassName'; import { create } from 'jss'; diff --git a/packages/material-ui-styles/src/ThemeProvider.js b/packages/material-ui-styles/src/ThemeProvider.js index 7c3990cc1a0eb4..f52d30458c66b2 100644 --- a/packages/material-ui-styles/src/ThemeProvider.js +++ b/packages/material-ui-styles/src/ThemeProvider.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { exactProp } from '@material-ui/utils'; import ThemeContext from './ThemeContext'; diff --git a/packages/material-ui-styles/src/createGenerateClassName.js b/packages/material-ui-styles/src/createGenerateClassName.js index 4fed9b645a6c16..c934d01211cbf0 100644 --- a/packages/material-ui-styles/src/createGenerateClassName.js +++ b/packages/material-ui-styles/src/createGenerateClassName.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import hash from '@emotion/hash'; const escapeRegex = /([[\].#*$><+~=|^:(),"'`\s])/g; diff --git a/packages/material-ui-styles/src/getStylesCreator.js b/packages/material-ui-styles/src/getStylesCreator.js index f9a1d826706923..3c8bb009bda779 100644 --- a/packages/material-ui-styles/src/getStylesCreator.js +++ b/packages/material-ui-styles/src/getStylesCreator.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import deepmerge from 'deepmerge'; // < 1kb payload overhead when lodash/merge is > 3kb. // Support for the jss-expand plugin. diff --git a/packages/material-ui-styles/src/indexCounter.js b/packages/material-ui-styles/src/indexCounter.js index 755b2773c2ccf9..c016cf7002763b 100644 --- a/packages/material-ui-styles/src/indexCounter.js +++ b/packages/material-ui-styles/src/indexCounter.js @@ -1,6 +1,6 @@ /* eslint-disable import/prefer-default-export */ -import warning from 'warning'; +import warning from 'tiny-warning'; // Global index counter to preserve source order. // We create the style sheet during at the creation of the component, diff --git a/packages/material-ui-styles/src/mergeClasses.js b/packages/material-ui-styles/src/mergeClasses.js index 67f7612971cb4c..cb3f89713a9ff1 100644 --- a/packages/material-ui-styles/src/mergeClasses.js +++ b/packages/material-ui-styles/src/mergeClasses.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import { getDisplayName } from '@material-ui/utils'; function mergeClasses(options = {}) { diff --git a/packages/material-ui-styles/src/withStyles.js b/packages/material-ui-styles/src/withStyles.js index a8ef6adf737cc8..0e582a906ec614 100644 --- a/packages/material-ui-styles/src/withStyles.js +++ b/packages/material-ui-styles/src/withStyles.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { getDynamicStyles } from 'jss'; import { getDisplayName } from '@material-ui/utils'; import { increment } from './indexCounter'; diff --git a/packages/material-ui-system/package.json b/packages/material-ui-system/package.json index cff0386cbd94ad..836d1bff5275c3 100644 --- a/packages/material-ui-system/package.json +++ b/packages/material-ui-system/package.json @@ -39,7 +39,7 @@ "@babel/runtime": "7.1.2", "deepmerge": "^2.0.1", "prop-types": "^15.6.0", - "warning": "^4.0.1" + "tiny-warning": "^1.0.2" }, "devDependencies": {}, "sideEffects": false, diff --git a/packages/material-ui-system/src/breakpoints.js b/packages/material-ui-system/src/breakpoints.js index f7c176adb2daae..a0d789b24d7414 100644 --- a/packages/material-ui-system/src/breakpoints.js +++ b/packages/material-ui-system/src/breakpoints.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import PropTypes from 'prop-types'; import merge from './merge'; diff --git a/packages/material-ui-system/src/spacing.js b/packages/material-ui-system/src/spacing.js index f8a7c628760366..84b52bf85d5551 100644 --- a/packages/material-ui-system/src/spacing.js +++ b/packages/material-ui-system/src/spacing.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import responsivePropType from './responsivePropType'; import { handleBreakpoints } from './breakpoints'; import merge from './merge'; diff --git a/packages/material-ui-system/src/spacing.test.js b/packages/material-ui-system/src/spacing.test.js index 28202c35b54b6e..9de302d38361fa 100644 --- a/packages/material-ui-system/src/spacing.test.js +++ b/packages/material-ui-system/src/spacing.test.js @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import spacing from './spacing'; describe('spacing', () => { @@ -41,11 +41,11 @@ describe('spacing', () => { describe('warnings', () => { beforeEach(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); afterEach(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should warn if the value overflow', () => { @@ -56,10 +56,10 @@ describe('spacing', () => { p: 3, }); assert.deepEqual(output, { padding: undefined }); - assert.strictEqual(consoleErrorMock.callCount(), 1); - assert.match(consoleErrorMock.args()[0][0], /the value provided \(3\) overflows\./); - assert.match(consoleErrorMock.args()[0][0], /The supported values are: \[0,3,5\]\./); - assert.match(consoleErrorMock.args()[0][0], /3 > 2, you need to add the missing values\./); + assert.strictEqual(consoleWarnMock.callCount(), 1); + assert.match(consoleWarnMock.args()[0][0], /the value provided \(3\) overflows\./); + assert.match(consoleWarnMock.args()[0][0], /The supported values are: \[0,3,5\]\./); + assert.match(consoleWarnMock.args()[0][0], /3 > 2, you need to add the missing values\./); }); it('should warn if the theme transformer is invalid', () => { @@ -70,13 +70,13 @@ describe('spacing', () => { p: 3, }); assert.deepEqual(output, { padding: undefined }); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /the `theme.spacing` value \(\[object Object\]\) is invalid\./, ); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /It should be a number, an array or a function\./, ); }); diff --git a/packages/material-ui/.size-snapshot.json b/packages/material-ui/.size-snapshot.json index feb298a4b8b53c..cf6153b9be104c 100644 --- a/packages/material-ui/.size-snapshot.json +++ b/packages/material-ui/.size-snapshot.json @@ -1,7 +1,7 @@ { "build/umd/material-ui.production.min.js": { - "bundled": 849608, - "minified": 312234, - "gzipped": 85103 + "bundled": 849960, + "minified": 312386, + "gzipped": 85138 } } diff --git a/packages/material-ui/package.json b/packages/material-ui/package.json index ba1033b9d8902f..b5cfd7ce5e982a 100644 --- a/packages/material-ui/package.json +++ b/packages/material-ui/package.json @@ -63,7 +63,7 @@ "react-event-listener": "^0.6.2", "react-transition-group": "^2.2.1", "recompose": "0.28.0 - 0.30.0", - "warning": "^4.0.1" + "tiny-warning": "^1.0.2" }, "sideEffects": false, "publishConfig": { diff --git a/packages/material-ui/src/BottomNavigation/BottomNavigation.js b/packages/material-ui/src/BottomNavigation/BottomNavigation.js index a72e15c75f27a6..87c297ffe55d6e 100755 --- a/packages/material-ui/src/BottomNavigation/BottomNavigation.js +++ b/packages/material-ui/src/BottomNavigation/BottomNavigation.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { componentPropType } from '@material-ui/utils'; -import warning from 'warning'; +import warning from 'tiny-warning'; import withStyles from '../styles/withStyles'; export const styles = theme => ({ diff --git a/packages/material-ui/src/ButtonBase/focusVisible.js b/packages/material-ui/src/ButtonBase/focusVisible.js index b84f83552e80e8..b184a4a12b7a81 100644 --- a/packages/material-ui/src/ButtonBase/focusVisible.js +++ b/packages/material-ui/src/ButtonBase/focusVisible.js @@ -1,5 +1,5 @@ import keycode from 'keycode'; -import warning from 'warning'; +import warning from 'tiny-warning'; import ownerDocument from '../utils/ownerDocument'; const internal = { diff --git a/packages/material-ui/src/CardMedia/CardMedia.js b/packages/material-ui/src/CardMedia/CardMedia.js index 0bb015ab6f8dd4..d2c77423351261 100644 --- a/packages/material-ui/src/CardMedia/CardMedia.js +++ b/packages/material-ui/src/CardMedia/CardMedia.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { componentPropType } from '@material-ui/utils'; import withStyles from '../styles/withStyles'; diff --git a/packages/material-ui/src/Chip/Chip.js b/packages/material-ui/src/Chip/Chip.js index 752d23730cbbdf..794eff0ecebb3f 100644 --- a/packages/material-ui/src/Chip/Chip.js +++ b/packages/material-ui/src/Chip/Chip.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import keycode from 'keycode'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { componentPropType } from '@material-ui/utils'; import CancelIcon from '../internal/svg-icons/Cancel'; import withStyles from '../styles/withStyles'; diff --git a/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js b/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js index 23e5519dfaac3e..77694e4a417f66 100644 --- a/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js +++ b/packages/material-ui/src/ExpansionPanel/ExpansionPanel.js @@ -3,7 +3,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import warning from 'warning'; +import warning from 'tiny-warning'; import Collapse from '../Collapse'; import Paper from '../Paper'; import withStyles from '../styles/withStyles'; diff --git a/packages/material-ui/src/GridList/GridList.js b/packages/material-ui/src/GridList/GridList.js index 760ed31d44c952..e78bdaff7e2cc1 100644 --- a/packages/material-ui/src/GridList/GridList.js +++ b/packages/material-ui/src/GridList/GridList.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { componentPropType } from '@material-ui/utils'; import withStyles from '../styles/withStyles'; diff --git a/packages/material-ui/src/Hidden/HiddenCss.js b/packages/material-ui/src/Hidden/HiddenCss.js index 9b6690e951e705..595002fb57ffb8 100644 --- a/packages/material-ui/src/Hidden/HiddenCss.js +++ b/packages/material-ui/src/Hidden/HiddenCss.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { keys as breakpointKeys } from '../styles/createBreakpoints'; import { capitalize } from '../utils/helpers'; import withStyles from '../styles/withStyles'; diff --git a/packages/material-ui/src/InputBase/InputBase.js b/packages/material-ui/src/InputBase/InputBase.js index 7e297c4ee3f313..c0f8bff98f0994 100644 --- a/packages/material-ui/src/InputBase/InputBase.js +++ b/packages/material-ui/src/InputBase/InputBase.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import classNames from 'classnames'; import { componentPropType } from '@material-ui/utils'; import formControlState from '../FormControl/formControlState'; diff --git a/packages/material-ui/src/LinearProgress/LinearProgress.js b/packages/material-ui/src/LinearProgress/LinearProgress.js index b0a2aa2f69a45d..b8a6bf7d0dbbba 100644 --- a/packages/material-ui/src/LinearProgress/LinearProgress.js +++ b/packages/material-ui/src/LinearProgress/LinearProgress.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import warning from 'warning'; +import warning from 'tiny-warning'; import withStyles from '../styles/withStyles'; import { lighten } from '../styles/colorManipulator'; diff --git a/packages/material-ui/src/LinearProgress/LinearProgress.test.js b/packages/material-ui/src/LinearProgress/LinearProgress.test.js index 67a07ab5711f67..04c3f0e6f0a246 100644 --- a/packages/material-ui/src/LinearProgress/LinearProgress.test.js +++ b/packages/material-ui/src/LinearProgress/LinearProgress.test.js @@ -1,6 +1,6 @@ import React from 'react'; import { assert } from 'chai'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import { createShallow, getClasses } from '@material-ui/core/test-utils'; import LinearProgress from './LinearProgress'; @@ -166,28 +166,28 @@ describe('', () => { describe('prop: value', () => { before(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); after(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should warn when not used as expected', () => { shallow(); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /Warning: Material-UI: you need to provide a value property/, ); shallow(); - assert.strictEqual(consoleErrorMock.callCount(), 3); + assert.strictEqual(consoleWarnMock.callCount(), 3); assert.match( - consoleErrorMock.args()[1][0], + consoleWarnMock.args()[1][0], /Warning: Material-UI: you need to provide a value property/, ); assert.match( - consoleErrorMock.args()[2][0], + consoleWarnMock.args()[2][0], /Warning: Material-UI: you need to provide a valueBuffer property/, ); }); diff --git a/packages/material-ui/src/MenuList/MenuList.js b/packages/material-ui/src/MenuList/MenuList.js index a80474901eec12..bb00041b016a85 100644 --- a/packages/material-ui/src/MenuList/MenuList.js +++ b/packages/material-ui/src/MenuList/MenuList.js @@ -4,7 +4,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import keycode from 'keycode'; -import warning from 'warning'; +import warning from 'tiny-warning'; import ownerDocument from '../utils/ownerDocument'; import List from '../List'; diff --git a/packages/material-ui/src/Modal/Modal.js b/packages/material-ui/src/Modal/Modal.js index 5d43101f5e5f5c..825b45f8bafc04 100644 --- a/packages/material-ui/src/Modal/Modal.js +++ b/packages/material-ui/src/Modal/Modal.js @@ -2,7 +2,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import warning from 'warning'; +import warning from 'tiny-warning'; import keycode from 'keycode'; import { componentPropType } from '@material-ui/utils'; import ownerDocument from '../utils/ownerDocument'; diff --git a/packages/material-ui/src/Modal/Modal.test.js b/packages/material-ui/src/Modal/Modal.test.js index 580b8415a88541..65e799db5bac3f 100644 --- a/packages/material-ui/src/Modal/Modal.test.js +++ b/packages/material-ui/src/Modal/Modal.test.js @@ -3,7 +3,7 @@ import { assert } from 'chai'; import { spy, stub } from 'sinon'; import PropTypes from 'prop-types'; import keycode from 'keycode'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import { createShallow, createMount, getClasses, unwrap } from '@material-ui/core/test-utils'; import Fade from '../Fade'; import Portal from '../Portal'; @@ -402,11 +402,11 @@ describe('', () => { document.body.appendChild(focusContainer); focusContainer.focus(); assert.strictEqual(document.activeElement, focusContainer); - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); afterEach(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); wrapper.unmount(); document.body.removeChild(focusContainer); }); @@ -489,8 +489,8 @@ describe('', () => { , ); - assert.strictEqual(consoleErrorMock.callCount(), 1); - assert.match(consoleErrorMock.args()[0][0], /the modal content node does not accept focus/); + assert.strictEqual(consoleWarnMock.callCount(), 1); + assert.match(consoleWarnMock.args()[0][0], /the modal content node does not accept focus/); }); it('should not attempt to focus nonexistent children', () => { diff --git a/packages/material-ui/src/Paper/Paper.js b/packages/material-ui/src/Paper/Paper.js index df7c60ad918f9f..5aa1377531faaa 100644 --- a/packages/material-ui/src/Paper/Paper.js +++ b/packages/material-ui/src/Paper/Paper.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { componentPropType } from '@material-ui/utils'; import withStyles from '../styles/withStyles'; diff --git a/packages/material-ui/src/Popover/Popover.js b/packages/material-ui/src/Popover/Popover.js index 3d2e7f749ecd7a..82ea79fa56bd96 100644 --- a/packages/material-ui/src/Popover/Popover.js +++ b/packages/material-ui/src/Popover/Popover.js @@ -3,7 +3,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; -import warning from 'warning'; +import warning from 'tiny-warning'; import debounce from 'debounce'; // < 1kb payload overhead when lodash/debounce is > 3kb. import EventListener from 'react-event-listener'; import { componentPropType } from '@material-ui/utils'; diff --git a/packages/material-ui/src/RadioGroup/RadioGroup.js b/packages/material-ui/src/RadioGroup/RadioGroup.js index 8d2c0ebf754ed9..e919661b6da473 100644 --- a/packages/material-ui/src/RadioGroup/RadioGroup.js +++ b/packages/material-ui/src/RadioGroup/RadioGroup.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import FormGroup from '../FormGroup'; import { createChainedFunction, find } from '../utils/helpers'; diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js index 455f7413dc17e8..58b77d720e1931 100644 --- a/packages/material-ui/src/Select/SelectInput.js +++ b/packages/material-ui/src/Select/SelectInput.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import keycode from 'keycode'; -import warning from 'warning'; +import warning from 'tiny-warning'; import { componentPropType } from '@material-ui/utils'; import Menu from '../Menu/Menu'; import { isFilled } from '../InputBase/utils'; diff --git a/packages/material-ui/src/Step/Step.js b/packages/material-ui/src/Step/Step.js index a382245d18b03c..3f78a6a34ecd46 100644 --- a/packages/material-ui/src/Step/Step.js +++ b/packages/material-ui/src/Step/Step.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; -import warning from 'warning'; +import warning from 'tiny-warning'; import withStyles from '../styles/withStyles'; export const styles = { diff --git a/packages/material-ui/src/StepContent/StepContent.js b/packages/material-ui/src/StepContent/StepContent.js index d93afac7af7d83..0fc59626b17aff 100644 --- a/packages/material-ui/src/StepContent/StepContent.js +++ b/packages/material-ui/src/StepContent/StepContent.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import classNames from 'classnames'; import { componentPropType } from '@material-ui/utils'; import Collapse from '../Collapse'; diff --git a/packages/material-ui/src/Tabs/Tabs.js b/packages/material-ui/src/Tabs/Tabs.js index a421570710b736..8a84047efbdd8e 100644 --- a/packages/material-ui/src/Tabs/Tabs.js +++ b/packages/material-ui/src/Tabs/Tabs.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import classNames from 'classnames'; import EventListener from 'react-event-listener'; import debounce from 'debounce'; // < 1kb payload overhead when lodash/debounce is > 3kb. diff --git a/packages/material-ui/src/Tabs/Tabs.test.js b/packages/material-ui/src/Tabs/Tabs.test.js index 25550fae0ca17e..9b5c225bd3750b 100644 --- a/packages/material-ui/src/Tabs/Tabs.test.js +++ b/packages/material-ui/src/Tabs/Tabs.test.js @@ -2,7 +2,7 @@ import React from 'react'; import { assert } from 'chai'; import { spy, stub, useFakeTimers } from 'sinon'; import { ShallowWrapper } from 'enzyme'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import { createShallow, createMount, getClasses, unwrap } from '@material-ui/core/test-utils'; import Tab from '../Tab'; import Tabs from './Tabs'; @@ -51,17 +51,17 @@ describe('', () => { describe('warning', () => { before(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); after(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should warn if the input is invalid', () => { shallow(); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /Material-UI: you can not use the `centered={true}` and `variant="scrollable"`/, ); }); @@ -150,7 +150,7 @@ describe('', () => { }); after(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should pass selected prop to children', () => { @@ -311,16 +311,16 @@ describe('', () => { }); it('should warn when the value is invalid', () => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); mount( , ); - assert.strictEqual(consoleErrorMock.callCount(), 3); + assert.strictEqual(consoleWarnMock.callCount(), 3); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /You can provide one of the following values: 1, 3/, ); }); diff --git a/packages/material-ui/src/TextField/TextField.js b/packages/material-ui/src/TextField/TextField.js index f231c3160ef940..65b5a305123d45 100644 --- a/packages/material-ui/src/TextField/TextField.js +++ b/packages/material-ui/src/TextField/TextField.js @@ -2,7 +2,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import warning from 'warning'; +import warning from 'tiny-warning'; import PropTypes from 'prop-types'; import Input from '../Input'; import FilledInput from '../FilledInput'; diff --git a/packages/material-ui/src/Tooltip/Tooltip.js b/packages/material-ui/src/Tooltip/Tooltip.js index 323a278e6aa726..9bc557525526ad 100644 --- a/packages/material-ui/src/Tooltip/Tooltip.js +++ b/packages/material-ui/src/Tooltip/Tooltip.js @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import classNames from 'classnames'; import { componentPropType } from '@material-ui/utils'; import RootRef from '../RootRef'; diff --git a/packages/material-ui/src/Tooltip/Tooltip.test.js b/packages/material-ui/src/Tooltip/Tooltip.test.js index 5adcf47cf27310..62086501a90958 100644 --- a/packages/material-ui/src/Tooltip/Tooltip.test.js +++ b/packages/material-ui/src/Tooltip/Tooltip.test.js @@ -1,7 +1,7 @@ import React from 'react'; import { assert } from 'chai'; import { spy, useFakeTimers } from 'sinon'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import { createShallow, createMount, getClasses, unwrap } from '@material-ui/core/test-utils'; import Popper from '../Popper'; import Tooltip from './Tooltip'; @@ -233,11 +233,11 @@ describe('', () => { describe('disabled button warning', () => { before(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); after(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should not raise a warning if title is empty', () => { @@ -248,7 +248,7 @@ describe('', () => { , ); - assert.strictEqual(consoleErrorMock.callCount(), 0, 'should not call console.error'); + assert.strictEqual(consoleWarnMock.callCount(), 0, 'should not call console.error'); }); it('should raise a warning when we can listen to events', () => { @@ -259,9 +259,9 @@ describe('', () => { , ); - assert.strictEqual(consoleErrorMock.callCount(), 1, 'should call console.error'); + assert.strictEqual(consoleWarnMock.callCount(), 1, 'should call console.error'); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /Material-UI: you are providing a disabled `button` child to the Tooltip component/, ); }); diff --git a/packages/material-ui/src/styles/MuiThemeProvider.js b/packages/material-ui/src/styles/MuiThemeProvider.js index a03a6d32846a25..aed7ea1baf87aa 100644 --- a/packages/material-ui/src/styles/MuiThemeProvider.js +++ b/packages/material-ui/src/styles/MuiThemeProvider.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import createBroadcast from 'brcast'; import { exactProp, ponyfillGlobal } from '@material-ui/utils'; import themeListener, { CHANNEL } from './themeListener'; diff --git a/packages/material-ui/src/styles/colorManipulator.js b/packages/material-ui/src/styles/colorManipulator.js index fc845e51d4f09c..078e732c4c7281 100644 --- a/packages/material-ui/src/styles/colorManipulator.js +++ b/packages/material-ui/src/styles/colorManipulator.js @@ -1,6 +1,6 @@ /* eslint-disable no-use-before-define */ -import warning from 'warning'; +import warning from 'tiny-warning'; /** * Returns a number whose value is limited to the given range. diff --git a/packages/material-ui/src/styles/colorManipulator.test.js b/packages/material-ui/src/styles/colorManipulator.test.js index cd5d644af1bf14..523849c8022449 100644 --- a/packages/material-ui/src/styles/colorManipulator.test.js +++ b/packages/material-ui/src/styles/colorManipulator.test.js @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import { recomposeColor, convertHexToRGB, @@ -15,11 +15,11 @@ import { describe('utils/colorManipulator', () => { beforeEach(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); afterEach(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); describe('recomposeColor', () => { @@ -212,12 +212,12 @@ describe('utils/colorManipulator', () => { it("doesn't overshoot if an above-range coefficient is supplied", () => { assert.strictEqual(darken('rgb(0, 127, 255)', 1.5), 'rgb(0, 0, 0)'); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); }); it("doesn't overshoot if a below-range coefficient is supplied", () => { assert.strictEqual(darken('rgb(0, 127, 255)', -0.1), 'rgb(0, 127, 255)'); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); }); it('darkens rgb white to black when coefficient is 1', () => { @@ -264,12 +264,12 @@ describe('utils/colorManipulator', () => { it("doesn't overshoot if an above-range coefficient is supplied", () => { assert.strictEqual(lighten('rgb(0, 127, 255)', 1.5), 'rgb(255, 255, 255)'); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); }); it("doesn't overshoot if a below-range coefficient is supplied", () => { assert.strictEqual(lighten('rgb(0, 127, 255)', -0.1), 'rgb(0, 127, 255)'); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); }); it('lightens rgb black to white when coefficient is 1', () => { diff --git a/packages/material-ui/src/styles/createGenerateClassName.js b/packages/material-ui/src/styles/createGenerateClassName.js index 56432917e42102..ee5d8192e4e797 100644 --- a/packages/material-ui/src/styles/createGenerateClassName.js +++ b/packages/material-ui/src/styles/createGenerateClassName.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; const escapeRegex = /([[\].#*$><+~=|^:(),"'`\s])/g; diff --git a/packages/material-ui/src/styles/createMuiTheme.js b/packages/material-ui/src/styles/createMuiTheme.js index 6bd453603360af..dacc47d68d7d88 100644 --- a/packages/material-ui/src/styles/createMuiTheme.js +++ b/packages/material-ui/src/styles/createMuiTheme.js @@ -1,6 +1,6 @@ import deepmerge from 'deepmerge'; // < 1kb payload overhead when lodash/merge is > 3kb. import isPlainObject from 'is-plain-object'; -import warning from 'warning'; +import warning from 'tiny-warning'; import createBreakpoints from './createBreakpoints'; import createMixins from './createMixins'; import createPalette from './createPalette'; diff --git a/packages/material-ui/src/styles/createMuiTheme.test.js b/packages/material-ui/src/styles/createMuiTheme.test.js index df758ca208ff14..56939069d70f35 100644 --- a/packages/material-ui/src/styles/createMuiTheme.test.js +++ b/packages/material-ui/src/styles/createMuiTheme.test.js @@ -1,7 +1,7 @@ import { assert } from 'chai'; import createMuiTheme from './createMuiTheme'; import { deepOrange, green } from '../colors'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; describe('createMuiTheme', () => { it('should have a palette', () => { @@ -93,22 +93,22 @@ describe('createMuiTheme', () => { describe('overrides', () => { beforeEach(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); afterEach(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should warn when trying to override an internal state the wrong way', () => { createMuiTheme({ overrides: { Button: { disabled: { color: 'blue' } } } }); - assert.strictEqual(consoleErrorMock.args().length, 0); + assert.strictEqual(consoleWarnMock.args().length, 0); createMuiTheme({ overrides: { MuiButton: { root: { color: 'blue' } } } }); - assert.strictEqual(consoleErrorMock.args().length, 0); + assert.strictEqual(consoleWarnMock.args().length, 0); createMuiTheme({ overrides: { MuiButton: { disabled: { color: 'blue' } } } }); - assert.strictEqual(consoleErrorMock.args().length, 1); + assert.strictEqual(consoleWarnMock.args().length, 1); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /the `MuiButton` component increases the CSS specificity of the `disabled` internal state./, ); }); diff --git a/packages/material-ui/src/styles/createPalette.js b/packages/material-ui/src/styles/createPalette.js index 7c3ef865d69820..9cbec535dc3e53 100644 --- a/packages/material-ui/src/styles/createPalette.js +++ b/packages/material-ui/src/styles/createPalette.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import deepmerge from 'deepmerge'; // < 1kb payload overhead when lodash/merge is > 3kb. import indigo from '../colors/indigo'; import pink from '../colors/pink'; diff --git a/packages/material-ui/src/styles/createPalette.test.js b/packages/material-ui/src/styles/createPalette.test.js index bbf86b68894f2d..3018e96812385b 100644 --- a/packages/material-ui/src/styles/createPalette.test.js +++ b/packages/material-ui/src/styles/createPalette.test.js @@ -1,16 +1,16 @@ import { assert } from 'chai'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import { indigo, pink, deepOrange, green, red } from '../colors'; import { lighten, darken } from './colorManipulator'; import createPalette, { dark, light } from './createPalette'; describe('createPalette()', () => { before(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); after(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should create a material design palette according to spec', () => { @@ -348,14 +348,14 @@ describe('createPalette()', () => { 'should use pink as the default secondary color', ); assert.strictEqual(palette.text, dark.text, 'should use dark theme text'); - assert.strictEqual(consoleErrorMock.callCount(), 0); + assert.strictEqual(consoleWarnMock.callCount(), 0); }); it('should throw an exception when an invalid type is specified', () => { createPalette({ type: 'foo' }); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /Material-UI: the palette type `foo` is not supported/, ); }); diff --git a/packages/material-ui/src/styles/createTypography.js b/packages/material-ui/src/styles/createTypography.js index 274dfa92efdd19..1c57e212840fc8 100644 --- a/packages/material-ui/src/styles/createTypography.js +++ b/packages/material-ui/src/styles/createTypography.js @@ -1,5 +1,5 @@ import deepmerge from 'deepmerge'; // < 1kb payload overhead when lodash/merge is > 3kb. -import warning from 'warning'; +import warning from 'tiny-warning'; import { ponyfillGlobal } from '@material-ui/utils'; function round(value) { diff --git a/packages/material-ui/src/styles/createTypography.test.js b/packages/material-ui/src/styles/createTypography.test.js index b2ee587a11f8c3..bbb2ee402d3487 100644 --- a/packages/material-ui/src/styles/createTypography.test.js +++ b/packages/material-ui/src/styles/createTypography.test.js @@ -1,7 +1,7 @@ import { assert } from 'chai'; import createPalette from './createPalette'; import createTypography from './createTypography'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; describe('createTypography', () => { let palette; @@ -75,23 +75,23 @@ describe('createTypography', () => { beforeEach(() => { // eslint-disable-next-line no-underscore-dangle global.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = false; - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); afterEach(() => { // eslint-disable-next-line no-underscore-dangle global.__MUI_USE_NEXT_TYPOGRAPHY_VARIANTS__ = true; - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); const testTypography = (options, expectWarning) => { createTypography(palette, options); if (expectWarning) { - assert.strictEqual(consoleErrorMock.callCount(), 1); - assert.include(consoleErrorMock.args()[0][0], 'Material-UI:'); + assert.strictEqual(consoleWarnMock.callCount(), 1); + assert.include(consoleWarnMock.args()[0][0], 'Material-UI:'); } else { - assert.strictEqual(consoleErrorMock.callCount(), 0); + assert.strictEqual(consoleWarnMock.callCount(), 0); } }; diff --git a/packages/material-ui/src/styles/getStylesCreator.js b/packages/material-ui/src/styles/getStylesCreator.js index 710f526750aec1..7d7f1b5ac27604 100644 --- a/packages/material-ui/src/styles/getStylesCreator.js +++ b/packages/material-ui/src/styles/getStylesCreator.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import deepmerge from 'deepmerge'; // < 1kb payload overhead when lodash/merge is > 3kb. // Support for the jss-expand plugin. diff --git a/packages/material-ui/src/styles/getStylesCreator.test.js b/packages/material-ui/src/styles/getStylesCreator.test.js index 7ec2b772766384..afa8f6558355d2 100644 --- a/packages/material-ui/src/styles/getStylesCreator.test.js +++ b/packages/material-ui/src/styles/getStylesCreator.test.js @@ -1,5 +1,5 @@ import { assert } from 'chai'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import getStylesCreator from './getStylesCreator'; describe('getStylesCreator', () => { @@ -29,11 +29,11 @@ describe('getStylesCreator', () => { describe('overrides', () => { before(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); after(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should be able to overrides some rules, deep', () => { @@ -68,8 +68,8 @@ describe('getStylesCreator', () => { }, }; stylesCreator.create(theme, name); - assert.strictEqual(consoleErrorMock.callCount(), 1); - assert.match(consoleErrorMock.args()[0][0], /Fix the `bubu` key of `theme\.overrides\.name`/); + assert.strictEqual(consoleWarnMock.callCount(), 1); + assert.match(consoleWarnMock.args()[0][0], /Fix the `bubu` key of `theme\.overrides\.name`/); }); it('should support jss-expand', () => { diff --git a/packages/material-ui/src/styles/mergeClasses.js b/packages/material-ui/src/styles/mergeClasses.js index 4c0a9a1625a1a0..3dd18b549ba8c5 100644 --- a/packages/material-ui/src/styles/mergeClasses.js +++ b/packages/material-ui/src/styles/mergeClasses.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; import { getDisplayName } from '@material-ui/utils'; function mergeClasses(options = {}) { diff --git a/packages/material-ui/src/styles/transitions.js b/packages/material-ui/src/styles/transitions.js index 03bbc2917d72dd..ee7ba3f4519ac5 100644 --- a/packages/material-ui/src/styles/transitions.js +++ b/packages/material-ui/src/styles/transitions.js @@ -1,6 +1,6 @@ /* eslint-disable no-restricted-globals */ -import warning from 'warning'; +import warning from 'tiny-warning'; // Follow https://material.google.com/motion/duration-easing.html#duration-easing-natural-easing-curves // to learn the context in which each easing should be used. diff --git a/packages/material-ui/src/styles/transitions.test.js b/packages/material-ui/src/styles/transitions.test.js index 16da1ecf0be688..619896233dabc0 100644 --- a/packages/material-ui/src/styles/transitions.test.js +++ b/packages/material-ui/src/styles/transitions.test.js @@ -3,14 +3,14 @@ import { stub } from 'sinon'; import transitions, { easing, duration, formatMs, isString, isNumber } from './transitions'; describe('transitions', () => { - let consoleErrorStub; + let consoleWarnStub; beforeEach(() => { - consoleErrorStub = stub(console, 'error'); + consoleWarnStub = stub(console, 'warn'); }); afterEach(() => { - consoleErrorStub.restore(); + consoleWarnStub.restore(); }); describe('formatMs() function', () => { @@ -72,13 +72,13 @@ describe('transitions', () => { it('should create default transition without arguments', () => { const transition = transitions.create(); assert.strictEqual(transition, `all ${duration.standard}ms ${easing.easeInOut} 0ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should take string props as a first argument', () => { const transition = transitions.create('color'); assert.strictEqual(transition, `color ${duration.standard}ms ${easing.easeInOut} 0ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should also take array of props as first argument', () => { @@ -88,7 +88,7 @@ describe('transitions', () => { const single2 = transitions.create('size', options); const expected = `${single1},${single2}`; assert.strictEqual(multiple, expected); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should warn when first argument is of bad type', () => { @@ -96,25 +96,25 @@ describe('transitions', () => { transitions.create(5554); // $FlowIgnore transitions.create({}); - assert.strictEqual(consoleErrorStub.callCount, 2, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 2, 'Wrong number of calls of warning()'); }); it('should optionally accept number "duration" option in second argument', () => { const transition = transitions.create('font', { duration: 500 }); assert.strictEqual(transition, `font 500ms ${easing.easeInOut} 0ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should optionally accept string "duration" option in second argument', () => { const transition = transitions.create('font', { duration: '500ms' }); assert.strictEqual(transition, `font 500ms ${easing.easeInOut} 0ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should round decimal digits of "duration" prop to whole numbers', () => { const transition = transitions.create('font', { duration: 12.125 }); assert.strictEqual(transition, `font 12ms ${easing.easeInOut} 0ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should warn when bad "duration" option type', () => { @@ -122,13 +122,13 @@ describe('transitions', () => { transitions.create('font', { duration: null }); // $FlowIgnore transitions.create('font', { duration: {} }); - assert.strictEqual(consoleErrorStub.callCount, 2, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 2, 'Wrong number of calls of warning()'); }); it('should optionally accept string "easing" option in second argument', () => { const transition = transitions.create('transform', { easing: easing.sharp }); assert.strictEqual(transition, `transform ${duration.standard}ms ${easing.sharp} 0ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should warn when bad "easing" option type', () => { @@ -136,25 +136,25 @@ describe('transitions', () => { transitions.create('transform', { easing: 123 }); // $FlowIgnore transitions.create('transform', { easing: {} }); - assert.strictEqual(consoleErrorStub.callCount, 2, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 2, 'Wrong number of calls of warning()'); }); it('should optionally accept number "delay" option in second argument', () => { const transition = transitions.create('size', { delay: 150 }); assert.strictEqual(transition, `size ${duration.standard}ms ${easing.easeInOut} 150ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should optionally accept string "delay" option in second argument', () => { const transition = transitions.create('size', { delay: '150ms' }); assert.strictEqual(transition, `size ${duration.standard}ms ${easing.easeInOut} 150ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should round decimal digits of "delay" prop to whole numbers', () => { const transition = transitions.create('size', { delay: 1.547 }); assert.strictEqual(transition, `size ${duration.standard}ms ${easing.easeInOut} 2ms`); - assert.strictEqual(consoleErrorStub.callCount, 0, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 0, 'Wrong number of calls of warning()'); }); it('should warn when bad "delay" option type', () => { @@ -162,12 +162,12 @@ describe('transitions', () => { transitions.create('size', { delay: null }); // $FlowIgnore transitions.create('size', { delay: {} }); - assert.strictEqual(consoleErrorStub.callCount, 2, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 2, 'Wrong number of calls of warning()'); }); it('should warn when passed unrecognized option', () => { transitions.create('size', { fffds: 'value' }); - assert.strictEqual(consoleErrorStub.callCount, 1, 'Wrong number of calls of warning()'); + assert.strictEqual(consoleWarnStub.callCount, 1, 'Wrong number of calls of warning()'); }); it('should return zero when not passed arguments', () => { diff --git a/packages/material-ui/src/styles/withStyles.js b/packages/material-ui/src/styles/withStyles.js index c0e82edb427c2c..2518591b42ea89 100644 --- a/packages/material-ui/src/styles/withStyles.js +++ b/packages/material-ui/src/styles/withStyles.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -import warning from 'warning'; +import warning from 'tiny-warning'; import hoistNonReactStatics from 'hoist-non-react-statics'; import { getDisplayName, ponyfillGlobal } from '@material-ui/utils'; import { create } from 'jss'; diff --git a/packages/material-ui/src/styles/withStyles.test.js b/packages/material-ui/src/styles/withStyles.test.js index 0f2ac4b53559af..486de91b0c3bda 100644 --- a/packages/material-ui/src/styles/withStyles.test.js +++ b/packages/material-ui/src/styles/withStyles.test.js @@ -3,7 +3,7 @@ import { spy } from 'sinon'; import { assert } from 'chai'; import { JssProvider } from 'react-jss'; import { create, SheetsRegistry } from 'jss'; -import consoleErrorMock from 'test/utils/consoleErrorMock'; +import consoleWarnMock from 'test/utils/consoleWarnMock'; import jssPreset from './jssPreset'; import withStyles from './withStyles'; import MuiThemeProvider from './MuiThemeProvider'; @@ -48,32 +48,32 @@ describe('withStyles', () => { describe('prop: classes', () => { before(() => { - consoleErrorMock.spy(); + consoleWarnMock.spy(); }); after(() => { - consoleErrorMock.reset(); + consoleWarnMock.reset(); }); it('should accept a classes property', () => { const wrapper = shallow(); assert.deepEqual(wrapper.props().classes, { root: `${classes.root} h1` }); - assert.strictEqual(consoleErrorMock.callCount(), 0); + assert.strictEqual(consoleWarnMock.callCount(), 0); }); it('should ignore undefined property', () => { const wrapper = shallow(); assert.deepEqual(wrapper.props().classes, { root: classes.root }); - assert.strictEqual(consoleErrorMock.callCount(), 0); + assert.strictEqual(consoleWarnMock.callCount(), 0); }); it('should warn if providing a unknown key', () => { const wrapper = shallow(); assert.deepEqual(wrapper.props().classes, { root: classes.root, bar: 'undefined foo' }); - assert.strictEqual(consoleErrorMock.callCount(), 1); + assert.strictEqual(consoleWarnMock.callCount(), 1); assert.match( - consoleErrorMock.args()[0][0], + consoleWarnMock.args()[0][0], /Material-UI: the key `bar` provided to the classes property is not implemented/, ); }); @@ -82,9 +82,9 @@ describe('withStyles', () => { const wrapper = shallow(); assert.deepEqual(wrapper.props().classes, { root: `${classes.root} [object Object]` }); - assert.strictEqual(consoleErrorMock.callCount(), 2); + assert.strictEqual(consoleWarnMock.callCount(), 2); assert.match( - consoleErrorMock.args()[1][0], + consoleWarnMock.args()[1][0], /Material-UI: the key `root` provided to the classes property is not valid/, ); }); diff --git a/packages/material-ui/src/utils/helpers.js b/packages/material-ui/src/utils/helpers.js index 6efb8966ea1a09..d339d8c9b0f7ec 100644 --- a/packages/material-ui/src/utils/helpers.js +++ b/packages/material-ui/src/utils/helpers.js @@ -1,4 +1,4 @@ -import warning from 'warning'; +import warning from 'tiny-warning'; // It should to be noted that this function isn't equivalent to `text-transform: capitalize`. // diff --git a/test/utils/consoleWarnMock.js b/test/utils/consoleWarnMock.js new file mode 100644 index 00000000000000..d13266f1b7c0ac --- /dev/null +++ b/test/utils/consoleWarnMock.js @@ -0,0 +1,48 @@ +/* eslint-disable no-console */ + +import { spy } from 'sinon'; + +/** + * One alternative to this module is to use something like: + * + * let warning; + * + * beforeEach(() => { + * warning = mock(console).expects('warn'); + * }); + * + * afterEach(() => { + * warning.restore(); + * }); + */ +class ConsoleWarnMock { + consoleWarnContainer; + + spy = () => { + this.consoleWarnContainer = console.warn; + console.warn = spy(); + }; + + reset = () => { + console.warn = this.consoleWarnContainer; + delete this.consoleWarnContainer; + }; + + callCount = () => { + if (this.consoleWarnContainer) { + return console.warn.callCount; + } + + throw new Error('Requested call count before spy() was called'); + }; + + args = () => { + if (this.consoleWarnContainer) { + return console.warn.args; + } + + throw new Error('Requested call count before spy() was called'); + }; +} + +export default new ConsoleWarnMock(); diff --git a/test/utils/consoleWarnMock.test.js b/test/utils/consoleWarnMock.test.js new file mode 100644 index 00000000000000..08e88b00bf3de9 --- /dev/null +++ b/test/utils/consoleWarnMock.test.js @@ -0,0 +1,38 @@ +/* eslint-disable no-console */ + +import { assert } from 'chai'; +import consoleWarnMock from './consoleWarnMock'; + +describe('consoleWarnMock()', () => { + describe('callCount()', () => { + it('should throw error when calling callCount() before spy()', () => { + assert.throws(() => { + consoleWarnMock.callCount(); + }, 'Requested call count before spy() was called'); + }); + }); + + describe('args()', () => { + it('should throw error when calling args() before spy()', () => { + assert.throws(() => { + consoleWarnMock.args(); + }, 'Requested call count before spy() was called'); + }); + }); + + describe('spy()', () => { + it('should place a spy in console.warn', () => { + consoleWarnMock.spy(); + assert.strictEqual(console.warn.hasOwnProperty('isSinonProxy'), true); + consoleWarnMock.reset(); + assert.strictEqual(console.warn.hasOwnProperty('isSinonProxy'), false); + }); + + it('should keep the call count', () => { + consoleWarnMock.spy(); + console.warn(); + assert.strictEqual(consoleWarnMock.callCount(), 1); + consoleWarnMock.reset(); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index 23ab7dab4f325a..d92962dea32c45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6004,9 +6004,6 @@ eslint-plugin-jsx-a11y@^6.0.3: has "^1.0.3" jsx-ast-utils "^2.0.1" -"eslint-plugin-material-ui@file:packages/eslint-plugin-material-ui": - version "3.0.0" - eslint-plugin-mocha@^5.0.0: version "5.2.0" resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-5.2.0.tgz#d8786d9fff8cb8b5f6e4b61e40395d6568a5c4e2" @@ -7282,7 +7279,12 @@ hmac-drbg@^1.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" -hoist-non-react-statics@2.5.5, hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0, hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.2.0, hoist-non-react-statics@^3.2.1: +hoist-non-react-statics@2.5.5, hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0: + version "2.5.5" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47" + integrity sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw== + +hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.2.0, hoist-non-react-statics@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.2.1.tgz#c09c0555c84b38a7ede6912b61efddafd6e75e1e" integrity sha512-TFsu3TV3YLY+zFTZDrN8L2DTFanObwmBLpWvJs1qfUuEQ5bTAdFcwfx2T/bsCXfM9QHSLvjfP+nihEl0yvozxw== @@ -8567,7 +8569,7 @@ jss-vendor-prefixer@^7.0.0: dependencies: css-vendor "^0.3.8" -jss@^10.0.0-alpha.3, jss@^10.0.0-alpha.7, jss@^9.8.7: +jss@^10.0.0-alpha.3, jss@^10.0.0-alpha.7: version "10.0.0-alpha.7" resolved "https://registry.yarnpkg.com/jss/-/jss-10.0.0-alpha.7.tgz#ee9909f3a97c9370fa120b50929a79b2caed8536" integrity sha512-nxCfzcL9KzJEpxmSfozCzj5xgRvINF/g1ryHH/sgHeHcleFvY6mzo9D1VuhkUYF1mdEpcoprAjdqFYlsi8gRsQ== @@ -8577,6 +8579,15 @@ jss@^10.0.0-alpha.3, jss@^10.0.0-alpha.7, jss@^9.8.7: symbol-observable "^1.2.0" tiny-warning "^1.0.2" +jss@^9.8.7: + version "9.8.7" + resolved "https://registry.yarnpkg.com/jss/-/jss-9.8.7.tgz#ed9763fc0f2f0260fc8260dac657af61e622ce05" + integrity sha512-awj3XRZYxbrmmrx9LUSj5pXSUfm12m8xzi/VKeqI1ZwWBtQ0kVPTs3vYs32t4rFw83CgFDukA8wKzOE9sMQnoQ== + dependencies: + is-in-browser "^1.1.3" + symbol-observable "^1.1.0" + warning "^3.0.0" + jsx-ast-utils@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz#e801b1b39985e20fffc87b40e3748080e2dcac7f" @@ -13389,7 +13400,7 @@ svgo@^1.0.0, svgo@^1.0.5: unquote "~1.1.1" util.promisify "~1.0.0" -symbol-observable@1.2.0, symbol-observable@^1.0.4, symbol-observable@^1.2.0: +symbol-observable@1.2.0, symbol-observable@^1.0.4, symbol-observable@^1.1.0, symbol-observable@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ== From f7f83fca12e61cea58a92c96b1b29f345808b90b Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 13 Jan 2019 01:16:21 +0300 Subject: [PATCH 2/3] Format and update size --- .size-limit.js | 2 +- packages/material-ui-system/src/spacing.test.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.size-limit.js b/.size-limit.js index 15d90e418b7b34..ab0df7e638caad 100644 --- a/.size-limit.js +++ b/.size-limit.js @@ -40,7 +40,7 @@ module.exports = [ name: 'The size of the color manipulator helpers', webpack: true, path: 'packages/material-ui/build/styles/colorManipulator.js', - limit: '900 B', + limit: '903 B', }, { // vs https://bundlephobia.com/result?p=react-popper diff --git a/packages/material-ui-system/src/spacing.test.js b/packages/material-ui-system/src/spacing.test.js index 9de302d38361fa..3420fc872b5acd 100644 --- a/packages/material-ui-system/src/spacing.test.js +++ b/packages/material-ui-system/src/spacing.test.js @@ -75,10 +75,7 @@ describe('spacing', () => { consoleWarnMock.args()[0][0], /the `theme.spacing` value \(\[object Object\]\) is invalid\./, ); - assert.match( - consoleWarnMock.args()[0][0], - /It should be a number, an array or a function\./, - ); + assert.match(consoleWarnMock.args()[0][0], /It should be a number, an array or a function\./); }); }); From 0c81e976fd5b1363925b36553e3dfafaf0fb3f02 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Sun, 13 Jan 2019 01:21:42 +0300 Subject: [PATCH 3/3] Update lockfile --- yarn.lock | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/yarn.lock b/yarn.lock index d92962dea32c45..23ab7dab4f325a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6004,6 +6004,9 @@ eslint-plugin-jsx-a11y@^6.0.3: has "^1.0.3" jsx-ast-utils "^2.0.1" +"eslint-plugin-material-ui@file:packages/eslint-plugin-material-ui": + version "3.0.0" + eslint-plugin-mocha@^5.0.0: version "5.2.0" resolved "https://registry.yarnpkg.com/eslint-plugin-mocha/-/eslint-plugin-mocha-5.2.0.tgz#d8786d9fff8cb8b5f6e4b61e40395d6568a5c4e2" @@ -7279,12 +7282,7 @@ hmac-drbg@^1.0.0: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" -hoist-non-react-statics@2.5.5, hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0: - version "2.5.5" - resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.5.tgz#c5903cf409c0dfd908f388e619d86b9c1174cb47" - integrity sha512-rqcy4pJo55FTTLWt+bU8ukscqHeE/e9KWvsOW2b/a3afxQZhwkQdT1rPPCJ0rYXdj4vNcasY8zHTH+jF/qStxw== - -hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.2.0, hoist-non-react-statics@^3.2.1: +hoist-non-react-statics@2.5.5, hoist-non-react-statics@^2.3.1, hoist-non-react-statics@^2.5.0, hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.2.0, hoist-non-react-statics@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.2.1.tgz#c09c0555c84b38a7ede6912b61efddafd6e75e1e" integrity sha512-TFsu3TV3YLY+zFTZDrN8L2DTFanObwmBLpWvJs1qfUuEQ5bTAdFcwfx2T/bsCXfM9QHSLvjfP+nihEl0yvozxw== @@ -8569,7 +8567,7 @@ jss-vendor-prefixer@^7.0.0: dependencies: css-vendor "^0.3.8" -jss@^10.0.0-alpha.3, jss@^10.0.0-alpha.7: +jss@^10.0.0-alpha.3, jss@^10.0.0-alpha.7, jss@^9.8.7: version "10.0.0-alpha.7" resolved "https://registry.yarnpkg.com/jss/-/jss-10.0.0-alpha.7.tgz#ee9909f3a97c9370fa120b50929a79b2caed8536" integrity sha512-nxCfzcL9KzJEpxmSfozCzj5xgRvINF/g1ryHH/sgHeHcleFvY6mzo9D1VuhkUYF1mdEpcoprAjdqFYlsi8gRsQ== @@ -8579,15 +8577,6 @@ jss@^10.0.0-alpha.3, jss@^10.0.0-alpha.7: symbol-observable "^1.2.0" tiny-warning "^1.0.2" -jss@^9.8.7: - version "9.8.7" - resolved "https://registry.yarnpkg.com/jss/-/jss-9.8.7.tgz#ed9763fc0f2f0260fc8260dac657af61e622ce05" - integrity sha512-awj3XRZYxbrmmrx9LUSj5pXSUfm12m8xzi/VKeqI1ZwWBtQ0kVPTs3vYs32t4rFw83CgFDukA8wKzOE9sMQnoQ== - dependencies: - is-in-browser "^1.1.3" - symbol-observable "^1.1.0" - warning "^3.0.0" - jsx-ast-utils@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz#e801b1b39985e20fffc87b40e3748080e2dcac7f" @@ -13400,7 +13389,7 @@ svgo@^1.0.0, svgo@^1.0.5: unquote "~1.1.1" util.promisify "~1.0.0" -symbol-observable@1.2.0, symbol-observable@^1.0.4, symbol-observable@^1.1.0, symbol-observable@^1.2.0: +symbol-observable@1.2.0, symbol-observable@^1.0.4, symbol-observable@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804" integrity sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ==