Skip to content

Commit

Permalink
Rewrite tests with jest
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwain committed Sep 22, 2017
1 parent 2485c56 commit 45d3ad5
Show file tree
Hide file tree
Showing 16 changed files with 1,769 additions and 472 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ language: node_js
node_js:
- "node"

cache: yarn
cache: yarn

script:
- yarn prepublishOnly
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
],
"scripts": {
"clean": "rimraf lib dist es",
"lint": "eslint src test",
"test": "cross-env BABEL_ENV=commonjs tape -r babel-polyfill -r babel-register './test/*.test.js'",
"lint": "eslint --max-warnings=0 src test",
"test": "cross-env BABEL_ENV=commonjs jest",
"build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
"build:es": "cross-env BABEL_ENV=es babel src --out-dir es",
"build:umd": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/redux-loop.js",
"build:umd:min": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/redux-loop.min.js",
"build": "yarn build:commonjs && yarn build:es && yarn build:umd && yarn build:umd:min",
"prebuild": "yarn clean",
"prepublish": "yarn lint && yarn test && yarn build"
"prepublishOnly": "yarn lint && yarn test && yarn build"
},
"keywords": [
"redux",
Expand Down Expand Up @@ -64,25 +64,27 @@
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-register": "^6.26.0",
"cross-env": "^5.0.5",
"eslint": "^4.7.0",
"eslint": "^4.7.1",
"eslint-config-react-app": "^2.0.0",
"eslint-plugin-flowtype": "^2.35.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-react": "^7.3.0",
"immutable": "^3.7.6",
"jest": "^21.1.0",
"redux": "^3.7.2",
"rimraf": "^2.6.2",
"rollup": "^0.50.0",
"rollup-plugin-babel": "^3.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^2.0.1",
"tape": "4.5.1",
"typescript": "^2.5.2",
"typescript-definition-tester": "^0.0.5"
},
"dependencies": {}
"dependencies": {},
"jest": {
"testRegex": "(/test/.*\\.spec.js)$"
}
}
3 changes: 1 addition & 2 deletions src/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const isCmdSymbol = Symbol('isCmd');
const dispatchSymbol = Symbol('dispatch');
const getStateSymbol = Symbol('getState');


const cmdTypes = {
RUN: 'RUN',
ACTION: 'ACTION',
Expand All @@ -15,7 +14,7 @@ const cmdTypes = {
}

export const isCmd = (object) => {
return object ? object[isCmdSymbol] : false
return object ? !!object[isCmdSymbol] : false
}

function getMappedCmdArgs(args = [], dispatch, getState){
Expand Down
8 changes: 2 additions & 6 deletions src/loop.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { throwInvariant } from './utils';
import Cmd, { isCmd } from './cmd';


export const isLoop = (array) => {
return Array.isArray(array) && array.length === 2 && isCmd(array[1])
return Array.isArray(array) && array.length === 2 && isCmd(array[1]) && !isCmd(array[0])
};


export const getCmd = (loop) => {
return isLoop(loop) ? loop[1] : null
}
Expand All @@ -15,7 +13,6 @@ export const getModel = (loop) => {
return isLoop(loop) ? loop[0] : loop
}


export const loop = (model, cmd) => {
if(process.env.NODE_ENV === 'development') {
throwInvariant(
Expand All @@ -27,7 +24,6 @@ export const loop = (model, cmd) => {
return [model, cmd]
}


export const liftState = (state) => {
return isLoop(state) ? state : loop(state, Cmd.none)
}
}
3 changes: 1 addition & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const flatten = (array) => {
return concat.apply([], array)
}


export const throwInvariant = (condition, message) => {
if(!condition) {
throw Error(message)
Expand All @@ -13,4 +12,4 @@ export const throwInvariant = (condition, message) => {

export const isPromiseLike = (obj) => {
return typeof obj === 'object' && typeof obj.then === 'function'
}
}
5 changes: 5 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}
Loading

0 comments on commit 45d3ad5

Please sign in to comment.