diff --git a/package.json b/package.json index 33b04cc5947f1..949b8386ab75b 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@types/enzyme": "^3.10.5", "@types/enzyme-adapter-react-16": "^1.0.6", "@types/jest": "^25.1.2", + "@types/mocha": "^8.0.3", "@types/node": "^12.0.0", "@types/react": "^16.9.25", "@types/react-dom": "^16.9.5", diff --git a/packages/grid/data-grid/package.json b/packages/grid/data-grid/package.json index 64d13f8c166ca..03341002a85cb 100644 --- a/packages/grid/data-grid/package.json +++ b/packages/grid/data-grid/package.json @@ -13,6 +13,15 @@ "publishConfig": { "access": "public" }, + "scripts": { + "precommit": "npm run lint", + "build": "rollup -c ", + "start": "rollup -cw", + "lint": "eslint 'src/**/*.{ts,tsx}' --quiet --fix -c ../../../.eslintrc.js && npm run lint:css", + "lint:css": "stylelint 'src/**/*.{ts,tsx}' ../../../.stylelintrc.js", + "test": "../../../node_modules/.bin/jest --config jest.config.js", + "typescript": "tsc -p tsconfig.json" + }, "dependencies": { "prop-types": "^15.7.2", "tslib": "^2.0.0" @@ -33,14 +42,6 @@ "react": "^16.8.0", "styled-components": "^5.1.0" }, - "scripts": { - "precommit": "npm run lint", - "build": "rollup -c ", - "start": "rollup -cw", - "lint": "eslint 'src/**/*.{ts,tsx}' --quiet --fix -c ../../../.eslintrc.js && npm run lint:css", - "lint:css": "stylelint 'src/**/*.{ts,tsx}' ../../../.stylelintrc.js", - "test": "../../../node_modules/.bin/jest --config jest.config.js" - }, "setupFiles": [ "/src/setupTests.js" ], diff --git a/packages/grid/data-grid/rollup.config.js b/packages/grid/data-grid/rollup.config.js index 38e4e9e771a8a..08e6b94838523 100644 --- a/packages/grid/data-grid/rollup.config.js +++ b/packages/grid/data-grid/rollup.config.js @@ -34,7 +34,7 @@ export default [ cleaner({ targets: ['./dist/'], }), - typescript({ build: true }), + typescript({ tsconfig: 'tsconfig.build.json' }), !production && sourceMaps(), production && terser(), ], diff --git a/packages/grid/data-grid/src/DataGrid.spec.tsx b/packages/grid/data-grid/src/DataGrid.spec.tsx new file mode 100644 index 0000000000000..cccfd27c49eff --- /dev/null +++ b/packages/grid/data-grid/src/DataGrid.spec.tsx @@ -0,0 +1,13 @@ +import * as React from 'react'; +import { DataGrid } from '@material-ui/data-grid'; + +function EnterpriseTest() { + return ( +
+ + + {/* @ts-expect-error Type 'false' is not assignable to type 'true | undefined' */} + +
+ ); +} diff --git a/packages/grid/data-grid/src/DataGrid.test.tsx b/packages/grid/data-grid/src/DataGrid.test.tsx index af387d4041248..519e402fac8d3 100644 --- a/packages/grid/data-grid/src/DataGrid.test.tsx +++ b/packages/grid/data-grid/src/DataGrid.test.tsx @@ -1,4 +1,7 @@ +/* eslint-disable react/forbid-foreign-prop-types */ import * as React from 'react'; +import PropTypes from 'prop-types'; +// @ts-ignore import { createClientRender } from 'test/utils'; import { expect } from 'chai'; import { DataGrid } from '@material-ui/data-grid'; @@ -19,42 +22,64 @@ describe('', () => { ], }; - before(function beforeHook() { - if (/jsdom/.test(window.navigator.userAgent)) { - // Need layouting - this.skip(); - } - }); - - // Adapation of describeConformance() - describe('Material-UI component API', () => { - it(`attaches the ref`, () => { - const ref = React.createRef(); - const { container } = render( -
- -
, - ); - expect(ref.current).to.be.instanceof(window.HTMLDivElement); - expect(ref.current).to.equal(container.firstChild.firstChild.firstChild); + describe('layout', () => { + before(function beforeHook() { + if (/jsdom/.test(window.navigator.userAgent)) { + // Need layouting + this.skip(); + } }); - function randomStringValue() { - return `r${Math.random().toString(36).slice(2)}`; - } + // Adapation of describeConformance() + describe('Material-UI component API', () => { + it(`attaches the ref`, () => { + const ref = React.createRef(); + const { container } = render( +
+ +
, + ); + expect(ref.current).to.be.instanceof(window.HTMLDivElement); + expect(ref.current).to.equal(container.firstChild.firstChild.firstChild); + }); + + function randomStringValue() { + return `r${Math.random().toString(36).slice(2)}`; + } + + it('applies the className to the root component', () => { + const className = randomStringValue(); - it('applies the className to the root component', () => { - const className = randomStringValue(); + const { container } = render( +
+ +
, + ); - const { container } = render( -
- -
, - ); + expect(document.querySelector(`.${className}`)).to.equal( + container.firstChild.firstChild.firstChild, + ); + }); + }); + }); + + describe('warnings', () => { + before(() => { + PropTypes.resetWarningCache(); + }); - expect(document.querySelector(`.${className}`)).to.equal( - container.firstChild.firstChild.firstChild, - ); + it('should raise a warning if trying to use an enterprise feature', () => { + expect(() => { + PropTypes.checkPropTypes( + // @ts-ignore + DataGrid.Naked.propTypes, + { + pagination: false, + }, + 'prop', + 'MockedDataGrid', + ); + }).toErrorDev('Material-UI: `` is not a valid prop.'); }); }); }); diff --git a/packages/grid/data-grid/src/DataGrid.tsx b/packages/grid/data-grid/src/DataGrid.tsx index 97678f211b1b1..f993d653c84e6 100644 --- a/packages/grid/data-grid/src/DataGrid.tsx +++ b/packages/grid/data-grid/src/DataGrid.tsx @@ -104,3 +104,6 @@ DataGrid2.propTypes = { }; export const DataGrid = React.memo(DataGrid2); + +// @ts-ignore +DataGrid.Naked = DataGrid2; diff --git a/packages/grid/data-grid/tsconfig.build.json b/packages/grid/data-grid/tsconfig.build.json new file mode 100644 index 0000000000000..0c5e11f717105 --- /dev/null +++ b/packages/grid/data-grid/tsconfig.build.json @@ -0,0 +1,22 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "baseUrl": "./", + "declaration": true, + "declarationDir": "./dist", + "module": "es6", + "noImplicitAny": false, + "strict": true, + "outDir": "./dist", + "target": "es6", + "sourceMap": true, + "build": true + }, + "include": ["src"], + "exclude": ["__tests__", "**/*.test.ts", "node_modules", "lib"], + "references": [ + { + "path": "../x-grid-modules" + } + ] +} diff --git a/packages/grid/data-grid/tsconfig.json b/packages/grid/data-grid/tsconfig.json index 0c5e11f717105..46440e0085b57 100644 --- a/packages/grid/data-grid/tsconfig.json +++ b/packages/grid/data-grid/tsconfig.json @@ -1,19 +1,10 @@ { "extends": "../../../tsconfig.json", "compilerOptions": { - "baseUrl": "./", - "declaration": true, - "declarationDir": "./dist", - "module": "es6", - "noImplicitAny": false, - "strict": true, - "outDir": "./dist", - "target": "es6", - "sourceMap": true, - "build": true + "noEmit": true, + "types": ["mocha"] }, "include": ["src"], - "exclude": ["__tests__", "**/*.test.ts", "node_modules", "lib"], "references": [ { "path": "../x-grid-modules" diff --git a/packages/grid/x-grid/rollup.config.js b/packages/grid/x-grid/rollup.config.js index f262a948fd58a..a8cdf15b7dac1 100644 --- a/packages/grid/x-grid/rollup.config.js +++ b/packages/grid/x-grid/rollup.config.js @@ -39,7 +39,7 @@ export default [ cleaner({ targets: ['./dist/'], }), - typescript({ build: true }), + typescript(), !production && sourceMaps(), production && terser(), ], diff --git a/test/utils/index.js b/test/utils/index.ts similarity index 100% rename from test/utils/index.js rename to test/utils/index.ts diff --git a/test/utils/licenseKey.js b/test/utils/licenseKey.ts similarity index 100% rename from test/utils/licenseKey.js rename to test/utils/licenseKey.ts diff --git a/test/utils/licenseRelease.js b/test/utils/licenseRelease.ts similarity index 100% rename from test/utils/licenseRelease.js rename to test/utils/licenseRelease.ts diff --git a/yarn.lock b/yarn.lock index 18e1dd9935cf3..56491ca03f25b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4775,6 +4775,11 @@ resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6" integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY= +"@types/mocha@^8.0.3": + version "8.0.3" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-8.0.3.tgz#51b21b6acb6d1b923bbdc7725c38f9f455166402" + integrity sha512-vyxR57nv8NfcU0GZu8EUXZLTbCMupIUwy95LJ6lllN+JRPG25CwMHoB1q5xKh8YKhQnHYRAn4yW2yuHbf/5xgg== + "@types/node-fetch@^2.5.4": version "2.5.7" resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"