Skip to content

Commit

Permalink
[test] Add e2e test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 26, 2020
1 parent 9451137 commit 95e8006
Show file tree
Hide file tree
Showing 32 changed files with 3,013 additions and 92 deletions.
42 changes: 42 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ commands:
- run:
name: Install js dependencies
command: yarn
prepare_chrome_headless:
steps:
- run:
name: Install dependencies for Chrome Headless
# From https://github.com/GoogleChrome/puppeteer/blob/811415bc8c47f7882375629b57b3fe186ad61ed4/docs/troubleshooting.md#chrome-headless-doesnt-launch
command: |
sudo apt-get update
sudo apt-get install -y --force-yes gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
jobs:
checkout:
Expand All @@ -50,6 +58,21 @@ jobs:
key: v2-yarn-sha-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn/v4
test_unit:
<<: *defaults
steps:
- checkout
- install_js
- run:
name: Tests fake browser
command: yarn test:coverage
- run:
name: Check coverage generated
command: |
if ! [[ -s coverage/lcov.info ]]
then
exit 1
fi
test_static:
<<: *defaults
steps:
Expand All @@ -61,11 +84,30 @@ jobs:
- run:
name: Lint
command: yarn lint:ci
test_browser:
<<: *defaults
steps:
- checkout
- install_js
- prepare_chrome_headless
- run:
name: Tests real browsers
command: yarn test:karma
- store_artifacts:
# hardcoded in karma-webpack
path: /tmp/_karma_webpack_
destination: artifact-file
workflows:
version: 2
pipeline:
jobs:
- checkout
- test_unit:
requires:
- checkout
- test_static:
requires:
- checkout
- test_browser:
requires:
- checkout
12 changes: 5 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path');

