From 4ada4a5a336219e1ff74e90145aea86b608e104d Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Fri, 6 Nov 2020 10:35:26 +0100 Subject: [PATCH] [test] Smoke test --- packages/grid/data-grid/src/DataGrid.test.tsx | 118 ------------------ packages/grid/x-grid/src/XGrid.test.tsx | 9 ++ test/karma.conf.js | 1 + test/karma.tests.js | 52 +++++++- test/utils/consoleError.js | 17 --- yarn.lock | 4 +- 6 files changed, 62 insertions(+), 139 deletions(-) delete mode 100644 test/utils/consoleError.js diff --git a/packages/grid/data-grid/src/DataGrid.test.tsx b/packages/grid/data-grid/src/DataGrid.test.tsx index 6fd967c0236f8..64edc84b33e7a 100644 --- a/packages/grid/data-grid/src/DataGrid.test.tsx +++ b/packages/grid/data-grid/src/DataGrid.test.tsx @@ -181,122 +181,4 @@ describe('', () => { ); }); }); - - describe('column width', () => { - before(function beforeHook() { - if (/jsdom/.test(window.navigator.userAgent)) { - // Need layouting - this.skip(); - } - }); - - it('should set the columns width to 100px by default', () => { - const rows = [ - { - id: 1, - username: 'John Doe', - age: 30, - }, - ]; - - const columns = [ - { - field: 'id', - }, - { - field: 'name', - }, - { - field: 'age', - }, - ]; - - const { getAllByRole } = render( -
- -
, - ); - - const DOMColumns = getAllByRole('columnheader'); - DOMColumns.forEach((col) => { - // @ts-expect-error need to migrate helpers to TypeScript - expect(col).toHaveInlineStyle({ width: '100px' }); - }); - }); - - it('should set the columns width value to what is provided', () => { - const rows = [ - { - id: 1, - username: 'John Doe', - age: 30, - }, - ]; - - const colWidthValues = [50, 50, 200]; - const columns = [ - { - field: 'id', - width: colWidthValues[0], - }, - { - field: 'name', - width: colWidthValues[1], - }, - { - field: 'age', - width: colWidthValues[2], - }, - ]; - - const { getAllByRole } = render( -
- -
, - ); - - const DOMColumns = getAllByRole('columnheader'); - DOMColumns.forEach((col, index) => { - // @ts-expect-error need to migrate helpers to TypeScript - expect(col).toHaveInlineStyle({ width: `${colWidthValues[index]}px` }); - }); - }); - - it('should set the first column to be twice as wide as the second one', () => { - const rows = [ - { - id: 1, - username: 'John Doe', - age: 30, - }, - ]; - - const columns = [ - { - field: 'id', - flex: 1, - }, - { - field: 'name', - flex: 0.5, - }, - ]; - - render( -
- -
, - ); - - const firstColumn = document.querySelector('[role="columnheader"][aria-colindex="1"]'); - const secondColumn: HTMLElement | null = document.querySelector( - '[role="columnheader"][aria-colindex="2"]', - ); - const secondColumnWidthVal = secondColumn!.style.width.split('px')[0]; - // @ts-expect-error need to migrate helpers to TypeScript - expect(firstColumn).toHaveInlineStyle({ - width: `${2 * parseInt(secondColumnWidthVal, 10)}px`, - }); - }); - }); }); diff --git a/packages/grid/x-grid/src/XGrid.test.tsx b/packages/grid/x-grid/src/XGrid.test.tsx index 61d15d4579469..967d22c2e93a4 100644 --- a/packages/grid/x-grid/src/XGrid.test.tsx +++ b/packages/grid/x-grid/src/XGrid.test.tsx @@ -105,6 +105,15 @@ describe('', () => { container.firstChild.firstChild.firstChild, ); }); + + it('should not fail after scheduled tasks are run', async () => { + render( +
+ +
, + ); + await sleep(0); + }); }); describe('keyboard', () => { diff --git a/test/karma.conf.js b/test/karma.conf.js index ad97ab9c4d2f1..739c6ce48b0e3 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -56,6 +56,7 @@ module.exports = function setKarmaConfig(config) { 'process.env': { NODE_ENV: JSON.stringify('test'), CI: JSON.stringify(process.env.CI), + KARMA: JSON.stringify(true), }, }), ], diff --git a/test/karma.tests.js b/test/karma.tests.js index 3efa3970ad7a6..7312ca3881b8c 100644 --- a/test/karma.tests.js +++ b/test/karma.tests.js @@ -1,7 +1,55 @@ +/* eslint-env mocha */ import './utils/init'; -import consoleError from './utils/consoleError'; +import { createMochaHooks } from '@material-ui/monorepo/test/utils/mochaHooks'; -consoleError(); +const mochaHooks = createMochaHooks(window.Mocha); + +before(function beforeAllHook() { + mochaHooks.beforeAll.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +after(function afterAllHook() { + mochaHooks.afterAll.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +beforeEach(function beforeEachHook() { + mochaHooks.beforeEach.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +afterEach(function afterEachHook() { + mochaHooks.afterEach.forEach((mochaHook) => { + mochaHook.call(this); + }); +}); + +// Ensure that uncaught exceptions between tests result in the tests failing. +// This works around an issue with mocha / karma-mocha, see +// https://github.com/karma-runner/karma-mocha/issues/227 +let pendingError = null; +let pendingErrorNotice = null; + +window.addEventListener('error', event => { + pendingError = event.error; + pendingErrorNotice = 'An uncaught exception was thrown between tests'; +}); + +window.addEventListener('unhandledrejection', event => { + pendingError = event.reason; + pendingErrorNotice = 'An uncaught promise rejection occurred between tests'; +}); + +afterEach(() => { + if (pendingError) { + console.error(pendingErrorNotice); + throw pendingError; + } +}); const packagesContext = require.context('../packages', true, /\.test\.tsx$/); packagesContext.keys().forEach(packagesContext); diff --git a/test/utils/consoleError.js b/test/utils/consoleError.js deleted file mode 100644 index 1b5aa26ebf762..0000000000000 --- a/test/utils/consoleError.js +++ /dev/null @@ -1,17 +0,0 @@ -/* eslint-disable no-console */ -// Makes sure the tests fails when a PropType validation fails. -function consoleError() { - console.error = (...args) => { - // Can't use log as karma is not displaying them. - console.info(...args); - throw new Error(...args); - }; - - console.warn = (...args) => { - // Can't use log as karma is not displaying them. - console.info(...args); - throw new Error(...args); - }; -} - -module.exports = consoleError; diff --git a/yarn.lock b/yarn.lock index 60a00fe97d0f7..fb4b9591bbe44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2735,8 +2735,8 @@ resolved "https://github.com/mui-org/material-ui.git#3c078f2f6943976fc4d3ed5d886bbfa0f391e4a2" "@material-ui/monorepo@https://github.com/mui-org/material-ui.git#next": - version "5.0.0-alpha.13" - resolved "https://github.com/mui-org/material-ui.git#13f3e9d8db81b40e1b08f43e4d45e37f3926c37d" + version "5.0.0-alpha.15" + resolved "https://github.com/mui-org/material-ui.git#c500fc3faf873142b9124319cebf728dd9a12cc5" "@material-ui/styles@^4.10.0": version "4.10.0"