Skip to content

Commit 51279dd

Browse files
committed
add test, eslint
1 parent 5596f29 commit 51279dd

File tree

12 files changed

+285
-100
lines changed

12 files changed

+285
-100
lines changed

.eslintrc

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
ecmaFeatures:
3+
modules: true
4+
5+
env:
6+
browser: true
7+
node: true
8+
es6: true
9+
10+
rules:
11+
comma-dangle: [2, "always-multiline"]
12+
no-dupe-args: 2
13+
no-dupe-keys: 2
14+
no-duplicate-case: 2
15+
no-empty-character-class: 2
16+
no-ex-assign: 1
17+
no-extra-boolean-cast: 1
18+
no-extra-parens: 1
19+
no-extra-semi: 1
20+
no-func-assign: 1
21+
no-inner-declarations: 1
22+
no-invalid-regexp: 1
23+
no-irregular-whitespace: 1
24+
no-negated-in-lhs: 1
25+
no-obj-calls: 1
26+
no-regex-spaces: 1
27+
no-sparse-arrays: 1
28+
no-unreachable: 1
29+
use-isnan: 1
30+
valid-typeof: 2
31+
no-unexpected-multiline: 1
32+
no-cond-assign: 1
33+
no-constant-condition: 1
34+
no-control-regex: 1
35+
no-debugger: 1
36+
# code style
37+
consistent-return: 1
38+
curly: 1
39+
default-case: 1
40+
dot-notation: 1
41+
dot-location: [1, "property"]
42+
eqeqeq: 1
43+
no-else-return: 1
44+
no-lone-blocks: 1
45+
no-loop-func: 1
46+
no-multi-spaces: 1
47+
no-multi-str: 1
48+
no-proto: 1
49+
no-redeclare: 1
50+
no-return-assign: 1
51+
no-sequences: 1
52+
no-throw-literal: 1
53+
no-unused-expressions: 1
54+
no-void: 1
55+
no-warning-comments: [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }]
56+
no-with: 1
57+
radix: 1
58+
wrap-iife: [2, "inside"]
59+
no-delete-var: 1
60+
no-shadow-restricted-names: 1
61+
no-shadow: 1
62+
no-undef: 2
63+
no-unused-vars: 1
64+
brace-style: [1, "1tbs", { "allowSingleLine": true }]
65+
comma-spacing: 1
66+
comma-style: 1
67+
consistent-this: [2, "self"]
68+
indent: [2, 2]
69+
key-spacing: 1
70+
max-nested-callbacks: [2, 3]
71+
no-lonely-if: 2
72+
no-mixed-spaces-and-tabs: 2
73+
no-nested-ternary: 2
74+
no-spaced-func: 2
75+
no-trailing-spaces: 2
76+
one-var: [2, "never"]
77+
operator-linebreak: 2
78+
quote-props: [2, "as-needed"]
79+
quotes: [2, "single", "avoid-escape"]
80+
semi: [2, "always"]
81+
space-after-keywords: 2
82+
space-before-blocks: 2
83+
space-infix-ops: 2
84+
space-return-throw-case: 2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/node_modules/
2+
.DS_Store
3+
npm-debug.log

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.gitignore
22
/test/
33
/example/
4+
npm-debug.log

index.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ var util = require('util');
22
var runTask = require('orchestrator/lib/runTask');
33

