Skip to content

Commit

Permalink
feat: enforce action.type (#36)
Browse files Browse the repository at this point in the history
- action.type must be a string or Symbol (the latter may or may not be
dropped, so test support can also be removed easily)
- use npm scripts instead of Makefile
- use Babel 6
- use nyc for code coverage and coveralls
- test against latest versions of Node LTS
- add editorconfig
- upgrade all dependencies except eslint-plugin-import
- Remove unnecessary test helper
- Add yarn.lock
  • Loading branch information
JaKXz authored Oct 27, 2016
1 parent 9634938 commit da8af44
Show file tree
Hide file tree
Showing 14 changed files with 3,297 additions and 61 deletions.
8 changes: 6 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"stage": 0,
"loose": "all"
"presets": ["stage-0", ["es2015", { "loose": true }]],
"env": {
"test": {
"plugins": ["istanbul"]
}
}
}
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
8 changes: 4 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "eslint-config-airbnb",
"extends": "eslint-config-airbnb-base",
"env": {
"mocha": true,
"node": true
Expand All @@ -8,8 +8,8 @@
"expect": true
},
"rules": {
"padded-blocks": 0,
"no-use-before-define": [2, "nofunc"],
"no-unused-expressions": 0
"no-use-before-define": 0,
"no-unused-expressions": 0,
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["!test/**/*.js"]}]
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ node_modules
coverage
*.log
lib
.idea
.nyc_output
5 changes: 0 additions & 5 deletions .npmignore

This file was deleted.

6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
sudo: false
language: node_js
node_js:
- "iojs"
- "stable"
- 4

after_success: "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
24 changes: 0 additions & 24 deletions Makefile

This file was deleted.

50 changes: 41 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
"version": "0.6.1",
"description": "A human-friendly standard for Flux action objects",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"test": "make test",
"prepublish": "make clean build"
"prebuild": "npm run clean",
"build": "babel src --out-dir lib",
"clean": "rimraf lib/",
"lint": "eslint src/ test/",
"prepublish": "npm test && npm run build",
"pretest": "npm run lint",
"test": "cross-env NODE_ENV=test nyc mocha"
},
"keywords": [
"flux",
Expand All @@ -16,15 +24,39 @@
"author": "Andrew Clark <[email protected]>",
"license": "MIT",
"devDependencies": {
"babel": "^5.6.14",
"babel-core": "^5.6.15",
"babel-eslint": "^4.1.8",
"babel-cli": "^6.16.0",
"babel-core": "^6.17.0",
"babel-eslint": "^7.0.0",
"babel-plugin-istanbul": "^2.0.1",
"babel-preset-es2015": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"chai": "^3.0.0",
"eslint": "^0.24.0",
"eslint-config-airbnb": "0.0.6",
"mocha": "^2.2.5"
"coveralls": "^2.11.14",
"cross-env": "^3.1.1",
"eslint": "^3.7.1",
"eslint-config-airbnb-base": "^8.0.0",
"eslint-plugin-import": "^1.0.0",
"mocha": "^3.0.0",
"nyc": "^8.3.0",
"rimraf": "^2.5.4"
},
"dependencies": {
"lodash.isplainobject": "^3.2.0"
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.issymbol": "^4.0.1"
},
"nyc": {
"all": true,
"sourceMap": false,
"instrument": false,
"reporter": [
"text-summary",
"lcov"
],
"check-coverage": true,
"lines": 100,
"statements": 100,
"functions": 100,
"branches": 100
}
}
2 changes: 0 additions & 2 deletions src/__tests__/init.js

This file was deleted.

24 changes: 12 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import isPlainObject from 'lodash.isplainobject';

const validKeys = [
'type',
'payload',
'error',
'meta'
];

function isValidKey(key) {
return validKeys.indexOf(key) > -1;
}
import isString from 'lodash.isstring';
import isSymbol from 'lodash.issymbol';

export function isFSA(action) {
return (
isPlainObject(action) &&
typeof action.type !== 'undefined' &&
(isString(action.type) || isSymbol(action.type)) &&
Object.keys(action).every(isValidKey)
);
}

export function isError(action) {
return action.error === true;
}

function isValidKey(key) {
return [
'type',
'payload',
'error',
'meta',
].indexOf(key) > -1;
}
3 changes: 2 additions & 1 deletion src/__tests__/isError-test.js → test/isError-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isError } from '../';
import { expect } from 'chai';
import { isError } from '../src/';

const type = 'ACTION_TYPE';

Expand Down
14 changes: 13 additions & 1 deletion src/__tests__/isFSA-test.js → test/isFSA-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { isFSA } from '../';
import { expect } from 'chai';
import { isFSA } from '../src/';

const type = 'ACTION_TYPE';
const symbolType = Symbol.for(type);

describe('isFSA()', () => {
it('requires a type', () => {
expect(isFSA({ type })).to.be.true;
expect(isFSA()).to.be.false;
expect(isFSA({})).to.be.false;
expect(isFSA({ type: undefined })).to.be.false;
});

it('only accepts plain objects', () => {
Expand All @@ -13,6 +18,13 @@ describe('isFSA()', () => {
expect(isFSA(action)).to.be.false;
});

it('only returns true if type is a string or symbol', () => {
// remove this assertion if/when symbol support is dropped
expect(isFSA({ type: symbolType })).to.be.true;
expect(isFSA({ type: true })).to.be.false;
expect(isFSA({ type: 123 })).to.be.false;
});

it('returns false if there are invalid keys', () => {
expect(isFSA({ type, payload: 'foobar' })).to.be.true;
expect(isFSA({ type, meta: 'foobar' })).to.be.true;
Expand Down
2 changes: 2 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--compilers js:babel-core/register
--recursive
Loading

0 comments on commit da8af44

Please sign in to comment.