tap-parser
Advanced tools
Comparing version 1.2.2 to 1.3.0
83
index.js
// Transforms a stream of TAP into a stream of result objects | ||
// and string comments. Emits "results" event with summary. | ||
var Writable = require('stream').Writable | ||
/* istanbul ignore if */ | ||
if (!Writable) { | ||
@@ -28,4 +29,8 @@ try { | ||
var n = +time[1] | ||
if (time[2] === 's') | ||
n *= 1000 | ||
if (time[2] === 's') { | ||
// JS does weird things with floats. Round it off a bit. | ||
n *= 1000000 | ||
n = Math.round(n) | ||
n /= 1000 | ||
} | ||
return [ 'time', n ] | ||
@@ -116,2 +121,3 @@ } | ||
this.commentQueue = [] | ||
this.buffered = options.buffered || null | ||
@@ -154,7 +160,2 @@ this.count = 0 | ||
if (!this.current) { | ||
this.nonTap(yamlish) | ||
return | ||
} | ||
try { | ||
@@ -273,4 +274,7 @@ var diags = yaml.safeLoad(yamlish) | ||
if (this.failures.length) | ||
if (this.failures.length) { | ||
final.failures = this.failures | ||
} else { | ||
final.failures = [] | ||
} | ||
@@ -332,3 +336,6 @@ this.emit('complete', final) | ||
Parser.prototype.startChild = function (indent, line) { | ||
if (!line.substr(indent.length).match(/^# Subtest:/)) { | ||
var maybeBuffered = this.current && this.current.name.match(/{$/) | ||
var streamComment = 0 === line.indexOf(indent + '# Subtest:') | ||
if (!maybeBuffered && !streamComment) { | ||
this.nonTap(line) | ||
@@ -338,3 +345,4 @@ return | ||
this.emitResult() | ||
if (streamComment) | ||
this.emitResult() | ||
@@ -344,3 +352,4 @@ this.child = new Parser({ | ||
parent: this, | ||
level: this.level + 1 | ||
level: this.level + 1, | ||
buffered: this.current | ||
}) | ||
@@ -355,3 +364,12 @@ | ||
}) | ||
this.child.write(line.substr(indent.length)) | ||
line = line.substr(indent.length) | ||
if (streamComment) { | ||
this.child.emit('line', line) | ||
this.child.emitComment(line) | ||
} else { | ||
this.current.name = this.current.name.replace(/{$/, '').trim() | ||
this.child.emitComment('# Subtest: ' + this.current.name) | ||
this.child._parse(line) | ||
} | ||
} | ||
@@ -366,2 +384,9 @@ | ||
function maybeEnd (child, line) { | ||
if (child.buffered) | ||
return line.trim() === '}' | ||
else | ||
return /^(not )?ok/.test(line) | ||
} | ||
Parser.prototype._parse = function (line) { | ||
@@ -417,3 +442,7 @@ // normalize line endings | ||
// still belongs to the child. | ||
var indent = line.match(/^[ \t]*/)[0] | ||
if (this.child) { | ||
if (indent && !this.child.indent) { | ||
this.child.indent = indent | ||
} | ||
if (line.indexOf(this.child.indent) === 0) { | ||
@@ -428,5 +457,7 @@ line = line.substr(this.child.indent.length) | ||
} | ||
// a child test can only end when we get an test point line. | ||
// a buffered child test can only end on } | ||
// streamed child test can only end when we get an test point line. | ||
// anything else is extra. | ||
if (this.child.sawValidTap && !/^(not )?ok/.test(line)) { | ||
if (this.child.sawValidTap && !maybeEnd(this.child, line)) { | ||
this.nonTap(line) | ||
@@ -437,5 +468,6 @@ return | ||
// comment, but let "# Subtest:" comments start a child | ||
// comment, but let "# Subtest:" comments start a streamed child | ||
var c = line.match(/^(\s+)?#(.*)/) | ||
if (c && !(c[1] && /^ Subtest: /.test(c[2]))) { | ||
var isChildTest = c && /^ Subtest: /.test(c[2]) | ||
if (c && !isChildTest) { | ||
this.emitComment(line) | ||
@@ -452,6 +484,9 @@ return | ||
var indent = line.match(/^[ \t]+/) | ||
// the `# Subtest: <name>` comment is not guaranteed to be indented | ||
// handle this by calling it a zero-width indent for now. | ||
if (isChildTest && !indent) { | ||
this.startChild('', line) | ||
} | ||
if (indent) { | ||
indent = indent[0] | ||
// if we don't have a current res, then it can't be yamlish. | ||
@@ -481,4 +516,5 @@ // If it is a subtest command, then it's a child test. | ||
// oops! was not actually yamlish, I guess. | ||
// this is a case where the indent is shortened mid-yamlish block | ||
// treat as garbage | ||
this.nonTap(this.yamlish + line) | ||
this.nonTap(this.yind + '---\n' + this.yamlish + line) | ||
this.emitResult() | ||
@@ -502,3 +538,3 @@ return | ||
if (this.yind) { | ||
this.nonTap(this.yamlish) | ||
this.nonTap(this.yind + '---\n' + this.yamlish) | ||
this.yamlish = '' | ||
@@ -540,2 +576,7 @@ this.yind = '' | ||
if (this.child && this.child.buffered && line.trim() === '}') { | ||
this.emitResult() | ||
return | ||
} | ||
var res = this.createResult(line) | ||
@@ -542,0 +583,0 @@ if (!res) { |
{ | ||
"name": "tap-parser", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "parse the test anything protocol", | ||
@@ -11,12 +11,11 @@ "main": "index.js", | ||
"events-to-array": "^1.0.1", | ||
"inherits": "~2.0.1", | ||
"js-yaml": "^3.2.7" | ||
}, | ||
"devDependencies": { | ||
"glob": "^5.0.2", | ||
"tap": "^1.2.0", | ||
"tape": "^3.5.0" | ||
"glob": "^7.0.5", | ||
"tap": "^6.3.0" | ||
}, | ||
"scripts": { | ||
"test": "tap test/*.js" | ||
"test": "tap test/*.js --cov", | ||
"regen-fixtures": "node scripts/generate-test.js test/fixtures/*.tap" | ||
}, | ||
@@ -23,0 +22,0 @@ "testling": { |
Sorry, the diff of this file is not supported yet
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22124
3
2
538
183
0
1
- Removedinherits@~2.0.1