44
module.exports = function (callbacks) {
5-
if (!callbacks) {
6-
callbacks = [];
7-
}
8-
if (!Array.isArray(callbacks)) {
9-
callbacks = Array.prototype.slice.call(arguments);
10-
}
11-
callbacks = callbacks.filter(util.isFunction);
5+
if (!callbacks) {
6+
callbacks = [];
7+
}
8+
if (!Array.isArray(callbacks)) {
9+
callbacks = Array.prototype.slice.call(arguments);
10+
}
11+
callbacks = callbacks.filter(util.isFunction);
1212

13-
var maxLen = callbacks.length;
13+
var maxLen = callbacks.length;
1414

15-
return function (done) {
16-
done = done || function () {};
15+
return function (done) {
16+
done = done || function () {};
1717

18-
(function next(i) {
19-
if (i >= maxLen) {
20-
return done();
21-
}
22-
var cb = callbacks[i];
23-
runTask(cb, function (err) {
24-
if (err) {
25-
return done(err);
26-
}
27-
next(++i);
28-
});
29-
}(0));
30-
};
18+
(function next(i) {
19+
if (i >= maxLen) {
20+
return done();
21+
}
22+
var cb = callbacks[i];
23+
runTask(cb, function (err) {
24+
if (err) {
25+
return done(err);
26+
}
27+
next(++i);
28+
});
29+
})(0);
30+
};
3131
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Make a new callback to run input callbacks in sequence",
55
"main": "index.js",
66
"scripts": {
7-
"test": "tap test/*.js"
7+
"test": "eslint . && tap test/*.js"
88
},
99
"repository": {
1010
"type": "git",
@@ -27,6 +27,7 @@
2727
"orchestrator": "^0.3.7"
2828
},
2929
"devDependencies": {
30+
"eslint": "^1.1.0",
3031
"tap": "^1.3.1"
3132
}
3233
}

test/async.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var test = require('tape');
2+
var sequence = require('..');
3+
4+
test('async', function(t) {
5+
t.plan(4);
6+
var i = 0;
7+
sequence(
8+
next(0),
9+
next(1),
10+
next(2)
11+
)(function () {
12+
t.ok(true);
13+
});
14+
15+
function next(j) {
16+
return function (done) {
17+
process.nextTick(function () {
18+
t.equal(i++, j);
19+
done();
20+
});
21+
};
22+
}
23+
});
24+

test/index.js

Lines changed: 0 additions & 76 deletions
This file was deleted.

test/mixed.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var test = require('tape');
2+
var sequence = require('..');
3+
var Readable = require('stream').Readable;
4+
5+
test('mixed', function(t) {
6+
t.plan(5);
7+
var i = 0;
8+
sequence(
9+
function () {
10+
t.equal(i++, 0);
11+
},
12+
function (done) {
13+
process.nextTick(function () {
14+
t.equal(i++, 1);
15+
done();
16+
});
17+
},
18+
function () {
19+
return new Promise(function (resolve) {
20+
t.equal(i++, 2);
21+
resolve();
22+
});
23+
},
24+
function () {
25+
var s = Readable();
26+
process.nextTick(function () {
27+
t.equal(i++, 3);
28+
s.push(null);
29+
});
30+
return s;
31+
}
32+
)(function () {
33+
t.ok(true);
34+
});
35+
});
36+

test/promise.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var test = require('tape');
2+
var sequence = require('..');
3+
4+
test('promise', function(t) {
5+
t.plan(4);
6+
var i = 0;
7+
sequence(
8+
next(0),
9+
next(1),
10+
next(2)
11+
)(function () {
12+
t.ok(true);
13+
});
14+
15+
function next(j) {
16+
return function () {
17+
return new Promise(function (resolve) {
18+
t.equal(i++, j);
19+
resolve();
20+
});
21+
};
22+
}
23+
});
24+

test/recursive.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var test = require('tape');
2+
var sequence = require('..');
3+
var Readable = require('stream').Readable;
4+
5+
test('recursive', function(t) {
6+
t.plan(5);
7+
var i = 0;
8+
var sync = function () {
9+
t.equal(i++, 0);
10+
};
11+
var async = function (done) {
12+
process.nextTick(function () {
13+
t.equal(i++, 1);
14+
done();
15+
});
16+
};
17+
var stream = function () {
18+
var s = Readable();
19+
process.nextTick(function () {
20+
t.equal(i++, 3);
21+
s.push(null);
22+
});
23+
return s;
24+
};
25+
var promise = function () {
26+
return new Promise(function (resolve) {
27+
t.equal(i++, 2);
28+
resolve();
29+
});
30+
};
31+
32+
sequence(
33+
sync,
34+
sequence(
35+
async,
36+
sequence(
37+
promise,
38+
sequence(
39+
stream
40+
)
41+
)
42+
)
43+
)(function () {
44+
t.ok(true);
45+
});
46+
});
47+

0 commit comments

Comments
 (0)