-
Notifications
You must be signed in to change notification settings - Fork 54
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
feat: auto require setup file #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules/ | ||
coverage/ | ||
test/fixtures/enzyme-example-mocha/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
"childprocess": "^2.0.2", | ||
"commander": "^2.9.0", | ||
"common-bin": "^1.0.0", | ||
"debug": "^2.4.4", | ||
"debug": "^2.5.2", | ||
"detect-port": "^1.0.7", | ||
"egg-utils": "^1.0.0", | ||
"glob": "^7.1.1", | ||
|
@@ -26,11 +26,20 @@ | |
}, | ||
"devDependencies": { | ||
"autod": "^2.7.1", | ||
"babel": "^6.3.26", | ||
"babel-preset-airbnb": "^1.0.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为啥多了一堆这个 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为了测试 fixture 里面的 react 例子加的。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我改一下 autod 的配置 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 哦,autod 不需要修改 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉就写一个简单的 .setup.js 的测试用例就好了吧? 要引入 react 全家桶么? 看起来好恐怖 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这样测试用例比较真实。。。 |
||
"babel-register": "^6.4.3", | ||
"coffee": "^3.3.0", | ||
"cross-env": "^3.1.3", | ||
"egg-ci": "^1.1.0", | ||
"enzyme": "^2.0.0", | ||
"eslint": "^3.12.2", | ||
"eslint-config-egg": "^3.2.0", | ||
"mm": "^2.0.0" | ||
"jsdom": "^8.0.1", | ||
"mm": "^2.0.0", | ||
"react": "^0.14.7", | ||
"react-addons-test-utils": "^0.14.7", | ||
"react-dom": "^0.14.7" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -40,8 +49,8 @@ | |
"author": "fengmk2 <[email protected]> (https://fengmk2.com)", | ||
"scripts": { | ||
"lint": "eslint bin lib test *.js", | ||
"test": "TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js test", | ||
"cov": "TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js cov", | ||
"test": "cross-env TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js test", | ||
"cov": "cross-env TEST_TIMEOUT=3600000 TESTS=test/*.test.js bin/egg-bin.js cov", | ||
"ci": "npm run lint && npm run cov", | ||
"autod": "autod" | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
presets: ["airbnb"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
node_modules | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个不需要了吧? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 保留着吧,比较直接 copy 别人的代码。 |
||
|
||
Copyright (c) 2016 Leland Richardson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# enzyme-example-mocha | ||
Example project with React + Enzyme + Mocha |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "enzyme-example-mocha", | ||
"version": "0.1.0", | ||
"description": "Example project with React + Enzyme + Mocha", | ||
"main": "build/index.js", | ||
"scripts": { | ||
"test": "mocha test/.setup.js test/**/*-test.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/lelandrichardson/enzyme-example-mocha.git" | ||
}, | ||
"author": "Leland Richardson <[email protected]>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/lelandrichardson/enzyme-example-mocha/issues" | ||
}, | ||
"homepage": "https://github.com/lelandrichardson/enzyme-example-mocha", | ||
"devDependencies": { | ||
"babel": "^6.3.26", | ||
"babel-preset-airbnb": "^1.0.1", | ||
"babel-register": "^6.4.3", | ||
"enzyme": "^2.0.0", | ||
"jsdom": "^8.0.1", | ||
"react-addons-test-utils": "^0.14.7" | ||
}, | ||
"dependencies": { | ||
"react": "^0.14.7", | ||
"react-dom": "^0.14.7" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
const propTypes = {}; | ||
|
||
const defaultProps = {}; | ||
|
||
class Foo extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="foo" /> | ||
); | ||
} | ||
} | ||
|
||
Foo.propTypes = propTypes; | ||
Foo.defaultProps = defaultProps; | ||
|
||
export default Foo; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require('babel-register')(); | ||
|
||
var jsdom = require('jsdom').jsdom; | ||
|
||
var exposedProperties = ['window', 'navigator', 'document']; | ||
|
||
global.document = jsdom(''); | ||
global.window = document.defaultView; | ||
Object.keys(document.defaultView).forEach((property) => { | ||
if (typeof global[property] === 'undefined') { | ||
exposedProperties.push(property); | ||
global[property] = document.defaultView[property]; | ||
} | ||
}); | ||
|
||
global.navigator = { | ||
userAgent: 'node.js' | ||
}; | ||
|
||
documentRef = document; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import assert from 'assert'; | ||
import { shallow, mount, render } from 'enzyme'; | ||
import Foo from '../src/Foo'; | ||
|
||
describe("A suite", () => { | ||
it("contains foo", () => { | ||
assert(shallow(<Foo />).contains(<div className="foo" />)); | ||
}); | ||
|
||
it("contains .foo", () => { | ||
assert(shallow(<Foo />).is('.foo')); | ||
}); | ||
|
||
it("contains .foo length 1", () => { | ||
assert(mount(<Foo />).find('.foo').length === 1); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
说明下里面怎么写?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
随便的,这个就是 mocha require 一下,setup 里面是什么内容都可以的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那为什么他们不直接写 mocha.opts ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
或者
egg-bin test -r test/.setup.js