Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Migrate to jest (#8)
Move from mocha + blanket to jest
Update eslint and add it as a dev dependency
  • Loading branch information
JMPerez committed Oct 22, 2016
1 parent a8f31e5 commit 1d5a922
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 80 deletions.
13 changes: 7 additions & 6 deletions .eslintrc
Expand Up @@ -4,13 +4,15 @@ env:
rules:
brace-style: [2, "1tbs"]
comma-style: [2, "last"]
camelcase: 2
curly: 2
default-case: 2
eqeqeq: 2
func-style: [1, "declaration"]
guard-for-in: 2
indent: [2, 2]
keyword-spacing: ["error", { "before": true }]
new-cap: 0
no-console: 0
no-debugger: 2
no-empty: 2
no-floating-decimal: 2
Expand All @@ -19,11 +21,10 @@ rules:
no-underscore-dangle: 0
no-unreachable: 2
radix: 2
quotes: 'single'
space-after-function-name: [2, "never"]
space-after-keywords: [2, "always"]
quotes: [2, "single"]
space-before-function-paren: [2, "never"]
space-before-blocks: 2
spaced-line-comment: [2, "always", { exceptions: ["-"]}]
spaced-comment: [2, "always", { exceptions: ["-"]}]
strict: [2, "global"]
valid-jsdoc: [2]
wrap-iife: 2
wrap-iife: [2, "any"]
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,2 +1,2 @@
coverage
node_modules
test/coverage.html
9 changes: 4 additions & 5 deletions .travis.yml
@@ -1,7 +1,6 @@
language: node_js
node_js:
- "4.1"
- "4.0"
- "0.12"
- "0.11"
after_success: make coveralls
- "6"
- "6.1"
- "5.11"
script: npm run travis
38 changes: 0 additions & 38 deletions Makefile

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -62,8 +62,8 @@ If you are using it in a browser, you can use bower: `bower install promise-thro

## Development

Install the dependencies using `make install`.
Run `make` to lint, test and generate the dist file.
Install the dependencies using `npm install`.
Run `npm start` to generate the dist file.

## Projects using it

Expand Down
6 changes: 4 additions & 2 deletions test/main.js → __tests__/main.test.js
Expand Up @@ -17,6 +17,10 @@ function createPromiseThrottle(rps) {

describe('PromiseThrottle', function() {

beforeEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});

it('should have the following API: add(), addAll()', function() {
assert.strictEqual(typeof PromiseThrottle.prototype.add, 'function');
assert.strictEqual(typeof PromiseThrottle.prototype.addAll, 'function');
Expand Down Expand Up @@ -143,8 +147,6 @@ describe('PromiseThrottle', function() {
});

it('should throttle properly the function calls, respecting the number of "requestsPerSecond" option', function(done) {
this.timeout(4000);

var pt10 = createPromiseThrottle(10);

var count = 30,
Expand Down
24 changes: 13 additions & 11 deletions dist/promise-throttle.js
@@ -1,10 +1,4 @@
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/* global window */

'use strict';
window.PromiseThrottle = require('./main');

},{"./main":2}],2:[function(require,module,exports){
/* exported PromiseThrottle */

'use strict';
Expand All @@ -24,7 +18,7 @@ function PromiseThrottle(options) {

/**
* Adds a promise
* @param {Promise} promise The promise to be added
* @param {Function} promise A function returning the promise to be added
* @return {Promise} A promise
*/
PromiseThrottle.prototype.add = function (promise) {
Expand All @@ -42,13 +36,15 @@ PromiseThrottle.prototype.add = function (promise) {

/**
* Adds all the promises passed as parameters
* @param {array} promises An array of promises
* @param {Function} promises An array of functions that return a promise
* @return {void}
*/
PromiseThrottle.prototype.addAll = function (promises) {
promises.forEach(function(promise) {
this.add(promise);
var addedPromises = promises.map(function(promise) {
return this.add(promise);
}.bind(this));

return Promise.all(addedPromises);
};

/**
Expand Down Expand Up @@ -89,4 +85,10 @@ PromiseThrottle.prototype._execute = function () {

module.exports = PromiseThrottle;

},{}]},{},[1]);
},{}],2:[function(require,module,exports){
/* global window */

'use strict';
window.PromiseThrottle = require('./main');

},{"./main":1}]},{},[2]);
12 changes: 6 additions & 6 deletions lib/main.js
Expand Up @@ -20,7 +20,7 @@ function PromiseThrottle(options) {
* @param {Function} promise A function returning the promise to be added
* @return {Promise} A promise
*/
PromiseThrottle.prototype.add = function (promise) {
PromiseThrottle.prototype.add = function(promise) {
var self = this;
return new self.promiseImplementation(function(resolve, reject) {
self.queued.push({
Expand All @@ -38,7 +38,7 @@ PromiseThrottle.prototype.add = function (promise) {
* @param {Function} promises An array of functions that return a promise
* @return {void}
*/
PromiseThrottle.prototype.addAll = function (promises) {
PromiseThrottle.prototype.addAll = function(promises) {
var addedPromises = promises.map(function(promise) {
return this.add(promise);
}.bind(this));
Expand All @@ -50,11 +50,11 @@ PromiseThrottle.prototype.addAll = function (promises) {
* Dequeues a promise
* @return {void}
*/
PromiseThrottle.prototype.dequeue = function () {
PromiseThrottle.prototype.dequeue = function() {
if (this.queued.length > 0) {
var now = new Date(),
inc = 1000 / this.requestsPerSecond,
elapsed = now - this.lastStartTime;
inc = 1000 / this.requestsPerSecond,
elapsed = now - this.lastStartTime;

if (elapsed >= inc) {
this._execute();
Expand All @@ -72,7 +72,7 @@ PromiseThrottle.prototype.dequeue = function () {
* @private
* @return {void}
*/
PromiseThrottle.prototype._execute = function () {
PromiseThrottle.prototype._execute = function() {
this.lastStartTime = new Date();
var candidate = this.queued.shift();
candidate.promise().then(function(r) {
Expand Down
16 changes: 7 additions & 9 deletions package.json
Expand Up @@ -11,22 +11,20 @@
"url": "https://github.com/jmperez/promise-throttle.git"
},
"scripts": {
"test": "make test"
},
"config": {
"blanket": {
"pattern": "//^(?!.*node_modules.*$).*lib//"
}
"start": "npm run dist",
"dist": "mkdir -p dist && browserify lib/browser.js -o dist/promise-throttle.js",
"lint": "eslint lib/*.js",
"test": "npm run lint && jest --coverage",
"travis": "npm test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
},
"keywords": [
"promise",
"throttle"
],
"devDependencies": {
"blanket": "~1.1.6",
"coveralls": "~2.11.2",
"mocha": "~2.1.0",
"mocha-lcov-reporter": "0.0.1",
"eslint": "^3.8.0",
"jest-cli": "^16.0.2",
"promise": "~6.1.0",
"sinon": "~1.12.2"
}
Expand Down

0 comments on commit 1d5a922

Please sign in to comment.