switch to jest

This commit is contained in:
DD Liu 2017-07-26 20:39:12 -04:00
parent 530b2d76f4
commit dc683f1d82
14 changed files with 67 additions and 40 deletions

3
.babelrc Normal file
View file

@ -0,0 +1,3 @@
{
"presets": ["es2015", "react"]
}

View file

@ -9,8 +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",
"tap": "./node_modules/.bin/tap ./test/*.js", "test": "npm run lint && npm run build && npm run unit-test",
"test": "npm run lint && npm run build && npm run tap", "unit": "jest",
"watch": "webpack --progress --colors --watch" "watch": "webpack --progress --colors --watch"
}, },
"author": "Massachusetts Institute of Technology", "author": "Massachusetts Institute of Technology",
@ -28,17 +28,22 @@
"autoprefixer": "7.1.1", "autoprefixer": "7.1.1",
"babel-core": "^6.23.1", "babel-core": "^6.23.1",
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
"babel-jest": "^20.0.3",
"babel-loader": "^7.0.0", "babel-loader": "^7.0.0",
"babel-plugin-transform-object-rest-spread": "^6.22.0", "babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-preset-es2015": "^6.22.0", "babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.22.0", "babel-preset-react": "^6.22.0",
"classnames": "2.2.5", "classnames": "2.2.5",
"css-loader": "0.28.3", "css-loader": "0.28.3",
"enzyme": "^2.8.2",
"eslint": "^3.16.1", "eslint": "^3.16.1",
"eslint-config-import": "^0.13.0",
"eslint-config-scratch": "^3.0.0", "eslint-config-scratch": "^3.0.0",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-react": "^7.0.1", "eslint-plugin-react": "^7.0.1",
"gh-pages": "github:rschamp/gh-pages#publish-branch-to-subfolder", "gh-pages": "github:rschamp/gh-pages#publish-branch-to-subfolder",
"html-webpack-plugin": "2.28.0", "html-webpack-plugin": "2.28.0",
"jest": "^20.0.4",
"lodash.defaultsdeep": "4.6.0", "lodash.defaultsdeep": "4.6.0",
"minilog": "3.1.0", "minilog": "3.1.0",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
@ -51,12 +56,21 @@
"react-dom": "15.5.4", "react-dom": "15.5.4",
"react-intl": "2.3.0", "react-intl": "2.3.0",
"react-redux": "5.0.5", "react-redux": "5.0.5",
"react-test-renderer": "^15.5.4",
"redux": "3.6.0", "redux": "3.6.0",
"redux-mock-store": "^1.2.3",
"redux-throttle": "0.1.1", "redux-throttle": "0.1.1",
"regenerator-runtime": "^0.10.5",
"rimraf": "^2.6.1", "rimraf": "^2.6.1",
"style-loader": "^0.18.0", "style-loader": "^0.18.0",
"tap": "^10.2.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"
},
"jest": {
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/test/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/test/__mocks__/styleMock.js"
}
} }
} }

View file

@ -1,7 +1,13 @@
module.exports = { module.exports = {
root: true, root: true,
extends: ['scratch', 'scratch/es6', 'scratch/react'], extends: ['scratch', 'scratch/es6', 'scratch/react', 'import'],
env: { env: {
browser: true browser: true
},
rules: {
'import/no-mutable-exports': 'error',
'import/no-commonjs': 'error',
'import/no-amd': 'error',
'import/no-nodejs-modules': 'error'
} }
}; };

View file

@ -14,5 +14,4 @@ PaintEditorComponent.propTypes = {
}) })
}; };
export default PaintEditorComponent;
module.exports = PaintEditorComponent;

View file

@ -42,7 +42,7 @@ const mapDispatchToProps = dispatch => ({
} }
}); });
module.exports = connect( export default connect(
mapStateToProps, mapStateToProps,
mapDispatchToProps mapDispatchToProps
)(PaintEditor); )(PaintEditor);

View file

@ -44,4 +44,4 @@ PaperCanvas.propTypes = {
}) })
}; };
module.exports = PaperCanvas; export default PaperCanvas;

View file

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

View file

@ -1,5 +1,6 @@
import {combineReducers} from 'redux'; import {combineReducers} from 'redux';
import toolReducer from './tools';
module.exports = combineReducers({ export default combineReducers({
tool: require('./tools') tool: toolReducer
}); });

View file

@ -1,5 +1,5 @@
const ToolTypes = require('../tools/tool-types'); import ToolTypes from '../tools/tool-types';
const log = require('../log/log'); import log from '../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;
@ -29,4 +29,4 @@ reducer.changeTool = function (tool) {
}; };
}; };
module.exports = reducer; export default reducer;

View file

@ -9,4 +9,4 @@ class ToolTypes {
ToolTypes.BRUSH = new ToolTypes('BRUSH'); ToolTypes.BRUSH = new ToolTypes('BRUSH');
ToolTypes.ERASER = new ToolTypes('ERASER'); ToolTypes.ERASER = new ToolTypes('ERASER');
module.exports = ToolTypes; export default ToolTypes;

View file

@ -0,0 +1,3 @@
// __mocks__/fileMock.js
module.exports = 'test-file-stub';

View file

@ -0,0 +1,3 @@
// __mocks__/styleMock.js
module.exports = {};

View file

@ -1,25 +0,0 @@
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();
});

View file

@ -0,0 +1,23 @@
/* eslint-env jest */
import ToolTypes from '../../src/tools/tool-types';
import reducer from '../../src/reducers/tools';
test('initialState', () => {
let defaultState;
expect(reducer(defaultState /* state */, {type: 'anything'} /* action */) instanceof ToolTypes).toBeTruthy();
});
test('changeTool', () => {
let defaultState;
expect(reducer(defaultState /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */)).toBe(ToolTypes.ERASER);
expect(reducer(ToolTypes.ERASER /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */))
.toBe(ToolTypes.ERASER);
expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */))
.toBe(ToolTypes.ERASER);
});
test('invalidChangeTool', () => {
expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool('non-existant tool') /* action */))
.toBe(ToolTypes.BRUSH);
expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool() /* action */)).toBe(ToolTypes.BRUSH);
});