mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 13:32:28 -05:00
add logging and test
This commit is contained in:
parent
435f00b745
commit
f245114f51
5 changed files with 40 additions and 5 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -7,4 +7,8 @@ npm-*
|
|||
|
||||
# Build
|
||||
playground/*
|
||||
dist/*
|
||||
dist/*
|
||||
|
||||
# Editors
|
||||
/#*
|
||||
*~
|
|
@ -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"
|
||||
}
|
||||
|
|
4
src/log/log.js
Normal file
4
src/log/log.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
const minilog = require('minilog');
|
||||
minilog.enable();
|
||||
|
||||
module.exports = minilog('paint-editor');
|
|
@ -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;
|
||||
|
|
25
test/tools-reducer-test.js
Normal file
25
test/tools-reducer-test.js
Normal 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();
|
||||
});
|
Loading…
Reference in a new issue