Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Add visual regression tests #1081

Merged
merged 17 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 71 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,69 @@ defaults: &defaults

commands:
install_js:
parameters:
browsers:
type: boolean
default: false
description: 'Set to true if you intend to any browser (e.g. with playwright).'

steps:
- run:
name: View install environment
command: |
node --version
yarn --version
- restore_cache:
name: Restore yarn cache
keys:
- v6-yarn-sha-{{ checksum "yarn.lock" }}
- v6-yarn-sha-
- v7-yarn-{{ checksum "yarn.lock" }}
- v7-yarn-
- run:
name: Set yarn cache folder
command: |
# Keep path in sync with `save_cache` for key "v6-yarn-sha-"
yarn config set cache-folder ~/.cache/yarn
# Keep path in sync with `save_cache` for key "v7-yarn-"
yarn config set cache-folder /tmp/yarn-cache
# Debug information
yarn cache dir
yarn cache list
- when:
condition: << parameters.browsers >>
steps:
- run:
name: Prepare playwright hash
command: yarn --json list --pattern playwright > /tmp/playwright_info.json
- store_artifacts:
name: Debug playwright hash
path: /tmp/playwright_info.json
- restore_cache:
name: Restore playwright cache
keys:
- v5-playwright-{{ arch }}-{{ checksum "/tmp/playwright_info.json" }}
- v5-playwright-{{ arch }}-
- v5-playwright-
- run:
name: Install js dependencies
command: yarn install --verbose
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
environment:
PLAYWRIGHT_BROWSERS_PATH: /tmp/pw-browsers
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: <<# parameters.browsers >>0<</ parameters.browsers >><<^ parameters.browsers >>1<</ parameters.browsers >>
- save_cache:
name: Save yarn cache
key: v7-yarn-{{ checksum "yarn.lock" }}
paths:
# Keep path in sync with "Set yarn cache folder"
# Can't use environment variables for `save_cache` paths (tested in https://app.circleci.com/pipelines/github/mui-org/material-ui/37813/workflows/5b1e207f-ac8b-44e7-9ba4-d0f9a01f5c55/jobs/223370)
- /tmp/yarn-cache
- when:
condition: << parameters.browsers >>
steps:
- save_cache:
name: Save playwright cache
key: v5-playwright-{{ arch }}-{{ checksum "/tmp/playwright_info.json" }}
paths:
# Keep path in sync with "Install js dependencies"
# Can't use environment variables for `save_cache` paths (tested in https://app.circleci.com/pipelines/github/mui-org/material-ui/37813/workflows/5b1e207f-ac8b-44e7-9ba4-d0f9a01f5c55/jobs/223370)
- /tmp/pw-browsers

jobs:
checkout:
Expand Down Expand Up @@ -105,10 +139,14 @@ jobs:
command: yarn jsonlint
test_browser:
<<: *defaults
docker:
- image: mcr.microsoft.com/playwright:bionic
environment:
NODE_ENV: development # Needed if playwright is in `devDependencies`
steps:
- checkout
- install_js
- prepare_chrome_headless
- install_js:
browsers: true
- run:
name: Tests real browsers
command: yarn test:karma
Expand All @@ -130,6 +168,22 @@ jobs:
- run:
name: Tests TypeScript definitions
command: yarn typescript
test_regressions:
<<: *defaults
docker:
- image: mcr.microsoft.com/playwright:bionic
environment:
NODE_ENV: development # Needed if playwright is in `devDependencies`
steps:
- checkout
- install_js:
browsers: true
- run:
name: Run visual regression tests
command: xvfb-run yarn test:regressions
- run:
name: Upload screenshots to Argos CI
command: yarn test:argos
workflows:
version: 2
pipeline:
Expand All @@ -147,3 +201,6 @@ workflows:
- test_types:
requires:
- checkout
- test_regressions:
requires:
- checkout
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ __diff_output__
/coverage
/docs/.next
/docs/export
/test/regressions/screenshots
build
# TODO `dist` should be replaced with `build`, per convention
dist
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
"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",
"test:regressions": "cross-env NODE_ENV=production yarn test:regressions:build && concurrently --success first --kill-others \"yarn test:regressions:run\" \"yarn test:regressions:server\"",
"test:regressions:build": "webpack --config test/regressions/webpack.config.js",
"test:regressions:dev": "concurrently \"yarn test:regressions:build --watch\" \"yarn test:regressions:server\"",
"test:regressions:run": "mocha --config test/regressions/.mocharc.js --delay 'test/regressions/**/*.test.js'",
"test:regressions:server": "serve test/regressions",
"test:argos": "node ./scripts/pushArgos.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a way to reduce the number of scripts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only have to run one script yarn test:regressions locally. The others are here to help debug (when working on improving the regression generation tool.

