Skip to content

Commit 4c26940

Browse files
committed
tap-summary
1 parent 9616222 commit 4c26940

13 files changed

+621
-2
lines changed

.eslintrc

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

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store
3+
npm-debug.log

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
example
2+
test
3+
changelog.md
4+
.*

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: node_js
2+
node_js:
3+
- "5"
4+
- "4"
5+
- "0.12"
6+
- "0.11"
7+
- "iojs"

README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1-
# tap-traceback
2-
Summarize TAP with tracebacks
1+
# tap-summary
2+
Summarize TAP.
3+
4+
## Usage
5+
6+
```javascript
7+
var reporter = require('tap-summary')()
8+
9+
```
10+
11+
or in `package.json`
12+
13+
```json
14+
{
15+
"scripts": {
16+
"test": "tape test/*.js | tap-summary"
17+
}
18+
}
19+
```
20+
21+
## Example
22+
23+
![summary](example/summary.png)
24+

bin/cmd.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
3+
var reporter = require('..')()
4+
5+
process.stdin
6+
.pipe(reporter)
7+
.pipe(process.stdout)
8+
9+
process.on('exit', function (status) {
10+
if (status === 1) {
11+
process.exit(1)
12+
}
13+
if (reporter.failed) {
14+
process.exit(1)
15+
}
16+
})

example/math/index.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This is copied from [math-hacker](https://github.com/zoubin/math-hacker/blob/master/index.js)
2+
3+
// bugfix: (2.385).toFixed(2) === '2.38'
4+
exports.toFixed = toFixed
5+
function toFixed(num, digits) {
6+
digits = ~~digits
7+
if (!digits) {
8+
return '' + Math.round(num)
9+
}
10+
var str = num + 'e' + digits
11+
num = Math.round(str)
12+
str = num + 'e' + -digits
13+
num = +str + ''
14+
var p = precision(num)
15+
if (p === 0) {
16+
num += '.'
17+
}
18+
while (p++ < digits) {
19+
num += '0'
20+
}
21+
return num
22+
}
23+
24+
// bugfix: 0.34 + 0.01 === 0.35000000000000003
25+
exports.add = add
26+
function add(a, b) {
27+
var p = Math.max(precision(a), precision(b))
28+
if (!p) {
29+
return +a + +b
30+
}
31+
var as = a + 'e' + p
32+
var bs = b + 'e' + p
33+
var sum = +as + +bs
34+
return +(sum + 'e-' + p)
35+
}
36+
37+
exports.precision = precision
38+
function precision(num) {
39+
num = +num
40+
if (~~num === num) {
41+
return 0
42+
}
43+
var str = '' + num
44+
return str.length - 1 - str.indexOf('.')
45+
}

example/summary.png

79.9 KB
Loading

example/test.js

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
var test = require('tape')
2+
var math = require('./math')
3+
4+
test('t.plan', function(t) {
5+
t.plan(3)
6+
7+
t.equal(
8+
math.toFixed(2.385, 2),
9+
'2.39'
10+
)
11+
next(function () {
12+
t.equal(
13+
math.toFixed(2.384, 2),
14+
'2.38'
15+
)
16+
t.equal(
17+
math.toFixed(2, 2),
18+
'2.00'
19+
)
20+
})
21+
})
22+
23+
test('t.end', function(t) {
24+
t.equal(
25+
math.precision(0),
26+
0
27+
)
28+
t.equal(
29+
math.precision(0.1),
30+
1
31+
)
32+
var plan = 10
33+
;(function NEXT() {
34+
next(function () {
35+
t.equal(
36+
math.precision(0.1),
37+
--plan === 5 ? 2 : 1
38+
)
39+
if (plan) {
40+
NEXT()
41+
} else {
42+
console.log('DONE')
43+
t.end()
44+
}
45+
})
46+
})()
47+
})
48+
49+
test('promise support', function(t) {
50+
var plan = 10
51+
t.equal(
52+
math.add(0.34, 0.01),
53+
0.35
54+
)
55+
t.equal(
56+
math.add(1.1111, -1.11),
57+
0.0011
58+
)
59+
// the test will end when the returned promise resolves
60+
return new Promise(function (rs) {
61+
(function NEXT() {
62+
next(function () {
63+
t.equal(
64+
math.add(1, 2),
65+
--plan === 5 ? 2 : 3
66+
)
67+
if (plan) {
68+
NEXT()
69+
} else {
70+
console.log('DONE')
71+
rs()
72+
}
73+
})
74+
})()
75+
})
76+
})
77+
78+
test('callback support', function(t, cb) {
79+
next(function () {
80+
t.equal(
81+
math.add(0.34, 0.01),
82+
0.35
83+
)
84+
cb()
85+
})
86+
})
87+
88+
test('check `https://github.com/zoubin/task-tape` for more information', function(t) {
89+
t.task(function (cb) {
90+
next(function () {
91+
t.equal(
92+
math.precision(0.1),
93+
1
94+
)
95+
cb()
96+
})
97+
})
98+
})
99+
100+
function next(fn) {
101+
setTimeout(function() {
102+
fn()
103+
}, 100)
104+
}
105+

0 commit comments

Comments
 (0)