test: demo snapshot testing (#3916)

* Run snapshot testing against all demos

* Split demo tests

* ignore coverage folder

* Upgrade antd-demo-jest

* enable cache

* intergate with coveralls.io

* Add node test

* Set worker to 2

https://github.com/facebook/jest/issues/1742

* config coverage

* Set default supportServerRender to true
This commit is contained in:
Wei Zhu 2016-11-22 13:43:53 +08:00 committed by Benjy Cui
parent 4b1722e95d
commit d20572bdab
60 changed files with 219 additions and 18 deletions

View File

@ -1,3 +1,6 @@
{ {
"presets": ["es2015", "react", "stage-0"] "presets": ["es2015", "react", "stage-0"],
"plugins": [
"add-module-exports"
]
} }

1
.gitignore vendored
View File

@ -30,3 +30,4 @@ config/base.yaml
components/**/*.js components/**/*.js
components/**/*.jsx components/**/*.jsx
/.vscode/ /.vscode/
/coverage

15
.jest.node.json Normal file
View File

@ -0,0 +1,15 @@
{
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"md"
],
"transform": {
"\\.tsx?$": "node_modules/typescript-babel-jest",
"tests/.*\\.js$": "node_modules/babel-jest",
"\\.md$": "node_modules/antd-demo-jest"
},
"testRegex": "/tests/node/.*\\.test\\.js$",
"testEnvironment": "node"
}

View File

@ -4,3 +4,6 @@ language: node_js
node_js: node_js:
- "6" - "6"
after_script:
- cat ./coverage/lcov.info | node_modules/coveralls/bin/coveralls.js

View File

