Skip to content

Commit

Permalink
Feature repo improvements (#250)
Browse files Browse the repository at this point in the history
* Added waitFor method

* fixed README.md code example for waitFor method

* Closes #153 by using the current global scope instead of window

* Added universal test loader for nodeunit and mocha test suites;
Updated dependencies;
Fixed coverage script;
Reworked repo scripts set;
Added coveralls integration;
Added travis build integration;
Updated README.md badges;

* Extended integration with assert module;

* Added prepublishOnly & postversion scripts

* Reduced required branches coverage to 75%

* added return value from test function just in case

* allowed to skip null tests

* updated package description

* Added keywords
  • Loading branch information
DigitalBrainJS committed Apr 1, 2020
1 parent 191e0ff commit 9f8a837
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 10 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sudo: false
language: node_js
node_js:
- "8"
- "10"
env:
- NODE_ENV=TEST
script:
- npm run test:coverage
after_success: npm run coveralls
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Codeship](https://img.shields.io/codeship/3ad58940-4c7d-0131-15d5-5a8cd3f550f8.svg?maxAge=2592000)]()
[![Build Status](https://travis-ci.com/EventEmitter2/EventEmitter2.svg?branch=master)](https://travis-ci.com/DigitalBrainJS/define-accessor2)
[![Coverage Status](https://coveralls.io/repos/github/EventEmitter2/EventEmitter2/badge.svg?branch=master)](https://coveralls.io/github/DigitalBrainJS/define-accessor2?branch=master)
[![NPM version](https://badge.fury.io/js/eventemitter2.svg)](http://badge.fury.io/js/eventemitter2)
[![Dependency Status](https://img.shields.io/david/asyncly/eventemitter2.svg)](https://david-dm.org/asyncly/eventemitter2)
[![npm](https://img.shields.io/npm/dm/eventemitter2.svg?maxAge=2592000)]()
Expand Down
37 changes: 28 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
{
"name": "eventemitter2",
"version": "6.3.1",
"description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.",
"description": "A Node.js event emitter implementation with namespaces, wildcards, TTL, promises and browser support.",
"keywords": [
"event",
"events",
"emitter",
"eventemitter"
"eventemitter",
"addEventListener",
"addListener",
"pub/sub",
"emit",
"emits",
"on",
"once",
"publish",
"subscribe"
],
"author": "hij1nx <paolo@async.ly> http://twitter.com/hij1nx",
"contributors": [
Expand All @@ -19,16 +28,23 @@
"license": "MIT",
"repository": "git://github.com/hij1nx/EventEmitter2.git",
"devDependencies": {
"benchmark": ">= 0.2.2",
"bluebird": "^3.7.2",
"benchmark": "^2.1.4",
"coveralls": "^3.0.11",
"mocha": "^7.1.1",
"nodeunit": "*",
"nyc": "^11.4.1"
"nyc": "^15.0.0",
"bluebird": "^3.7.2"
},
"main": "./lib/eventemitter2.js",
"scripts": {
"test": "nodeunit test/simple/ test/wildcardEvents/",
"coverage": "nyc --check-coverage npm run test",
"benchmark": "node test/perf/benchmark.js"
"test": "mocha ./test/loader.js --exit --timeout=3000",
"test:legacy": "nodeunit test/simple/ test/wildcardEvents/",
"test:coverage": "nyc --check-coverage npm run test",
"coverage:report": "nyc report --reporter=html --reporter=text",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
"benchmark": "node test/perf/benchmark.js",
"prepublishOnly": "npm run test:coverage",
"postversion": "git push && git push --tags"
},
"files": [
"lib/eventemitter2.js",
Expand All @@ -42,7 +58,7 @@
"nyc": {
"lines": 83,
"functions": 84,
"branches": 79,
"branches": 75,
"statements": 83,
"watermarks": {
"lines": [
Expand All @@ -62,6 +78,9 @@
95
]
},
"include": [
"lib/**/*.js"
],
"reporter": [
"lcov",
"text-summary"
Expand Down
81 changes: 81 additions & 0 deletions test/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert');

function importTests(root, filter) {
const tests = {};

function scanDir(currentDir, testEntry) {
fs.readdirSync(currentDir).forEach(function (entry) {
entry = path.resolve(currentDir, entry);
const stats = fs.statSync(entry);
const {name, ext} = path.parse(entry);
const relativePath = path.relative(root, entry);
if (filter && !filter(relativePath)) return;
if (stats.isDirectory()) {
return scanDir(entry, testEntry[name] || (testEntry[name] = {}));
}
ext === '.js' && (testEntry[name] = require(entry));
});
}

scanDir(root, tests);

function _import(tests) {
Object.keys(tests).forEach(function (testName) {
const test = tests[testName];
const type = typeof test;
if (type === 'object') {
if (!type) {
return;
}
describe(testName, function () {
_import(test);
})
} else if (type === 'function') {
const executor = function (done) {
if (!done) {
return test.call(this);
}
let count, expectedCount;

function wrap(fn) {
return function () {
count++;
return fn.apply(null, arguments);
}
}

const testObj = Object.assign(function () {
return done.apply(this, arguments);
}, {
done: function (err) {
if (expectedCount !== undefined && count < expectedCount) {
throw Error(`${count}/${expectedCount} assertions was done`);
}
err ? done(err) : done();
},
expect: function (count) {
expectedCount = count;
}
});
Object.keys(assert).forEach(function(prop){
const value= assert[prop];
typeof value==='function' && (testObj[prop]= wrap(value));
});
return test.call(this, testObj);
};
it(testName, test.length ? executor : function () {
return executor.call(this, null);
})
} else {
throw TypeError('expected an object or function');
}
})
}
_import(tests);
}

importTests('./test', function (path) {
return !~['common.js', 'perf', 'test-loader.js'].indexOf(path);
});

0 comments on commit 9f8a837

Please sign in to comment.