Comparing version 1.4.2 to 2.0.0
39
index.js
@@ -12,2 +12,3 @@ 'use strict'; | ||
var parseLine = require('./lib/parse-line'); | ||
var error = require('./lib/error'); | ||
@@ -30,2 +31,3 @@ function Parser() { | ||
fail: [], | ||
errors: [], | ||
}; | ||
@@ -195,2 +197,28 @@ this.testNumber = 0; | ||
Parser.prototype._handleEnd = function _handleEnd() { | ||
var plan = this.results.plans.length ? this.results.plans[0] : null; | ||
var count = this.results.asserts.length; | ||
var first = count && this.results.asserts.reduce(firstAssertion); | ||
var last = count && this.results.asserts.reduce(lastAssertion); | ||
if (!plan) { | ||
if (count > 0) { | ||
this.results.errors.push(error('no plan provided')); | ||
} | ||
return; | ||
} | ||
if (this.results.fail.length > 0) { | ||
return; | ||
} | ||
if (count !== (plan.to - plan.from + 1)) { | ||
this.results.errors.push(error('incorrect number of assertions made')); | ||
} else if (first && first.number !== plan.from) { | ||
this.results.errors.push(error('first assertion number does not equal the plan start')); | ||
} else if (last && last.number !== plan.to) { | ||
this.results.errors.push(error('last assertion number does not equal the plan end')); | ||
} | ||
}; | ||
module.exports = function (done) { | ||
@@ -218,3 +246,6 @@ | ||
.on('close', function () { | ||
parser._handleEnd(); | ||
stream.emit('output', parser.results); | ||
done(null, parser.results); | ||
@@ -254,1 +285,9 @@ }) | ||
} | ||
function firstAssertion(first, assert) { | ||
return assert.number < first.number ? assert : first; | ||
} | ||
function lastAssertion(last, assert) { | ||
return assert.number > last.number ? assert : last; | ||
} |
{ | ||
"name": "tap-out", | ||
"version": "1.4.2", | ||
"version": "2.0.0", | ||
"description": "A different tap parser", | ||
@@ -15,9 +15,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"re-emitter": "^1.0.0", | ||
"readable-stream": "^2.0.0", | ||
"split": "^1.0.0", | ||
"re-emitter": "1.1.3", | ||
"readable-stream": "2.2.9", | ||
"split": "1.0.0", | ||
"trim": "0.0.1" | ||
}, | ||
"devDependencies": { | ||
"tape": "^4.0.0" | ||
"tape": "4.6.3" | ||
}, | ||
@@ -24,0 +24,0 @@ "directories": { |
@@ -22,13 +22,15 @@ # tap-out | ||
asserts: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' } | ||
], | ||
versions: [], | ||
results: [], | ||
versions: [], | ||
comments: [], | ||
fail: [], | ||
pass: [ | ||
plans: [{ type: 'plan', raw: '1..2', from: 1, to: 2, skip: false }], | ||
pass: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' } | ||
], | ||
fail: [], | ||
errors: [] | ||
} | ||
@@ -43,3 +45,3 @@ ``` | ||
var t = tapOut(function (output) { | ||
console.log(output); | ||
@@ -76,3 +78,3 @@ }); | ||
asserts: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
{ name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' } | ||
@@ -84,3 +86,3 @@ ], | ||
fail: [], | ||
pass: [ | ||
pass: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
@@ -162,3 +164,3 @@ { name: 'true value', number: 2, ok: true, raw: 'ok 2 true value', test: 1, type: 'assert' } | ||
raw: '# tests 15', | ||
type: 'result' | ||
type: 'result' | ||
} | ||
@@ -203,3 +205,3 @@ ``` | ||
* `raw` - the raw output before it was parsed | ||
* `test` - the nubmer of the test this comment belongs to | ||
* `test` - the number of the test this comment belongs to | ||
@@ -206,0 +208,0 @@ ```js |
@@ -35,3 +35,4 @@ var parser = require('../'); | ||
comments: [], | ||
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }] | ||
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }], | ||
errors: [] | ||
}, 'output data'); | ||
@@ -76,3 +77,4 @@ }); | ||
comments: [], | ||
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }] | ||
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }], | ||
errors: [] | ||
}, 'output data'); | ||
@@ -573,1 +575,133 @@ }); | ||
}); | ||
test('output without plan', function (t) { | ||
t.plan(1); | ||
var mockTap = [ | ||
"# is true", | ||
"ok 1 true value", | ||
]; | ||
var p = parser(); | ||
p.on('output', function (output) { | ||
t.deepEqual(output, { | ||
asserts: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' } | ||
], | ||
fail: [], | ||
pass: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' } | ||
], | ||
results: [], | ||
tests: [ | ||
{ name: 'is true', number: 1, raw: '# is true', type: 'test' } | ||
], | ||
versions: [], | ||
comments: [], | ||
plans: [], | ||
errors: [ | ||
{ message: 'no plan provided', type: 'error' } | ||
] | ||
}, 'output data with empty plans and no plan provided'); | ||
}); | ||
mockTap.forEach(function (line) { | ||
p.write(line + '\n'); | ||
}); | ||
p.end(); | ||
}); | ||
test('output with assert count and plan mismatch', function (t) { | ||
t.plan(1); | ||
var mockTap = [ | ||
"# is true", | ||
"ok 1 true value", | ||
"1..2", | ||
]; | ||
var p = parser(); | ||
p.on('output', function (output) { | ||
t.deepEqual(output, { | ||
asserts: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' } | ||
], | ||
fail: [], | ||
pass: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' } | ||
], | ||
results: [], | ||
tests: [ | ||
{ name: 'is true', number: 1, raw: '# is true', type: 'test' } | ||
], | ||
versions: [], | ||
comments: [], | ||
plans: [ | ||
{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' } | ||
], | ||
errors: [ | ||
{ message: 'incorrect number of assertions made', type: 'error' } | ||
] | ||
}, 'output data with empty assert count and plan mismatch error'); | ||
}); | ||
mockTap.forEach(function (line) { | ||
p.write(line + '\n'); | ||
}); | ||
p.end(); | ||
}); | ||
test('output with plan end and assertion number mismatch', function (t) { | ||
t.plan(1); | ||
var mockTap = [ | ||
"# is true", | ||
"ok 1 true value", | ||
'ok 3 true value', | ||
"1..2", | ||
]; | ||
var p = parser(); | ||
p.on('output', function (output) { | ||
t.deepEqual(output, { | ||
asserts: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
{ name: 'true value', number: 3, ok: true, raw: 'ok 3 true value', test: 1, type: 'assert' } | ||
], | ||
fail: [], | ||
pass: [ | ||
{ name: 'true value', number: 1, ok: true, raw: 'ok 1 true value', test: 1, type: 'assert' }, | ||
{ name: 'true value', number: 3, ok: true, raw: 'ok 3 true value', test: 1, type: 'assert' } | ||
], | ||
results: [], | ||
tests: [ | ||
{ name: 'is true', number: 1, raw: '# is true', type: 'test' } | ||
], | ||
versions: [], | ||
comments: [], | ||
plans: [ | ||
{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' } | ||
], | ||
errors: [ | ||
{ message: 'last assertion number does not equal the plan end', type: 'error' } | ||
] | ||
}, 'output data with plan end error'); | ||
}); | ||
mockTap.forEach(function (line) { | ||
p.write(line + '\n'); | ||
}); | ||
p.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31763
25083
17
926
217
+ Addedbuffer-shims@1.0.0(transitive)
+ Addedprocess-nextick-args@1.0.7(transitive)
+ Addedre-emitter@1.1.3(transitive)
+ Addedreadable-stream@2.2.9(transitive)
+ Addedsplit@1.0.0(transitive)
+ Addedstring_decoder@1.0.3(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedre-emitter@1.1.4(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsplit@1.0.1(transitive)
- Removedstring_decoder@1.1.1(transitive)
Updatedre-emitter@1.1.3
Updatedreadable-stream@2.2.9
Updatedsplit@1.0.0