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

Update to latest version of tap and tap-parser #314

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7db3bdc
update test/array.js to use concat-stream instead of tap.createConsum…
nelsonic Aug 28, 2016
0e04ba7
remove redundant .map that checks typeof r === 'object' ... rows are …
nelsonic Aug 28, 2016
c319f83
update test/default-messages.js to match output of latest version of …
nelsonic Aug 28, 2016
fae3c51
add getStackTrace method to extract the error message from tap output…
nelsonic Aug 28, 2016
f944fbb
update test/end-as-callback.js using concat-stream instead of tap.cre…
nelsonic Aug 28, 2016
c33c0bf
update test/exit.js to use concat-stream instead of tap.createConsume…
nelsonic Aug 28, 2016
c68c34c
update test/fail.js to use concat-stream instead of tap.createConsume…
nelsonic Aug 28, 2016
370b6fb
update test/nested-sync-noplan-noend.js to use concat-stream instead …
nelsonic Aug 28, 2016
cf6fcb4
update test/nested.js to use concat-stream instead of tap.createConsu…
nelsonic Aug 28, 2016
8afdd1e
update test/require.js to use concat-stream instead of tap.createCons…
nelsonic Aug 28, 2016
a0f7d73
update test/only.js to use concat-stream instead of tap.createConsume…
nelsonic Aug 28, 2016
453bd55
update test/timeoutAfter.js to use concat-stream instead of tap.creat…
nelsonic Aug 28, 2016
771e411
update test/too_many.js to use concat-stream instead of tap.createCon…
nelsonic Aug 28, 2016
6633e9a
temporarily comment out 3 tests in test/skip.js makes the other tests…
nelsonic Aug 28, 2016
27ce042
remove redundant tests from test/skip.js - still testing the document…
nelsonic Aug 28, 2016
4b52e9a
remove redundant tests in test/throws.js (assertion unchanged! Passes…
nelsonic Aug 28, 2016
ceec1f1
tidy up before requesting pull request code review.
nelsonic Aug 28, 2016
3bdd82f
update tests to match format in test/skip.js (consistency) see: https…
nelsonic Aug 28, 2016
ce0b410
split the tap output array before comparing in test/require.js to kee…
nelsonic Aug 28, 2016
82ba4d4
update all instances of spawn to use path.join for windows compatabil…
nelsonic Aug 29, 2016
c4025c1
update tests to reflect double-blank-lines in Tap output as discussed…
nelsonic Aug 29, 2016
e721508
tidy up test/default-messages.js as discussed in https://github.com/s…
nelsonic Sep 2, 2016
d93d3e3
tidy up tests containing spawn discussed in https://github.com/substa…
nelsonic Sep 2, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"concat-stream": "~1.5.1",
"falafel": "~1.2.0",
"js-yaml": "~3.6.1",
"tap": "~0.7.1",
"tap-parser": "~1.2.2"
"tap": "~7.0.0",
"tap-parser": "~2.0.0"
},
"scripts": {
"test": "tap test/*.js"
Expand Down
42 changes: 17 additions & 25 deletions test/array.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
var falafel = require('falafel');
var tape = require('../');
var tap = require('tap');
var trim = require('string.prototype.trim');
var concat = require('concat-stream');

tap.test('array test', function (tt) {
tt.plan(1);

var test = tape.createHarness();
var tc = tap.createConsumer();

var rows = [];
tc.on('data', function (r) { rows.push(r) });
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
tt.same(rs, [
test.createStream().pipe(concat(function (rows) {
tt.same(rows.toString('utf8'), [
'TAP version 13',
'array',
{ id: 1, ok: true, name: 'should be equivalent' },
{ id: 2, ok: true, name: 'should be equivalent' },
{ id: 3, ok: true, name: 'should be equivalent' },
{ id: 4, ok: true, name: 'should be equivalent' },
{ id: 5, ok: true, name: 'should be equivalent' },
'tests 5',
'pass 5',
'ok'
]);
});

test.createStream().pipe(tc);
'# array',
'ok 1 should be equivalent',
'ok 2 should be equivalent',
'ok 3 should be equivalent',
'ok 4 should be equivalent',
'ok 5 should be equivalent',
'',
'1..5',
'# tests 5',
'# pass 5',
'',
'# ok'
].join('\n') + '\n');
}));

test('array', function (t) {
t.plan(5);
Expand Down
50 changes: 22 additions & 28 deletions test/default-messages.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
var tap = require('tap');
var spawn = require('child_process').spawn;
var trim = require('string.prototype.trim');
var concat = require('concat-stream');

tap.test('default messages', function (t) {
t.plan(1);

var tc = tap.createConsumer();
var ps = spawn(process.execPath,
[ require('path').join(__dirname, 'messages', 'defaults.js') ]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd prefer this indentation to be such that if the entire invocation doesn't fit on one line, each argument goes on a line by itself, as does the closing invocation paren.

Copy link
Contributor Author

@nelsonic nelsonic Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb like this:

var ps = spawn(
  process.execPath,
  [ require('path').join(__dirname, 'messages', 'defaults.js') ]
);

There does not appear to be a line-length rule/guideline in the project.
in-lining the the code is 96 characters is that acceptable?

var ps = spawn(process.execPath, [ require('path').join(__dirname, 'messages', 'defaults.js') ]);

(I'm used to aiming for max 80 chars per line...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first example is exactly what I had in mind.

Personally I find "max line length" restrictions silly. If your first example is too long for you, you could do:

var path = require('path');
var ps = spawn(
  process.execPath,
  [
    path.join(__dirname, 'messages', 'defaults.js')
  ]
);

(in either case, please move the require to a variable at the top level)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!
Went with the single line with the `require('path') moved above its only 89 chars which I think is acceptable:

var ps = spawn(process.execPath, [path.join(__dirname, 'messages', 'defaults.js')]);


var rows = [];
tc.on('data', function (r) { rows.push(r) });
tc.on('end', function () {
var rs = rows.map(function (r) {
if (r && typeof r === 'object') {
return { id : r.id, ok : r.ok, name : trim(r.name) };
}
else return r;
});
t.same(rs, [
'TAP version 13',
'default messages',
{ id: 1, ok: true, name: 'should be truthy' },
{ id: 2, ok: true, name: 'should be falsy' },
{ id: 3, ok: true, name: 'should be equal' },
{ id: 4, ok: true, name: 'should not be equal' },
{ id: 5, ok: true, name: 'should be equivalent' },
{ id: 6, ok: true, name: 'should be equivalent' },
{ id: 7, ok: true, name: 'should be equivalent' },
'tests 7',
'pass 7',
'ok'
]);
});
ps.stdout.pipe(concat(function (rows) {

var ps = spawn(process.execPath, [ __dirname + '/messages/defaults.js' ]);
ps.stdout.pipe(tc);
t.same(rows.toString('utf8'), [
'TAP version 13',
'# default messages',
'ok 1 should be truthy',
'ok 2 should be falsy',
'ok 3 should be equal',
'ok 4 should not be equal',
'ok 5 should be equivalent',
'ok 6 should be equivalent',
'ok 7 should be equivalent',
'',
'1..7',
'# tests 7',
'# pass 7',
'',
'# ok'
].join('\n') + '\n\n');
}));
});
3 changes: 2 additions & 1 deletion test/double_end.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var spawn = require('child_process').spawn;

test(function (t) {
t.plan(2);
var ps = spawn(process.execPath, [ __dirname + '/double_end/double.js' ]);
var ps = spawn(process.execPath,
[ require('path').join(__dirname, 'double_end', 'double.js') ]);
ps.on('exit', function (code) {
t.equal(code, 1);
});
Expand Down
79 changes: 50 additions & 29 deletions test/end-as-callback.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
var tap = require("tap");
var tape = require("../");
var trim = require('string.prototype.trim');
var concat = require('concat-stream');

tap.test("tape assert.end as callback", function (tt) {
var test = tape.createHarness({ exit: false })
var tc = tap.createConsumer()

var rows = []
tc.on("data", function (r) { rows.push(r) })
tc.on("end", function () {
var rs = rows.map(function (r) {
return r && typeof r === "object" ?
{ id: r.id, ok: r.ok, name: trim(r.name) } :
r
})

tt.deepEqual(rs, [
"TAP version 13",
"do a task and write",
{ id: 1, ok: true, name: "null" },
{ id: 2, ok: true, name: "should be equal" },
"do a task and write fail",
{ id: 3, ok: true, name: "null" },
{ id: 4, ok: true, name: "should be equal" },
{ id: 5, ok: false, name: "Error: fail" },
"tests 5",
"pass 4",
"fail 1"
])


test.createStream().pipe(concat(function (rows) {
tt.equal(rows.toString('utf8'), [
'TAP version 13',
'# do a task and write',
'ok 1 null',
'ok 2 should be equal',
'# do a task and write fail',
'ok 3 null',
'ok 4 should be equal',
'not ok 5 Error: fail',
getStackTrace(rows), // tap error stack
'',
'1..5',
'# tests 5',
'# pass 4',
'# fail 1'
].join('\n') + '\n');
tt.end()
})

test.createStream().pipe(tc)
}));

test("do a task and write", function (assert) {
fakeAsyncTask("foo", function (err, value) {
Expand Down Expand Up @@ -64,3 +55,33 @@ function fakeAsyncWrite(name, cb) {
function fakeAsyncWriteFail(name, cb) {
cb(new Error("fail"))
}

/**
* extract the stack trace for the failed test.
* this will change dependent on the environment
* so no point hard-coding it in the test assertion
* see: https://git.io/v6hGG for example
* @param String rows - the tap output lines
* @returns String stacktrace - just the error stack part
*/
function getStackTrace(rows) {
var stacktrace = ' ---\n';
var extract = false;
rows.toString('utf8').split('\n').forEach(function (row) {
if (!extract) {
if (row.indexOf('---') > -1) { // start of stack trace
extract = true;
}
} else {
if (row.indexOf('...') > -1) { // end of stack trace
extract = false;
stacktrace += ' ...';
} else {
stacktrace += row + '\n';
}

}
});
// console.log(stacktrace);
return stacktrace;
}