Skip to content

Commit

Permalink
Add eslint, tidy for major release
Browse files Browse the repository at this point in the history
PR #12
  • Loading branch information
hulbert authored Jul 18, 2017
2 parents c6c6927 + 29e05e6 commit 952b7be
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@scoop/eslint-config-scoop"
}
3 changes: 2 additions & 1 deletion include_dirs.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
console.log(require('path').relative('.', __dirname));
'use strict'
console.log(require('path').relative('.', __dirname))
66 changes: 35 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
{
"name": "cpp-eventemitter",
"version": "1.0.0",
"description": "A Native Nan version of EventEmitter that allows C++ (and single-threaded C) to emit to javascript listeners as events happen.",
"main": "include_dirs.js",
"scripts": {
"test": "cd test; make clean; make alltests",
"jstests": "cd test; node-gyp configure && node-gyp rebuild && mocha ./js/*-test.js"
},
"keywords": [
"nan",
"native",
"c++",
"cpp",
"cplusplus",
"eventemitter",
"event",
"emitter"
],
"author": "Jamie Beverly",
"license": "ISC",
"devDependencies": {
"catch": "^1.0.48",
"chai": "^4.0.2",
"mocha": "^3.4.2",
"node-gyp": "^3.6.2",
"path": "^0.12.7"
},
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.6.2"
}
"name": "cpp-eventemitter",
"version": "0.1.0",
"description": "A Native Nan version of EventEmitter that allows C++ and wrapped C to emit to javascript listeners as events happen.",
"main": "include_dirs.js",
"scripts": {
"test": "eslint . && cd test && make clean && make alltests",
"jstests": "cd test && node-gyp configure && node-gyp rebuild && mocha ./js/*.js",
"lint": "eslint ."
},
"keywords": [
"nan",
"native",
"c++",
"cpp",
"cplusplus",
"eventemitter",
"event",
"emitter"
],
"author": "Jamie Beverly",
"license": "MIT",
"devDependencies": {
"@scoop/eslint-config-scoop": "^3.1.0",
"catch": "^1.0.48",
"code": "^4.1.0",
"eslint": "^3.19.0",
"eslint-plugin-dependencies": "^2.4.0",
"mocha": "^3.4.2",
"node-gyp": "^3.6.2",
"path": "^0.12.7"
},
"dependencies": {
"bindings": "^1.2.1",
"nan": "^2.6.2"
}
}
6 changes: 6 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"globals": {
"describe": true,
"it": true
}
}
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ $(TESTS): $(TEST_INPUTS)
g++ -std=c++11 -ggdb -Wall -Wextra -isystem $(CATCHHEADER) -o $@ $< -lpthread

clean:
rm $(TESTS)
rm -f $(TESTS) || true
58 changes: 30 additions & 28 deletions test/js/eventemitter-test.js → test/js/eventemitter.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
const expect = require('chai').expect
'use strict'

const expect = require('code').expect
const testRoot = require('path').resolve(__dirname, '..')
const bindings = require('bindings')({ module_root: testRoot, bindings: 'eventemitter' })
const bindings = require('bindings')({ 'module_root': testRoot, bindings: 'eventemitter' })

describe('Verify EventEmitter Single', function() {
it('should invoke the callback for test', function(done) {
let thing = new bindings.EmitterThing()
let n = 100;
let k = 0;
let n = 100
let k = 0
thing.on('test', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k++)
if(k === n) {
done();
if (k === n) {
done()
}
})

Expand All @@ -22,24 +24,24 @@ describe('Verify EventEmitter Single', function() {
describe('Verify EventEmitter Multi', function() {
it('should invoke the callbacks for test, test2, and test3', function(done) {
let thing = new bindings.EmitterThing()
let n = 300;
let k = [0,0,0];
let n = 300
let k = [0, 0, 0]
thing.on('test', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k[0]++)
})

thing.on('test2', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k[1]++)
})
thing.on('test3', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k[2]++)

if(k[2] === n) {
while(k[0] !== n || k[1] !== n);
done();
if (k[2] === n) {
while (k[0] !== n || k[1] !== n) { /* do nothing */ }
done()
}
})
thing.run(n)
Expand All @@ -50,13 +52,13 @@ describe('Verify EventEmitter Multi', function() {
describe('Verify EventEmitter Reentrant Single', function() {
it('should invoke the callback for test', function(done) {
let thing = new bindings.EmitterThing()
let n = 100;
let k = 0;
let n = 100
let k = 0
thing.on('test', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k++)
if(k === n) {
done();
if (k === n) {
done()
}
})

Expand All @@ -67,24 +69,24 @@ describe('Verify EventEmitter Reentrant Single', function() {
describe('Verify EventEmitter Reentrant Multi', function() {
it('should invoke the callbacks for test, test2, and test3', function(done) {
let thing = new bindings.EmitterThing()
let n = 300;
let k = [0,0,0];
let n = 300
let k = [0, 0, 0]
thing.on('test', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k[0]++)
})

thing.on('test2', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k[1]++)
})
thing.on('test3', function(ev) {
expect(ev).to.be.a('string')
expect(ev).to.be.a.string()
expect(ev).to.equal('Test' + k[2]++)

if(k[2] === n) {
while(k[0] !== n || k[1] !== n);
done();
if (k[2] === n) {
while (k[0] !== n || k[1] !== n) { /* do nothing */ }
done()
}
})
thing.runReentrant(n)
Expand Down

0 comments on commit 952b7be

Please sign in to comment.