-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
321 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Different from https://github.com/tapjs/tap-parser | ||
// This implementation doesn't support subtests, because | ||
// subtests is not in TAP spec v12 or v13, it's in v14 draft | ||
// which only node-tap uses. | ||
// But node-tap does not run in browser, so that's irrelevant. | ||
|
||
const readline = require('readline'); | ||
|
||
module.exports = function(readableStream, cb) { | ||
const rl = readline.createInterface({ | ||
input: readableStream, | ||
crlfDelay: Infinity // '\r\n' as single line break. | ||
}); | ||
|
||
function panic(err) { | ||
rl.close(); | ||
cb(err); | ||
} | ||
|
||
function complete(passed) { | ||
rl.close(); | ||
cb(null, passed); | ||
} | ||
|
||
let plan = null; | ||
let tests = []; | ||
|
||
function captureVersion(line) { | ||
const m = line.match(/^TAP version (\d+)$/); | ||
if (m) { | ||
const version = parseInt(m[1], 10); | ||
if (version < 12 || version > 13) { | ||
throw new Error('TAP version ' + version + ' is not supported'); | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
function capturePlan(line) { | ||
const m = line.match(/^1\.\.(\d+)$/); | ||
if (m) { | ||
plan = parseInt(m[1], 10); | ||
return true; | ||
} | ||
} | ||
|
||
function captureTest(line) { | ||
const m = line.match(/^((?:not )?ok)\b/); | ||
if (m) { | ||
const pass = m[1] === 'ok'; | ||
const todo = (/# TODO /i).test(line); | ||
const skip = !todo && (/# SKIP\S*\s+/i).test(line); | ||
tests.push({pass, todo, skip}); | ||
return true; | ||
} | ||
} | ||
|
||
function captureBailout(line) { | ||
const m = line.match(/^Bail out!/); | ||
if (m) { | ||
throw new Error(line); | ||
} | ||
} | ||
|
||
rl.on('line', line => { | ||
if (line.match(/^\s*$/)) return; | ||
|
||
// console.log(' LINE: ' + line); | ||
try { | ||
captureVersion(line) || | ||
capturePlan(line) || | ||
captureTest(line) || | ||
captureBailout(line); | ||
|
||
// console.log(' PLAN: ' + plan); | ||
// console.log(' TESTS: ', tests); | ||
if (plan && tests.length === plan) { | ||
complete(tests.every(t => t.pass || t.todo || t.skip)); | ||
} | ||
} catch (err) { | ||
panic(err); | ||
} | ||
}); | ||
|
||
return rl; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.