@ -86,7 +86,7 @@ for (let i = 0; i < 100; i++) {
data.push({ data.push({
key: i, key: i,
name: 'John Brown', name: 'John Brown',
age: Math.ceil(Math.random() * 100), age: i + 1,
street: 'Lake Park', street: 'Lake Park',
building: 'C', building: 'C',
number: 2035, number: 2035,

View File

@ -22,12 +22,12 @@ for (let i = 0; i < 20; i++) {
key: i.toString(), key: i.toString(),
title: `content${i + 1}`, title: `content${i + 1}`,
description: `description of content${i + 1}`, description: `description of content${i + 1}`,
disabled: Math.random() * 3 < 1, disabled: i % 3 < 1,
}); });
} }
const targetKeys = mockData const targetKeys = mockData
.filter(() => Math.random() * 2 > 1) .filter(item => +item.key % 3 > 1)
.map(item => item.key); .map(item => item.key);
const App = React.createClass({ const App = React.createClass({

View File

@ -71,6 +71,7 @@ export default class Upload extends React.Component<UploadProps, any> {
listType: 'text', // or pictrue listType: 'text', // or pictrue
className: '', className: '',
disabled: false, disabled: false,
supportServerRender: true,
}; };
recentUploadStatus: boolean | PromiseLike<any>; recentUploadStatus: boolean | PromiseLike<any>;

View File

@ -78,20 +78,22 @@
"devDependencies": { "devDependencies": {
"@types/react": "~0.14.41", "@types/react": "~0.14.41",
"@types/react-dom": "~0.14.18", "@types/react-dom": "~0.14.18",
"antd-demo-jest": "^1.0.5",
"antd-tools": "0.14.2", "antd-tools": "0.14.2",
"babel-cli": "^6.18.0", "babel-cli": "^6.18.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"babel-eslint": "^7.1.0", "babel-eslint": "^7.1.0",
"babel-jest": "^17.0.0", "babel-jest": "^17.0.0",
"babel-plugin-import": "^1.0.0", "babel-plugin-import": "^1.0.0",
"babel-plugin-transform-runtime": "~6.15.0", "babel-plugin-transform-runtime": "~6.15.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"bisheng": "^0.17.0", "bisheng": "^0.17.0",
"bisheng-plugin-antd": "~0.6.0", "bisheng-plugin-antd": "~0.6.0",
"bisheng-plugin-description": "^0.1.1", "bisheng-plugin-description": "^0.1.1",
"bisheng-plugin-react": "^0.3.0", "bisheng-plugin-react": "^0.3.0",
"bisheng-plugin-toc": "^0.3.0", "bisheng-plugin-toc": "^0.3.0",
"coveralls": "^2.11.15",
"css-split-webpack-plugin": "^0.2.1", "css-split-webpack-plugin": "^0.2.1",
"dekko": "^0.2.0", "dekko": "^0.2.0",
"dora-plugin-upload": "^0.3.1", "dora-plugin-upload": "^0.3.1",
@ -107,6 +109,7 @@
"eslint-plugin-markdown": "*", "eslint-plugin-markdown": "*",
"eslint-plugin-react": "^6.1.2", "eslint-plugin-react": "^6.1.2",
"eslint-tinker": "^0.4.0", "eslint-tinker": "^0.4.0",
"glob": "^7.1.1",
"history": "^4.4.0", "history": "^4.4.0",
"jest": "^17.0.1", "jest": "^17.0.1",
"jest-cli": "^17.0.0", "jest-cli": "^17.0.0",
@ -133,7 +136,8 @@
"react-sublime-video": "^0.2.0", "react-sublime-video": "^0.2.0",
"reqwest": "^2.0.5", "reqwest": "^2.0.5",
"typescript-babel-jest": "^0.1.5", "typescript-babel-jest": "^0.1.5",
"values.js": "^1.0.3" "values.js": "^1.0.3",
"xhr2": "^0.1.3"
}, },
"babel": { "babel": {
"presets": [ "presets": [
@ -143,7 +147,7 @@
] ]
}, },
"scripts": { "scripts": {
"test": "npm run lint && npm run dist && npm run jest && npm run site", "test": "npm run lint && npm run dist && npm run jest -- --coverage -w 2 && npm run jest:node -- -w 2 && npm run site",
"lint": "npm run tslint && npm run eslint && npm run demolint && npm run lesshint", "lint": "npm run tslint && npm run eslint && npm run demolint && npm run lesshint",
"tslint": "antd-tools run ts-lint && npm run compile && rm -rf lib", "tslint": "antd-tools run ts-lint && npm run compile && rm -rf lib",
"eslint": "eslint test site scripts ./.eslintrc.js ./webpack.config.js --ext '.js,.jsx,.tsx' --ignore-pattern '!.eslintrc.js'", "eslint": "eslint test site scripts ./.eslintrc.js ./webpack.config.js --ext '.js,.jsx,.tsx' --ignore-pattern '!.eslintrc.js'",
@ -151,7 +155,8 @@
"lesshint": "lesshint components -r scripts/lesshint-report.js", "lesshint": "lesshint components -r scripts/lesshint-report.js",
"eslint-fix": "eslint --fix test site scripts ./.eslintrc.js ./webpack.config.js --ext '.js,.jsx,.tsx' --ignore-pattern '!.eslintrc.js' && eslint-tinker ./components/*/demo/*.md", "eslint-fix": "eslint --fix test site scripts ./.eslintrc.js ./webpack.config.js --ext '.js,.jsx,.tsx' --ignore-pattern '!.eslintrc.js' && eslint-tinker ./components/*/demo/*.md",
"jest": "jest --no-cache", "jest": "jest",
"jest:node": "jest --config .jest.node.json",
"clean": "antd-tools run clean", "clean": "antd-tools run clean",
"dist": "antd-tools run dist && node ./tests/dekko/dist.test.js", "dist": "antd-tools run dist && node ./tests/dekko/dist.test.js",
@ -174,19 +179,29 @@
"tsx", "tsx",
"js", "js",
"jsx", "jsx",
"json" "json",
"md"
], ],
"modulePathIgnorePatterns": [ "modulePathIgnorePatterns": [
"/_site/" "/_site/"
], ],
"testPathIgnorePatterns": [ "testPathIgnorePatterns": [
"dekko", "dekko",
"/node_modules/" "/node_modules/",
"node"
], ],
"transform": { "transform": {
".*": "node_modules/typescript-babel-jest" "\\.tsx?$": "node_modules/typescript-babel-jest",
"tests/.*\\.js$": "node_modules/babel-jest",
"\\.md$": "node_modules/antd-demo-jest"
}, },
"testRegex": "(/tests/.*|\\.(test|spec))\\.(js)$" "testRegex": "/tests/.*\\.test\\.js$",
"coveragePathIgnorePatterns": [
"/node_modules/",
"components/.*/demo",
"/dist/",
"/tests/"
]
}, },
"pre-commit": [ "pre-commit": [
"lint" "lint"

3
tests/affix/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('affix');

3
tests/alert/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('alert');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('anchor');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('auto-complete');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('back-top');

3
tests/badge/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('badge');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('breadcrumb');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('button');

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { render } from 'enzyme'; import { render } from 'enzyme';
import { renderToJson } from 'enzyme-to-json'; import { renderToJson } from 'enzyme-to-json';
import Button from '../components/button/button'; import Button from '../../components/button';
describe('Button', function() { describe('Button', function() {
it('renders correctly', () => { it('renders correctly', () => {

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('calendar');

3
tests/card/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('card');

View File

@ -0,0 +1,12 @@
import demoTest from '../shared/demoTest';
// https://github.com/WickyNilliams/enquire.js/issues/82
window.matchMedia = window.matchMedia || function() {
return {
matches : false,
addListener : function() {},
removeListener: function() {}
};
};
demoTest('carousel');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('checkbox');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('collapse');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('date-picker');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('dropdown');

3
tests/form/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('form');

3
tests/grid/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('grid');

View File

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import TestUtils from 'react-addons-test-utils'; import TestUtils from 'react-addons-test-utils';
import { wrap } from 'react-stateless-wrapper'; import { wrap } from 'react-stateless-wrapper';
import AntIcon from '../components/icon/index'; import AntIcon from '../../components/icon/index';
const Icon = wrap(AntIcon); const Icon = wrap(AntIcon);
describe('Icon', function() { describe('Icon', function() {

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('input-number');

3
tests/input/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('input');

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import TestUtils from 'react-addons-test-utils'; import TestUtils from 'react-addons-test-utils';
let { Col, Row } = require('../components/grid/index'); let { Col, Row } = require('../../components/grid/index');
describe('Grid', function() { describe('Grid', function() {
it('should render Col', () => { it('should render Col', () => {

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('locale-provider');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('mention', { skip: true });

3
tests/menu/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('menu', { skip: true });

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('message');

3
tests/modal/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('modal');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('notification');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('pagination');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('popconfirm');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('popover');

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import TestUtils from 'react-addons-test-utils'; import TestUtils from 'react-addons-test-utils';
import Popover from '../components/popover/index'; import Popover from '../../components/popover/index';
describe('Popover', function() { describe('Popover', function() {
it('should show overlay when trigger is clicked', () => { it('should show overlay when trigger is clicked', () => {

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('progress');

3
tests/radio/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('radio');

3
tests/rate/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('rate');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('select');

16
tests/shared/demoTest.js Normal file
View File

@ -0,0 +1,16 @@
import glob from 'glob'
import { render } from 'enzyme';
import { renderToJson } from 'enzyme-to-json';
export default function demoTest(component, options = {}) {
const testMethod = options.skip ? test.skip : test;
const files = glob.sync(`./components/${component}/demo/*.md`);
files.forEach(file => {
testMethod(`renders ${file} correctly`, () => {
const demo = require('../.' + file);
const wrapper = render(demo);
expect(renderToJson(wrapper)).toMatchSnapshot();
});
});
}

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('slider');

3
tests/spin/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('spin');

3
tests/steps/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('steps');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('switch');

3
tests/table/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('table');

3
tests/tabs/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('tabs');

3
tests/tag/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('tag');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('time-picker');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('timeline');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('tooltip');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('transfer');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('tree-select');

3
tests/tree/demo.test.js Normal file
View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('tree');

View File

@ -0,0 +1,3 @@
import demoTest from '../shared/demoTest';
demoTest('upload');