Revert "use ava and enzyme, replace jest" (#2144)

This commit is contained in:
偏右 2016-06-22 22:31:00 +08:00 committed by GitHub
parent 3cf0a59916
commit 193fa8e9d6
7 changed files with 178 additions and 134 deletions

View File

@ -74,8 +74,8 @@
}, },
"devDependencies": { "devDependencies": {
"antd-tools": "^0.8.0", "antd-tools": "^0.8.0",
"ava": "^0.15.2",
"babel-eslint": "^6.0.2", "babel-eslint": "^6.0.2",
"babel-jest": "^12.0.2",
"babel-plugin-antd": "^0.4.0", "babel-plugin-antd": "^0.4.0",
"bisheng": "^0.7.1", "bisheng": "^0.7.1",
"bisheng-plugin-antd": "0.1.0", "bisheng-plugin-antd": "0.1.0",
@ -84,7 +84,7 @@
"bisheng-plugin-toc": "0.2.0", "bisheng-plugin-toc": "0.2.0",
"dora-plugin-upload": "^0.3.1", "dora-plugin-upload": "^0.3.1",
"enquire.js": "^2.1.1", "enquire.js": "^2.1.1",
"enzyme": "^2.3.0", "es6-shim": "^0.35.0",
"eslint": "^2.2.0", "eslint": "^2.2.0",
"eslint-config-airbnb": "^9.0.1", "eslint-config-airbnb": "^9.0.1",
"eslint-plugin-babel": "^3.0.0", "eslint-plugin-babel": "^3.0.0",
@ -96,6 +96,7 @@
"history": "^2.0.1", "history": "^2.0.1",
"intl": "^1.2.2", "intl": "^1.2.2",
"intl-locales-supported": "^1.0.0", "intl-locales-supported": "^1.0.0",
"jest-cli": "^12.0.2",
"jsonml-to-react-component": "~0.2.0", "jsonml-to-react-component": "~0.2.0",
"jsonml.js": "^0.1.0", "jsonml.js": "^0.1.0",
"jsonp": "^0.2.0", "jsonp": "^0.2.0",
@ -115,9 +116,11 @@
"react-github-button": "^0.1.1", "react-github-button": "^0.1.1",
"react-intl": "^2.0.1", "react-intl": "^2.0.1",
"react-router": "^2.0.0", "react-router": "^2.0.0",
"react-stateless-wrapper": "^1.0.2",
"react-sublime-video": "^0.2.0", "react-sublime-video": "^0.2.0",
"reqwest": "^2.0.5", "reqwest": "^2.0.5",
"values.js": "^1.0.3" "values.js": "^1.0.3",
"webpack-babel-jest": "^1.0.4"
}, },
"scripts": { "scripts": {
"dist": "antd-tools run dist", "dist": "antd-tools run dist",
@ -133,25 +136,30 @@
"demolint": "RUN_ENV=DEMO eslint components/*/demo/*.md --ext '.md'", "demolint": "RUN_ENV=DEMO eslint components/*/demo/*.md --ext '.md'",
"lesshint": "lesshint components -r scripts/lesshint-report.js", "lesshint": "lesshint components -r scripts/lesshint-report.js",
"eslint-fix": "eslint --fix components test site scripts ./*.js --ext '.js,.jsx' && eslint-tinker ./components/*/demo/*.md", "eslint-fix": "eslint --fix components test site scripts ./*.js --ext '.js,.jsx' && eslint-tinker ./components/*/demo/*.md",
"test": "npm run lint && npm run dist && npm run ava", "test": "npm run lint && npm run dist && npm run jest",
"ava": "ava tests/*.test.js", "jest": "jest",
"pre-publish": "node ./scripts/prepub", "pre-publish": "node ./scripts/prepub",
"prepublish": "antd-tools run guard", "prepublish": "antd-tools run guard",
"pub": "antd-tools run update-self && antd-tools run pub", "pub": "antd-tools run update-self && antd-tools run pub",
"authors": "git log --format='%aN <%aE>' | sort -u | grep -v 'users.noreply.github.com' | grep -v 'gitter.im' | grep -v '.local>' | grep -v 'alibaba-inc.com' | grep -v 'alipay.com' | grep -v 'taobao.com' > AUTHORS.txt" "authors": "git log --format='%aN <%aE>' | sort -u | grep -v 'users.noreply.github.com' | grep -v 'gitter.im' | grep -v '.local>' | grep -v 'alibaba-inc.com' | grep -v 'alipay.com' | grep -v 'taobao.com' > AUTHORS.txt"
}, },
"ava": { "jest": {
"babel": { "moduleFileExtensions": [
"presets": [ "js",
"es2015", "jsx",
"stage-0", "json"
"react" ],
] "unmockedModulePathPatterns": [
}, "<rootDir>/node_modules/*"
"require": [ ],
"./tests/helpers/setup-browser-env.js", "modulePathIgnorePatterns": [
"babel-register" "/_site/"
] ],
"testPathIgnorePatterns": [
"/node_modules/"
],
"scriptPreprocessor": "<rootDir>/node_modules/webpack-babel-jest",
"testDirectoryName": "tests"
}, },
"pre-commit": [ "pre-commit": [
"lint" "lint"

View File

@ -1,23 +1,34 @@
import test from 'ava'; jest.unmock('../components/button/button');
jest.unmock('../components/icon/index');
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import TestUtils from 'react-addons-test-utils';
import Button from '../components/button/button'; import Button from '../components/button/button';
let buttonNode; describe('Button', function() {
let button;
let buttonNode;
test.beforeEach(() => { beforeEach(() => {
buttonNode = shallow(<Button>Follow</Button>); button = TestUtils.renderIntoDocument(
}); <Button>Follow</Button>
);
buttonNode = TestUtils.findRenderedDOMComponentWithTag(button, 'button');
});
test('should set the type to button by default', (t) => { it('should set the type to button by default', () => {
t.is(buttonNode.type(), 'button'); expect(buttonNode.type).toBe('button');
}); });
test('should set the default className to button', (t) => { it('should set the default className to button', () => {
t.true(buttonNode.hasClass('ant-btn')); expect(buttonNode.className).toBe('ant-btn');
}); });
test('should has a whitespace in two Chinese charactor', (t) => { it('should has a whitespace in two Chinese charactor', () => {
buttonNode = shallow(<Button>按钮</Button>); button = TestUtils.renderIntoDocument(
t.is(buttonNode.text(), '按 钮'); <Button>按钮</Button>
);
buttonNode = TestUtils.findRenderedDOMComponentWithTag(button, 'button');
expect(buttonNode.textContent).toBe('按 钮');
});
}); });

View File

@ -1,3 +0,0 @@
global.document = require('jsdom').jsdom('<body></body>');
global.window = document.defaultView;
global.navigator = window.navigator;

View File

@ -1,19 +1,27 @@
import test from 'ava'; jest.unmock('../components/icon/index');
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import TestUtils from 'react-addons-test-utils';
import Icon from '../components/icon/index'; import { wrap } from 'react-stateless-wrapper';
let iconNode; import AntIcon from '../components/icon/index';
const Icon = wrap(AntIcon);
test.beforeEach(() => { describe('Icon', function() {
iconNode = shallow( let icon;
let iconNode;
beforeEach(() => {
icon = TestUtils.renderIntoDocument(
<Icon type="appstore" className="my-icon-classname" /> <Icon type="appstore" className="my-icon-classname" />
); );
}); iconNode = TestUtils.findRenderedDOMComponentWithTag(icon, 'I');
});
test('should render to a <i class="xxx"></i>', (t) => { it('should render to a <i class="xxx"></i>', () => {
t.is(iconNode.type(), 'i'); expect(iconNode.tagName).toBe('I');
t.true(iconNode.hasClass('my-icon-classname')); expect(iconNode.className).toContain('my-icon-classname');
t.true(iconNode.hasClass('anticon')); expect(iconNode.className).toContain('anticon');
t.true(iconNode.hasClass('anticon-appstore')); expect(iconNode.className).toContain('anticon-appstore');
});
}); });

View File

@ -2,13 +2,13 @@
import React from 'react'; import React from 'react';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
import test from 'ava';
(function() { describe('antd dist files', function() {
const distFilesExisted = fs.existsSync(path.join(process.cwd(), '..', 'dist', 'antd.js')); const distFilesExisted = fs.existsSync(path.join(process.cwd(), 'dist', 'antd.js'));
if (!distFilesExisted) { if (!distFilesExisted) {
test(t => t.pass());
return; return;
} else {
jest.unmock('../dist/antd');
} }
// fixed jsdom miss // fixed jsdom miss
@ -29,64 +29,63 @@ import test from 'ava';
// https://github.com/ant-design/ant-design/issues/1638 // https://github.com/ant-design/ant-design/issues/1638
// https://github.com/ant-design/ant-design/issues/1968 // https://github.com/ant-design/ant-design/issues/1968
test('should has modules in antd', (t) => { it('should has modules in antd', () => {
t.true('Affix' in antd); expect('Affix' in antd).toBeTruthy();
t.true('Alert' in antd); expect('Alert' in antd).toBeTruthy();
t.true('Badge' in antd); expect('Badge' in antd).toBeTruthy();
t.true('Breadcrumb' in antd); expect('Breadcrumb' in antd).toBeTruthy();
t.true('Button' in antd); expect('Button' in antd).toBeTruthy();
t.true('Calendar' in antd); expect('Calendar' in antd).toBeTruthy();
t.true('Card' in antd); expect('Card' in antd).toBeTruthy();
t.true('Carousel' in antd); expect('Carousel' in antd).toBeTruthy();
t.true('Cascader' in antd); expect('Cascader' in antd).toBeTruthy();
t.true('Checkbox' in antd); expect('Checkbox' in antd).toBeTruthy();
t.true('Col' in antd); expect('Col' in antd).toBeTruthy();
t.true('Collapse' in antd); expect('Collapse' in antd).toBeTruthy();
t.true('DatePicker' in antd); expect('DatePicker' in antd).toBeTruthy();
t.true('Dropdown' in antd); expect('Dropdown' in antd).toBeTruthy();
t.true('Form' in antd); expect('Form' in antd).toBeTruthy();
t.true('Icon' in antd); expect('Icon' in antd).toBeTruthy();
t.true('Input' in antd); expect('Input' in antd).toBeTruthy();
t.true('InputNumber' in antd); expect('InputNumber' in antd).toBeTruthy();
t.true('LocaleProvider' in antd); expect('LocaleProvider' in antd).toBeTruthy();
t.true('Menu' in antd); expect('Menu' in antd).toBeTruthy();
t.true('message' in antd); expect('message' in antd).toBeTruthy();
t.true('Modal' in antd); expect('Modal' in antd).toBeTruthy();
t.true('notification' in antd); expect('notification' in antd).toBeTruthy();
t.true('Pagination' in antd); expect('Pagination' in antd).toBeTruthy();
t.true('Popconfirm' in antd); expect('Popconfirm' in antd).toBeTruthy();
t.true('Popover' in antd); expect('Popover' in antd).toBeTruthy();
t.true('Progress' in antd); expect('Progress' in antd).toBeTruthy();
t.true('QueueAnim' in antd); expect('QueueAnim' in antd).toBeTruthy();
t.true('Radio' in antd); expect('Radio' in antd).toBeTruthy();
t.true('Rate' in antd); expect('Rate' in antd).toBeTruthy();
t.true('Row' in antd); expect('Row' in antd).toBeTruthy();
t.true('Select' in antd); expect('Select' in antd).toBeTruthy();
t.true('Slider' in antd); expect('Slider' in antd).toBeTruthy();
t.true('Spin' in antd); expect('Spin' in antd).toBeTruthy();
t.true('Steps' in antd); expect('Steps' in antd).toBeTruthy();
t.true('Switch' in antd); expect('Switch' in antd).toBeTruthy();
t.true('Table' in antd); expect('Table' in antd).toBeTruthy();
t.true('Tabs' in antd); expect('Tabs' in antd).toBeTruthy();
t.true('Tag' in antd); expect('Tag' in antd).toBeTruthy();
t.true('TimePicker' in antd); expect('TimePicker' in antd).toBeTruthy();
t.true('Timeline' in antd); expect('Timeline' in antd).toBeTruthy();
t.true('Tooltip' in antd); expect('Tooltip' in antd).toBeTruthy();
t.true('Transfer' in antd); expect('Transfer' in antd).toBeTruthy();
t.true('Tree' in antd); expect('Tree' in antd).toBeTruthy();
t.true('TreeSelect' in antd); expect('TreeSelect' in antd).toBeTruthy();
t.true('Upload' in antd); expect('Upload' in antd).toBeTruthy();
t.true('Validation' in antd); expect('Validation' in antd).toBeTruthy();
}); });
// https://github.com/ant-design/ant-design/issues/1970 // https://github.com/ant-design/ant-design/issues/1970
// https://github.com/ant-design/ant-design/issues/1804 // https://github.com/ant-design/ant-design/issues/1804
test('should be compatible in IE8', (t) => { it('should be compatible in IE8', () => {
const antdJsContent = fs.readFileSync(path.join(process.cwd(), '..', 'dist', 'antd.js')); const antdJsContent = fs.readFileSync(path.join(process.cwd(), 'dist', 'antd.js'));
t.is( expect(
antdJsContent.toString() antdJsContent.toString()
.indexOf('function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }'), .indexOf('function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }')
-1 ).toBe(-1);
);
}) })
})(); });

View File

@ -1,14 +1,27 @@
import test from 'ava'; jest.unmock('../components/layout/index');
jest.unmock('../components/layout/col');
jest.unmock('../components/layout/row');
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import TestUtils from 'react-addons-test-utils';
import { Col, Row } from '../components/layout/index'; import { wrap } from 'react-stateless-wrapper';
test('should render Col', (t) => { let { Col, Row } = require('../components/layout/index');
const col = shallow(<Col span={2} />); Col = wrap(Col);
t.true(col.hasClass('ant-col-2'));
});
test('should render Row', (t) => { describe('Layout', function() {
const row = shallow(<Row />); it('should render Col', () => {
t.true(row.hasClass('ant-row')); const col = TestUtils.renderIntoDocument(
<Col span="2"></Col>
);
const colNode = TestUtils.findRenderedDOMComponentWithTag(col, 'DIV');
expect(colNode.className).toBe('ant-col-2');
});
it('should render Row', () => {
const row = TestUtils.renderIntoDocument(
<Row></Row>
);
const rowNode = TestUtils.findRenderedDOMComponentWithTag(row, 'DIV');
expect(rowNode.className).toBe('ant-row');
});
}); });

View File

@ -1,21 +1,29 @@
import test from 'ava'; jest.unmock('../components/popover/placements');
import React from 'react'; jest.unmock('../components/popover/index');
import Popover from '../components/popover' jest.unmock('../components/tooltip/index');
import { mount } from 'enzyme';
test('should show overlay when trigger is clicked', (t) => { import React from 'react';
const popover = mount( import TestUtils from 'react-addons-test-utils';
import Popover from '../components/popover/index';
describe('Popover', function() {
it('should show overlay when trigger is clicked', () => {
const popover = TestUtils.renderIntoDocument(
<Popover content="console.log('hello world')" title="code" trigger="click"> <Popover content="console.log('hello world')" title="code" trigger="click">
<a href="#">show me your code</a> <a href="#">show me your code</a>
</Popover> </Popover>
); );
t.is(popover.instance().getPopupDomNode(), undefined); expect(popover.getPopupDomNode()).toBe(undefined);
popover.find('a').simulate('click'); TestUtils.Simulate.click(
TestUtils.findRenderedDOMComponentWithTag(popover, 'a')
);
const popup = popover.instance().getPopupDomNode(); const popup = popover.getPopupDomNode();
t.truthy(popup); expect(popup).not.toBe(undefined);
t.true(popup.className.indexOf('ant-popover-placement-top') > 0); expect(popup.className).toContain('ant-popover-placement-top');
t.is(popup.innerHTML, '<div class="ant-popover-content"><div class="ant-popover-arrow"></div><div class="ant-popover-inner">code</div></div>'); expect(popup.innerHTML).toMatch(/<div class="ant-popover-title".*?>code<\/div>/);
expect(popup.innerHTML).toMatch(/<div class="ant-popover-inner-content".*?>console\.log\('hello world'\)<\/div>/);
});
}); });