Skip to content

Commit

Permalink
first push
Browse files Browse the repository at this point in the history
  • Loading branch information
zackify committed Mar 11, 2016
1 parent 71c0bc0 commit 291e3e8
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 562 deletions.
5 changes: 4 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"stage": 0
"presets": [
"react",
"es2015"
]
}
4 changes: 2 additions & 2 deletions mocha.opts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--full-trace
--compilers js:babel/register
--compilers js:babel-register
--harmony-proxies
--recursive ./tests/**/*.jsx
--recursive ./tests
35 changes: 12 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"scripts": {
"compile": "babel src --out-dir .",
"prepublish": "babel src --out-dir .",
"lint": "eslint ./src/ ./tests/ --ext .jsx,.js --global require,exports:true",
"mocha": "mocha --opts ./mocha.opts",
"test": "npm run mocha; npm run lint"
"test": "mocha --opts ./mocha.opts"
},
"repository": {
"type": "git",
Expand All @@ -28,28 +26,19 @@
},
"homepage": "https://github.com/legitcode/tests#readme",
"devDependencies": {
"alt": "^0.17.4",
"babel-core": "^5.8.25",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.3.2",
"babel-runtime": "^5.8.25",
"babel-cli": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-register": "^6.7.2",
"chai": "^3.3.0",
"eslint": "^1.6.0",
"eslint-plugin-react": "^3.5.1",
"expect": "^1.12.0",
"mocha": "^2.3.3",
"mocha-babel": "^3.0.0",
"react-hot-loader": "^1.3.0",
"sinon": "^1.17.1",
"webpack": "^1.12.2"
"mocha": "^2.4.5",
"react": "^0.14.7",
"react-addons-test-utils": "^0.14.7",
"sinon": "^1.17.1"
},
"dependencies": {
"babel": "^5.8.29",
"harmony-reflect": "^1.4.2",
"jsdom": "^6.5.1",
"lodash": "^3.10.1",
"react": "^0.14.0",
"react-addons-test-utils": "^0.14.0",
"react-dom": "^0.14.0"
"peerDependencies": {
"react-addons-test-utils": ">0.14.0",
"react": ">0.14.0"
}
}
3 changes: 0 additions & 3 deletions src/alt/alt.js

This file was deleted.

31 changes: 0 additions & 31 deletions src/alt/store.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/dom.js

This file was deleted.

23 changes: 23 additions & 0 deletions src/find-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import React from 'react';

/**
* Traverses the tree and returns all components that satisfy the function `test`.
*
* @param {ReactComponent} tree the tree to traverse
* @param {Function} test the test for each component
* @return {Array} the components that satisfied `test`
*/
export default function findAll(tree, test) {
let found = test(tree) ? [tree] : [];

if (React.isValidElement(tree)) {
if (React.Children.count(tree.props.children) > 0) {
React.Children.forEach(tree.props.children, (child) => {
found = found.concat(findAll(child, test));
});
}
}

return found;
}
58 changes: 56 additions & 2 deletions src/legit-tests.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
import './dom'
export default from './tests'
import TestUtils from 'react-addons-test-utils'
import React from 'react'
import findAll from './find-all'

export default (component) => {
let items, selectedIndex

const shallowRenderer = TestUtils.createRenderer()
shallowRenderer.render(component)
const instance = shallowRenderer.getRenderOutput();

const find = (term, child) => {
const selector = term.charAt(0)
switch (selector) {
case '.':
items = findAll(instance, child => child.props ? child.props.className == term.slice(1) : false)
return proxy
case '#':
items = findAll(instance, child => child.props ? child.props.id == term.slice(1) : false)
return proxy
default:
return proxy
}
}

const first = () => {
selectedIndex = 0
return proxy
}

const last = () => {
selectedIndex = items.length - 1
return proxy
}

const get = (index) => {
selectedIndex = index
return proxy
}

const utils = {
props: instance.props,
find,
first,
last,
get
}

const proxy = Proxy.create({
get: (proxy, name) => {
if(utils[name]) return value => utils[name](value)
return items[selectedIndex || 0].props[name]
}
})
return proxy
}
11 changes: 0 additions & 11 deletions src/middleware.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/middleware/clean.js

This file was deleted.

73 changes: 0 additions & 73 deletions src/middleware/find.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/middleware/setState.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/middleware/simulate.js

This file was deleted.

1 change: 0 additions & 1 deletion src/no-dom.js

This file was deleted.

Loading

0 comments on commit 291e3e8

Please sign in to comment.