Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit test plans #18

Merged
merged 1 commit into from
Nov 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function Parser() {
versions: [],
results: [],
comments: [],
plans: [],
pass: [],
fail: [],
};
Expand Down Expand Up @@ -184,7 +185,7 @@ module.exports = function (done) {
var stream = new PassThrough();
var parser = Parser();
reemit(parser, stream, [
'test', 'assert', 'version', 'result', 'pass', 'fail', 'comment'
'test', 'assert', 'version', 'result', 'pass', 'fail', 'comment', 'plan'
]);

stream
Expand Down
4 changes: 4 additions & 0 deletions lib/parse-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ module.exports = function (line) {
if (types.is('test', line)) {
return types.test(line);
}

if (types.is('plan', line)) {
return types.plan(line);
}
};
17 changes: 17 additions & 0 deletions lib/plan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var expr = require('./utils/regexes');

var exports = module.exports = function (line) {
var m = expr.plan.exec(line);
return {
type: 'plan',
raw: line,
from: m[1] && Number(m[1]),
to: m[2] && Number(m[2]),
skip: m[3]
};
};

exports.equals = function (line) {

return expr.plan.test(line);
};
1 change: 1 addition & 0 deletions lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var types = module.exports = {
assert: require('./assert'),
test: require('./test'),
version: require('./version'),
plan: require('./plan'),
is: function (type, line) {

var type = types[type];
Expand Down
37 changes: 33 additions & 4 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ test('output event', function (t) {
var mockTap = [
'# is true',
'ok 1 true value',
'ok 2 true value'
'ok 2 true value',
'1..2'
];

var p = parser();
Expand All @@ -30,7 +31,8 @@ test('output event', function (t) {
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
versions: [],
comments: []
comments: [],
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }]
}, 'output data');
});

Expand All @@ -48,7 +50,8 @@ test('output callback', function (t) {
var mockTap = [
'# is true',
'ok 1 true value',
'ok 2 true value'
'ok 2 true value',
'1..2'
];

var p = parser(function (err, output) {
Expand All @@ -68,7 +71,8 @@ test('output callback', function (t) {
{ name: 'is true', number: 1, raw: '# is true', type: 'test' }
],
versions: [],
comments: []
comments: [],
plans: [{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }]
}, 'output data');
});

Expand Down Expand Up @@ -363,6 +367,31 @@ test('failed assertion', function (t) {
p.end();
});

test('plan', function (t) {

var mockTap = [
'1..2',
];

var plans = [];
var p = parser(function () {
t.deepEqual(plans, [
{ from: 1, to: 2, raw: '1..2', skip: undefined, type: 'plan' }
]);
t.end();
});

p.on('plan', function (plan) {
plans.push(plan);
});

mockTap.forEach(function (line) {

p.write(line + '\n');
});
p.end();
});


// NOTE: comments output the same as test names.
// This makes it very difficult to parse them.
Expand Down