diff --git a/.gitignore b/.gitignore index 46658083..f6371491 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,8 @@ npm-* # Build playground/* -dist/* \ No newline at end of file +dist/* + +# Editors +/#* +*~ \ No newline at end of file diff --git a/package.json b/package.json index a3c0209c..3190fdc5 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "deploy": "touch playground/.nojekyll && gh-pages -t -d playground -m \"Build for $(git log --pretty=format:%H -n1)\"", "lint": "eslint . --ext .js,.jsx", "start": "webpack-dev-server", - "test": "npm run lint && npm run build", + "tap": "./node_modules/.bin/tap ./test/*.js", + "test": "npm run lint && npm run build && npm run tap", "watch": "webpack --progress --colors --watch" }, "author": "Massachusetts Institute of Technology", @@ -54,6 +55,7 @@ "redux-throttle": "0.1.1", "rimraf": "^2.6.1", "style-loader": "^0.18.0", + "tap": "^10.2.0", "webpack": "^2.4.1", "webpack-dev-server": "^2.4.1" } diff --git a/src/log/log.js b/src/log/log.js new file mode 100644 index 00000000..9b991a58 --- /dev/null +++ b/src/log/log.js @@ -0,0 +1,4 @@ +const minilog = require('minilog'); +minilog.enable(); + +module.exports = minilog('paint-editor'); diff --git a/src/reducers/tools.js b/src/reducers/tools.js index 5a09586e..59cf1afb 100644 --- a/src/reducers/tools.js +++ b/src/reducers/tools.js @@ -1,4 +1,5 @@ -import ToolTypes from '../tools/tool-types.js'; +const ToolTypes = require('../tools/tool-types'); +const log = require('../log/log'); const CHANGE_TOOL = 'scratch-paint/tools/CHANGE_TOOL'; const initialState = ToolTypes.BRUSH; @@ -10,8 +11,7 @@ const reducer = function (state, action) { if (action.tool instanceof ToolTypes) { return action.tool; } - // TODO switch to minilog - console.warn('Warning: Tool type does not exist: ${action.tool}'); + log.warn(`Warning: Tool type does not exist: ${action.tool}`); /* falls through */ default: return state; diff --git a/test/tools-reducer-test.js b/test/tools-reducer-test.js new file mode 100644 index 00000000..3da061d1 --- /dev/null +++ b/test/tools-reducer-test.js @@ -0,0 +1,25 @@ +const test = require('tap').test; +const ToolTypes = require('../src/tools/tool-types'); +const reducer = require('../src/reducers/tools'); + +test('initialState', t => { + let defaultState; + t.assert(reducer(defaultState /* state */, {type: 'anything'} /* action */) instanceof ToolTypes); + t.end(); +}); + +test('changeTool', t => { + let defaultState; + t.assert(reducer(defaultState /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */), ToolTypes.ERASER); + t.assert( + reducer(ToolTypes.ERASER /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */), ToolTypes.ERASER); + t.assert(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */), ToolTypes.ERASER); + t.end(); +}); + +test('invalidChangeTool', t => { + t.assert( + reducer(ToolTypes.BRUSH /* state */, reducer.changeTool('non-existant tool') /* action */), ToolTypes.BRUSH); + t.assert(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool() /* action */), ToolTypes.BRUSH); + t.end(); +});