add logging and test

This commit is contained in:
DD Liu 2017-07-18 14:35:58 -04:00
parent 435f00b745
commit f245114f51
5 changed files with 40 additions and 5 deletions

6
.gitignore vendored
View file

@ -7,4 +7,8 @@ npm-*
# Build # Build
playground/* playground/*
dist/* dist/*
# Editors
/#*
*~

View file

@ -9,7 +9,8 @@
"deploy": "touch playground/.nojekyll && gh-pages -t -d playground -m \"Build for $(git log --pretty=format:%H -n1)\"", "deploy": "touch playground/.nojekyll && gh-pages -t -d playground -m \"Build for $(git log --pretty=format:%H -n1)\"",
"lint": "eslint . --ext .js,.jsx", "lint": "eslint . --ext .js,.jsx",
"start": "webpack-dev-server", "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" "watch": "webpack --progress --colors --watch"
}, },
"author": "Massachusetts Institute of Technology", "author": "Massachusetts Institute of Technology",
@ -54,6 +55,7 @@
"redux-throttle": "0.1.1", "redux-throttle": "0.1.1",
"rimraf": "^2.6.1", "rimraf": "^2.6.1",
"style-loader": "^0.18.0", "style-loader": "^0.18.0",
"tap": "^10.2.0",
"webpack": "^2.4.1", "webpack": "^2.4.1",
"webpack-dev-server": "^2.4.1" "webpack-dev-server": "^2.4.1"
} }

4
src/log/log.js Normal file
View file

@ -0,0 +1,4 @@
const minilog = require('minilog');
minilog.enable();
module.exports = minilog('paint-editor');

View file

@ -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 CHANGE_TOOL = 'scratch-paint/tools/CHANGE_TOOL';
const initialState = ToolTypes.BRUSH; const initialState = ToolTypes.BRUSH;
@ -10,8 +11,7 @@ const reducer = function (state, action) {
if (action.tool instanceof ToolTypes) { if (action.tool instanceof ToolTypes) {
return action.tool; return action.tool;
} }
// TODO switch to minilog log.warn(`Warning: Tool type does not exist: ${action.tool}`);
console.warn('Warning: Tool type does not exist: ${action.tool}');
/* falls through */ /* falls through */
default: default:
return state; return state;

View file

@ -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();
});