Skip to content

Commit

Permalink
Adding code coverage with istanbul and monitoring with coveralls, fix…
Browse files Browse the repository at this point in the history
…ing non-executing unit test assertions, and fixing bug with (str)key == (str)value enum mappings.
  • Loading branch information
Evan King committed Jun 19, 2016
1 parent 7542f10 commit bcb8dd9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 21 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/*
dist/*
coverage/
node_modules/
dist/
npm-debug.log
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test/
coverage/
build.js
test.js
test.html
dist/test.js
.travis.yml
.npmignore
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
language: node_js
node_js:
- 5.3.0
- 4
- 5

script:
- ./node_modules/.bin/mocha test.js
- npm run-script travis

after_script:
- npm install coveralls@2.10.0
- cat ./coverage/lcov.info | coveralls
4 changes: 2 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ browserify()
})
.transform(dependencyShim.configure({
'chai': 'chai',
'./index': 'PrimitiveEnum',
'../index': 'PrimitiveEnum',
}))
.require('./test.js', {entry: true})
.require('./test/test.js', {entry: true})
.bundle()
.on("error", err => console.log("Error: " + err.message))
.pipe(fs.createWriteStream('dist/test.js'));
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const Enum = function PrimitiveEnumBuilder(inputMap, options) {
map[''+key] = val;
reverseMap[''+val] = key;
prop(key, val, true);
prop(val, key);
if(''+key !== ''+val) prop(val, key);
}

let transform = opts.transform;
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"name": "primitive-enum",
"version": "0.9.5",
"version": "0.9.6",
"description": "Lightweight enums with primitive datatypes",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "istanbul cover --report html -x dist/ _mocha -- test/**/*.js",
"travis": "istanbul cover --report lcovonly -x dist/ _mocha",
"posttravis": "istanbul check-coverage --statements $npm_package_config_min_coverage --branches $npm_package_config_min_coverage --lines $npm_package_config_min_coverage"
},
"config": {
"min_coverage": 60
},
"repository": {
"type": "git",
Expand All @@ -31,6 +36,7 @@
"browserify": "^13.0.0",
"browserify-global-shim": "^1.0.3",
"chai": "^3.5.0",
"istanbul": "^0.4.3",
"mocha": "^2.4.5"
}
}
4 changes: 2 additions & 2 deletions test.html → test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
<script>
var PrimitiveEnum = 'original';
</script>
<script src="dist/primitive-enum.js"></script>
<script src="../dist/primitive-enum.js"></script>

<script>
mocha.checkLeaks();
mocha.setup('bdd');
</script>
<script src="dist/test.js"></script>
<script src="../dist/test.js"></script>
<script>
mocha.run();
</script>
Expand Down
16 changes: 8 additions & 8 deletions test.js → test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const
expect = require('chai').expect,
Enum = require('./index');
Enum = require('../index');

describe('PrimitiveEnumBuilder', function() {

Expand All @@ -28,21 +28,21 @@ describe('PrimitiveEnumBuilder', function() {
});

it('rejects duplicate keys or values', function(done) {
expect(() => Enum(['a', 'a'])).throw;
expect(() => Enum({a: 1, b: 1})).throw;
expect(() => Enum(['a', 'a'])).throw();
expect(() => Enum({a: 1, b: 1})).throw();
done();
});

it('rejects maps with lookup conflict', function(done) {
expect(Enum.bind(null, {a: 'x', b: 'x'})).throw;
expect(Enum.bind(null, {a: 'b', b: 'c'})).throw;
expect(Enum.bind(null, ['a', 'a', 'b'])).throw;
expect(Enum.bind(null, {a: 'x', b: 'x'})).throw();
expect(Enum.bind(null, {a: 'b', b: 'c'})).throw();
expect(Enum.bind(null, ['a', 'a', 'b'])).throw();
done();
});

it('rejects enum values duplicating unrelated keys', function(done) {
expect(() => Enum({a: 'b', b: 'c'})).throw;
expect(() => Enum({a: 'a', b: 'b'})).not.throw;
expect(() => Enum({a: 'b', b: 'c'})).throw();
expect(() => Enum({a: 'a', b: 'b'})).not.throw();
done();
});

Expand Down

0 comments on commit bcb8dd9

Please sign in to comment.