Skip to content

Commit d5246bd

Browse files
authored
Merge pull request #11 from achappuis/master
[fix] fix issues when no test or no assert names are provided
2 parents cdb5b22 + 3f9c506 commit d5246bd

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- fixes issue when no assert name is provided
4+
- fixes issue when no test name is provided with TAP comment
35
- Change behavior when no output file is given to tap-html to restore what is described in README.md
46

57
# 1.0.1 (04/20/2019)

index.js

+25-11
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ module.exports = function tapHTML (callback) {
1414

1515
const startTime = Date.now();
1616

17+
function pushTest(name) {
18+
data.push({
19+
type: 'test',
20+
name: name,
21+
start: Date.now(),
22+
assertions: []
23+
});
24+
25+
// get the current index of the plan
26+
// so that we can use this to push the current assertions to it
27+
currentPlan += 1;
28+
currentAssertion = -1;
29+
}
30+
1731
tap.on('comment', (res) => {
1832
if (!plan) {
19-
data.push({
20-
type: 'test',
21-
name: res,
22-
start: Date.now(),
23-
assertions: []
24-
});
25-
26-
// get the current index of the plan
27-
// so that we can use this to push the current assertions to it
28-
currentPlan += 1;
29-
currentAssertion = -1;
33+
pushTest(res);
3034
}
3135
});
3236

@@ -43,6 +47,16 @@ module.exports = function tapHTML (callback) {
4347
});
4448

4549
tap.on('assert', (res) => {
50+
// If no plan is registered yet, create a default plan.
51+
if(currentPlan == -1) {
52+
pushTest('default');
53+
}
54+
55+
// TAP does not require a name. If no name is registered, set a default name.
56+
if (!res.name) {
57+
res.name = 'test #' + res.id;
58+
}
59+
4660
data[currentPlan].assertions.push({
4761
type: 'assert',
4862
number: res.id,

0 commit comments

Comments
 (0)