"lint": "yarn eslint && yarn jsonlint",
"eslint": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx",
"eslint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx",
Expand Down Expand Up @@ -64,12 +70,14 @@
"@types/styled-components": "^5.0.1",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"argos-cli": "^0.3.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-optimize-clsx": "^2.6.1",
"babel-plugin-transform-rename-import": "^2.3.0",
"chai": "^4.2.0",
"chai-dom": "^1.8.2",
"compression-webpack-plugin": "^6.0.2",
"concurrently": "^5.3.0",
"cross-env": "^7.0.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
Expand All @@ -92,12 +100,12 @@
"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",
"playwright": "^1.6.1",
"prettier": "^2.0.5",
"pretty-format-v24": "npm:pretty-format@24",
"react": "^16.13.1",
Expand All @@ -111,6 +119,7 @@
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.30.0",
"sinon": "^9.0.2",
"serve": "^11.3.2",
"stylelint": "^13.7.2",
"stylelint-config-standard": "^20.0.0",
"stylelint-processor-styled-components": "^1.10.0",
Expand Down
52 changes: 0 additions & 52 deletions packages/demo-app/src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ const GlobalStyle = createGlobalStyle`
width: 100%;
}

.main-container {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to change that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing dead CSS code (at least, it's the objective)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I think it should be done in the demo move to the doc PR...

Copy link
Member Author

@oliviertassinari oliviertassinari Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't intend to break the demo-app if it's what you assume. I can definitely revert.

position: relative;
flex-grow: 1;
box-sizing: border-box;
}

.fill-space,
.fill-abs,
.fill {
Expand All @@ -49,16 +43,6 @@ const GlobalStyle = createGlobalStyle`
right: 0;
}

.flex-col {
display: flex;
flex-direction: column;
}

.flex-row {
display: flex;
flex-direction: row;
}

.grow {
flex-grow: 1;
}
Expand All @@ -67,45 +51,9 @@ const GlobalStyle = createGlobalStyle`
justify-content: center;
}

.action-bar {
display: flex;
justify-content: center;

button {
margin-right: 20px;
}
}

.storybook-img {
width: 30px;
}

@media screen and (max-width: 768px) {
.big-device {
display: none !important;
}
}

.negative {
color: #d20704;
}

.positive {
color: #008508;
}

.info-icon {
color: #2196f3;
align-self: center;
}

.bad {
background: rgba(255, 128, 171, 0.4);
}

.good {
background: rgba(185, 246, 202, 0.4);
}
`;

const StyledApp = styled.div`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import './style/real-data-stories.css';
import {
generateTotalPrice,
randomCommodity,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import './style/real-data-stories.css';
import {
generateName,
randomAvatar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import {
TAXCODE_OPTIONS,
} from './static-data';

const chance = globalChance();
const chanceId = globalChance();
let chance;

if (process.env.DISABLE_CHANCE_RANDOM) {
chance = globalChance(() => 0.5);
} else {
chance = chanceId;
}

function dateFuture(years?: number, refDate?: string) {
let date = new Date();
Expand Down Expand Up @@ -67,17 +74,17 @@ function datePast(years?: number, refDate?: string) {
return date;
}

export const random = (min: number, max: number): number => Math.random() * (max - min) + min;
export const random = (min: number, max: number): number => chance.random() * (max - min) + min;
export const randomInt = (min: number, max: number): number => Number(random(min, max).toFixed());
export const randomPrice = (min = 0, max = 100000): number => random(min, max);
export const randomRate = (): number => random(0, 1);
export const randomDate = (start, end) =>
new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
new Date(start.getTime() + chance.random() * (end.getTime() - start.getTime()));
export const getDate = () => randomDate(new Date(2012, 0, 1), new Date());
export const randomArrayItem = (arr: any[]) => arr[random(0, arr.length - 1).toFixed()];

export const randomColor = () => randomArrayItem(COLORS);
export const randomId = () => chance.guid();
export const randomId = () => chanceId.guid();
export const randomDesk = () => `D-${chance.integer({ min: 0, max: 10000 })}`;
export const randomCommodity = () => randomArrayItem(COMMODITY_OPTIONS);
export const randomTraderName = () => chance.name();
Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions packages/grid/x-grid-data-generator/src/useDemoData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ function extrapolateSeed(rowLength, columns, data) {
return { ...data, rows };
}

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

function deepFreeze(object) {
// Retrieve the property names defined on object
const propNames = Object.getOwnPropertyNames(object);
Expand Down Expand Up @@ -94,7 +86,6 @@ export const useDemoData = (options: DemoDataOptions): DemoDataReturnType => {
let active = true;

(async () => {
await sleep(100);
let columns = options.dataSet === 'Commodity' ? getCommodityColumns() : getEmployeeColumns();

if (options.maxColumns) {
Expand All @@ -105,7 +96,6 @@ export const useDemoData = (options: DemoDataOptions): DemoDataReturnType => {

if (rowLength > 1000) {
newData = await getRealData(1000, columns);
await sleep(100);
newData = extrapolateSeed(rowLength, columns, newData);
} else {
newData = await getRealData(rowLength, columns);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
8 changes: 4 additions & 4 deletions packages/storybook/src/stories/grid-pagination.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
} as Meta;

export function PaginationDefault() {
const data = useData(2000, 200);
const data = useData(200, 20);

return (
<div className="grid-container">
Expand All @@ -34,7 +34,7 @@ export function PaginationDefault() {
}

export function PageSize100() {
const data = useData(2000, 200);
const data = useData(2000, 20);

return (
<div className="grid-container">
Expand All @@ -44,7 +44,7 @@ export function PageSize100() {
}

export const PaginationArgs: Story = (args) => {
const data = useData(2000, 200);
const data = useData(200, 20);

return <XGrid rows={data.rows} columns={data.columns} {...args} />;
};
Expand All @@ -61,7 +61,7 @@ PaginationArgs.args = {
};

export function HiddenPagination() {
const data = useData(2000, 200);
const data = useData(200, 20);

return (
<div className="grid-container">
Expand Down
Loading