-
-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve yaml formatting of diagnostic information
- Loading branch information
Michael Hayes
committed
Aug 12, 2015
1 parent
d26e522
commit b73d2bf
Showing
6 changed files
with
191 additions
and
44 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 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 |
---|---|---|
@@ -1,43 +1,36 @@ | ||
var tape = require('../'); | ||
var tap = require('tap'); | ||
var concat = require('concat-stream'); | ||
|
||
tap.test('circular test', function (assert) { | ||
var test = tape.createHarness({ exit : false }); | ||
var tc = tap.createConsumer(); | ||
assert.plan(1); | ||
|
||
var rows = []; | ||
tc.on('data', function (r) { rows.push(r) }); | ||
tc.on('end', function () { | ||
// console.log("rs", rows) | ||
|
||
// console.log("deepEqual?") | ||
|
||
assert.same(rows, [ | ||
"TAP version 13" | ||
, "circular" | ||
, { id: 1 | ||
, ok: false | ||
, name: " should be equal" | ||
, operator: "equal" | ||
, expected: "{}" | ||
, actual: '{ circular: [Circular] }' | ||
} | ||
, "tests 1" | ||
, "pass 0" | ||
, "fail 1" | ||
]) | ||
assert.end() | ||
}) | ||
|
||
// tt.equal(10, 10) | ||
// tt.end() | ||
|
||
test.createStream().pipe(tc); | ||
test.createStream().pipe(concat(function (body) { | ||
assert.equal( | ||
body.toString('utf8'), | ||
'TAP version 13\n' | ||
+ '# circular\n' | ||
+ 'not ok 1 should be equal\n' | ||
+ ' ---\n' | ||
+ ' operator: equal\n' | ||
+ ' expected: |-\n' | ||
+ ' {}\n' | ||
+ ' actual: |-\n' | ||
+ ' { circular: [Circular] }\n' | ||
+ ' ...\n' | ||
+ '\n' | ||
+ '1..1\n' | ||
+ '# tests 1\n' | ||
+ '# pass 0\n' | ||
+ '# fail 1\n' | ||
); | ||
})); | ||
|
||
test("circular", function (t) { | ||
t.plan(1) | ||
var circular = {} | ||
circular.circular = circular | ||
t.equal(circular, {}) | ||
t.plan(1); | ||
var circular = {}; | ||
circular.circular = circular; | ||
t.equal(circular, {}); | ||
}) | ||
}) |
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,68 @@ | ||
var tape = require('../'); | ||
var tap = require('tap'); | ||
var concat = require('concat-stream'); | ||
var tapParser = require('tap-parser'); | ||
var yaml = require('js-yaml'); | ||
|
||
tap.test('deep equal failure', function (assert) { | ||
var test = tape.createHarness({ exit : false }); | ||
var stream = test.createStream(); | ||
var parser = tapParser(); | ||
assert.plan(3); | ||
|
||
stream.pipe(parser); | ||
stream.pipe(concat(function (body) { | ||
assert.equal( | ||
body.toString('utf8'), | ||
'TAP version 13\n' | ||
+ '# deep equal\n' | ||
+ 'not ok 1 should be equal\n' | ||
+ ' ---\n' | ||
+ ' operator: equal\n' | ||
+ ' expected: |-\n' | ||
+ ' { b: 2 }\n' | ||
+ ' actual: |-\n' | ||
+ ' { a: 1 }\n' | ||
+ ' ...\n' | ||
+ '\n' | ||
+ '1..1\n' | ||
+ '# tests 1\n' | ||
+ '# pass 0\n' | ||
+ '# fail 1\n' | ||
); | ||
|
||
assert.deepEqual(getDiag(body), { | ||
operator: 'equal', | ||
expected: '{ b: 2 }', | ||
actual: '{ a: 1 }' | ||
}); | ||
})); | ||
|
||
parser.once('assert', function (data) { | ||
assert.deepEqual(data, { | ||
ok: false, | ||
id: 1, | ||
name: 'should be equal', | ||
diag: { | ||
operator: 'equal', | ||
expected: '{ b: 2 }', | ||
actual: '{ a: 1 }' | ||
} | ||
}); | ||
}); | ||
|
||
test("deep equal", function (t) { | ||
t.plan(1); | ||
t.equal({a: 1}, {b: 2}); | ||
}); | ||
}) | ||
|
||
function getDiag (body) { | ||
var yamlStart = body.indexOf(' ---'); | ||
var yamlEnd = body.indexOf(' ...\n'); | ||
var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { | ||
return line.slice(2); | ||
}).join('\n'); | ||
|
||
return yaml.safeLoad(diag); | ||
} |
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,77 @@ | ||
var tape = require('../'); | ||
var tap = require('tap'); | ||
var concat = require('concat-stream'); | ||
var tapParser = require('tap-parser'); | ||
var yaml = require('js-yaml'); | ||
|
||
tap.test('preserves stack trace with newlines', function (tt) { | ||
tt.plan(3); | ||
|
||
var test = tape.createHarness(); | ||
var stream = test.createStream(); | ||
var parser = stream.pipe(tapParser()); | ||
var stackTrace = 'foo\n bar'; | ||
|
||
parser.once('assert', function (data) { | ||
tt.deepEqual(data, { | ||
ok: false, | ||
id: 1, | ||
name: "Error: Preserve stack", | ||
diag: { | ||
stack: stackTrace, | ||
operator: 'error', | ||
expected: 'undefined', | ||
actual: '[Error: Preserve stack]' | ||
} | ||
}); | ||
}); | ||
|
||
stream.pipe(concat(function (body) { | ||
var body = body.toString('utf8') | ||
tt.equal( | ||
body, | ||
'TAP version 13\n' | ||
+ '# multiline stack trace\n' | ||
+ 'not ok 1 Error: Preserve stack\n' | ||
+ ' ---\n' | ||
+ ' operator: error\n' | ||
+ ' expected: |-\n' | ||
+ ' undefined\n' | ||
+ ' actual: |-\n' | ||
+ ' [Error: Preserve stack]\n' | ||
+ ' stack: |-\n' | ||
+ ' foo\n' | ||
+ ' bar\n' | ||
+ ' ...\n' | ||
+ '\n' | ||
+ '1..1\n' | ||
+ '# tests 1\n' | ||
+ '# pass 0\n' | ||
+ '# fail 1\n' | ||
); | ||
|
||
tt.deepEqual(getDiag(body), { | ||
stack: stackTrace, | ||
operator: 'error', | ||
expected: 'undefined', | ||
actual: '[Error: Preserve stack]' | ||
}); | ||
})); | ||
|
||
test('multiline stack trace', function (t) { | ||
t.plan(1); | ||
var err = new Error('Preserve stack'); | ||
err.stack = stackTrace; | ||
t.error(err); | ||
}); | ||
}); | ||
|
||
function getDiag (body) { | ||
var yamlStart = body.indexOf(' ---'); | ||
var yamlEnd = body.indexOf(' ...\n'); | ||
var diag = body.slice(yamlStart, yamlEnd).split('\n').map(function (line) { | ||
return line.slice(2); | ||
}).join('\n'); | ||
|
||
return yaml.safeLoad(diag); | ||
} |
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