module.exports = {
root: true, // So parent files don't get applied
globals: {
Expand All @@ -24,8 +26,8 @@ module.exports = {
plugins: ['react-hooks', '@typescript-eslint'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts', '.tsx', '.json'],
webpack: {
config: path.join(__dirname, './webpackBaseConfig.js'),
},
},
},
Expand Down Expand Up @@ -88,11 +90,7 @@ module.exports = {
},
overrides: [
{
files: [
'**/test-utils/**/*.js',
// matching the pattern of the test runner
'*.test.js',
],
files: ['*.test.tsx'],
env: {
mocha: true,
},
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
.idea
.vscode

__diff_output__
.DS_STORE
*.log
/.eslintcache
/.nyc_output
/coverage
dist
node_modules
__diff_output__
5 changes: 5 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
recursive: true,
reporter: 'dot',
require: [require.resolve('./test/utils/setup')],
};
79 changes: 79 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const path = require('path');

const errorCodesPath = path.resolve(__dirname, './docs/public/static/error-codes.json');
const missingError = process.env.MUI_EXTRACT_ERROR_CODES === 'true' ? 'write' : 'annotate';

let defaultPresets;

// We release a ES version of Material-UI.
// It's something that matches the latest official supported features of JavaScript.
// Nothing more (stage-1, etc), nothing less (require, etc).
if (process.env.BABEL_ENV === 'es') {
defaultPresets = [];
} else {
defaultPresets = [
[
'@babel/preset-env',
{
bugfixes: true,
modules: ['esm', 'production-umd'].includes(process.env.BABEL_ENV) ? false : 'commonjs',
},
],
];
}

const defaultAlias = {
'@material-ui/x-grid': './packages/grid/x-grid/src',
'@material-ui/x-grid-modules': './packages/grid/x-grid-modules/src',
'@material-ui/x-license': './packages/license/src',
'@material-ui/data-grid': './packages/grid/data-grid/src',
};

module.exports = {
presets: defaultPresets.concat(['@babel/preset-react', '@babel/preset-typescript']),
plugins: [
[
'babel-plugin-macros',
{
muiError: {
errorCodesPath,
missingError,
},
},
],
'babel-plugin-optimize-clsx',
['@babel/plugin-proposal-class-properties', { loose: true }],
['@babel/plugin-proposal-object-rest-spread', { loose: true }],
// any package needs to declare 7.4.4 as a runtime dependency. default is ^7.0.0
['@babel/plugin-transform-runtime', { version: '^7.4.4' }],
// for IE 11 support
'@babel/plugin-transform-object-assign',
],
ignore: [/@babel[\\|/]runtime/], // Fix a Windows issue.
env: {
coverage: {
plugins: [
'babel-plugin-istanbul',
[
'babel-plugin-module-resolver',
{
root: ['./'],
alias: defaultAlias,
},
],
],
},
test: {
sourceMaps: 'both',
plugins: [
[
'babel-plugin-module-resolver',
{
root: ['./'],
alias: defaultAlias,
},
],
],
},
},
};
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"author": "Material-UI Team",
"private": true,
"devDependencies": {
"@babel/plugin-transform-object-assign": "^7.10.4",
"@babel/plugin-transform-runtime": "^7.10.5",
"@babel/register": "^7.10.5",
"@material-ui/core": "^4.9.12",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.54",
Expand All @@ -20,25 +23,43 @@
"@types/styled-components": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-optimize-clsx": "^2.6.1",
"chai": "^4.2.0",
"chai-dom": "^1.8.2",
"cross-env": "^7.0.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^7.4.0",
"eslint-config-airbnb-typescript": "^8.0.2",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-webpack": "^0.12.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-mocha": "^7.0.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.8",
"format-util": "^1.0.5",
"glob-gitignore": "^1.0.14",
"jest": "^25.1.0",
"jest-cli": "^25.1.0",
"jest-transform-stub": "^2.0.0",
"karma": "^5.1.0",
"karma-browserstack-launcher": "^1.6.0",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^2.0.1",
"karma-mocha-reporter": "^2.2.5",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^4.0.2",
"lerna": "^3.20.2",
"mocha": "^8.0.1",
"nyc": "^15.1.0",
"prettier": "^2.0.5",
"pretty-format-v24": "npm:pretty-format@24",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"sinon": "^9.0.2",
"styled-components": "^5.1.0",
"stylelint": "^13.3.3",
"stylelint-config-recommended": "^3.0.0",
Expand All @@ -54,6 +75,11 @@
"start": "lerna run start --parallel",
"prettier": "node ./scripts/prettier.js",
"test": "lerna run test --parallel",
"test:coverage": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc mocha 'packages/**/*.test.tsx' --exclude '**/node_modules/**' && nyc report -r lcovonly",
"test:coverage:html": "cross-env NODE_ENV=test BABEL_ENV=coverage nyc mocha 'packages/**/*.test.tsx' --exclude '**/node_modules/**' && nyc report --reporter=html",
"test:karma": "cross-env NODE_ENV=test karma start test/karma.conf.js",
"test:unit": "cross-env NODE_ENV=test mocha 'packages/**/*.test.tsx' --exclude '**/node_modules/**'",
"test:watch": "yarn test:unit --watch",
"lint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx",
"lint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/grid/x-grid-modules/src/hooks/utils/useLogger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { isFunction } from '../../utils/utils';

const forceDebug = localStorage.getItem('DEBUG') != null;
// const forceDebug = localStorage.getItem('DEBUG') != null;
const forceDebug = false;
const isDebugging = process.env.NODE_ENV !== 'production' || forceDebug;

export interface Logger {
Expand Down
1 change: 0 additions & 1 deletion packages/grid/x-grid/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import typescript from 'rollup-plugin-typescript2';
// eslint-disable-next-line import/no-unresolved
import { generateReleaseInfo } from '@material-ui/x-license';
import cleaner from 'rollup-plugin-cleaner';
import sourceMaps from 'rollup-plugin-sourcemaps';
Expand Down
56 changes: 56 additions & 0 deletions packages/grid/x-grid/test/XGrid.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import * as React from 'react';
import { createClientRender, act } from 'test/utils';
import { expect } from 'chai';
import { XGrid } from '@material-ui/x-grid';

async function sleep(duration: number) {
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, duration);
});
}

describe('<XGrid />', () => {
const render = createClientRender();

it('should resize the width of the columns', async function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// TODO: Unclear why this fails. Not important
// since a browser test gives us more confidence anyway
this.skip();
}

function App(props) {
const { width = 300 } = props;
return (
<div style={{ width, height: 300 }}>
<XGrid
rows={[
{
brand: 'Nike',
},
]}
columns={[
{ field: 'id', hide: true },
{ field: 'brand', width: 100 },
]}
options={{ checkboxSelection: true }}
/>
</div>
);
}

const { container, setProps } = render(<App />);
let rect;
rect = container.querySelector('[role="row"][data-rowindex="0"]').getBoundingClientRect();
expect(rect.width).to.equal(300 - 2);
setProps({ width: 400 });
act(() => {
window.dispatchEvent(new window.Event('resize', {}));
});
await sleep(200);
rect = container.querySelector('[role="row"][data-rowindex="0"]').getBoundingClientRect();
expect(rect.width).to.equal(400 - 2);
});
});
Loading

0 comments on commit 95e8006

Please sign in to comment.