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 Aug 2, 2020
1 parent d9b15ca commit 1fdae08
Show file tree
Hide file tree
Showing 33 changed files with 3,071 additions and 137 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 @@ -53,6 +61,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 @@ -67,11 +90,30 @@ jobs:
- run:
name: Lint JSON
command: yarn jsonlint
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', '*.test.ts'],
env: {
mocha: true,
},
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
.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')],
};
81 changes: 81 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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: ['./'],
extensions: ['.js', '.ts', '.tsx'],
alias: defaultAlias,
},
],
],
},
test: {
sourceMaps: 'both',
plugins: [
[
'babel-plugin-module-resolver',
{
root: ['./'],
extensions: ['.js', '.ts', '.tsx'],
alias: defaultAlias,
},
],
],
},
},
};
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"version": "0.1.0",
"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 @@ -17,25 +20,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": "^9.0.0",
"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": "yarn eslint && yarn jsonlint",
"eslint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx",
"eslint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx"
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
Loading

0 comments on commit 1fdae08

Please sign in to comment.