|
| 1 | +var concat = require('concat-stream'); |
| 2 | +var tap = require('tap'); |
| 3 | +var tape = require('../'); |
| 4 | + |
| 5 | +// Exploratory test to ascertain proper output when no t.comment() call |
| 6 | +// is made. |
| 7 | +tap.test('no comment', function (assert) { |
| 8 | + assert.plan(1); |
| 9 | + |
| 10 | + var verify = function (output) { |
| 11 | + assert.equal(output.toString('utf8'), [ |
| 12 | + 'TAP version 13', |
| 13 | + '# no comment', |
| 14 | + '', |
| 15 | + '1..0', |
| 16 | + '# tests 0', |
| 17 | + '# pass 0', |
| 18 | + '', |
| 19 | + '# ok', |
| 20 | + '' |
| 21 | + ].join('\n')); |
| 22 | + }; |
| 23 | + |
| 24 | + var test = tape.createHarness(); |
| 25 | + test.createStream().pipe(concat(verify)); |
| 26 | + test('no comment', function (t) { |
| 27 | + t.end(); |
| 28 | + }); |
| 29 | +}); |
| 30 | + |
| 31 | +// Exploratory test, can we call t.comment() passing nothing? |
| 32 | +tap.test('missing argument', function (assert) { |
| 33 | + assert.plan(2); |
| 34 | + var test = tape.createHarness(); |
| 35 | + test.createStream(); |
| 36 | + test('missing argument', function (t) { |
| 37 | + try { |
| 38 | + t.comment(); |
| 39 | + t.end(); |
| 40 | + } catch (err) { |
| 41 | + assert.equal(err.constructor, TypeError); |
| 42 | + assert.equal(err.message, 'Cannot call method on undefined'); |
| 43 | + } finally { |
| 44 | + assert.end(); |
| 45 | + } |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +// Exploratory test, can we call t.comment() passing nothing? |
| 50 | +tap.test('null argument', function (assert) { |
| 51 | + assert.plan(2); |
| 52 | + var test = tape.createHarness(); |
| 53 | + test.createStream(); |
| 54 | + test('null argument', function (t) { |
| 55 | + try { |
| 56 | + t.comment(null); |
| 57 | + t.end(); |
| 58 | + } catch (err) { |
| 59 | + assert.equal(err.constructor, TypeError); |
| 60 | + assert.equal(err.message, 'Cannot call method on null'); |
| 61 | + } finally { |
| 62 | + assert.end(); |
| 63 | + } |
| 64 | + }); |
| 65 | +}); |
| 66 | + |
| 67 | + |
| 68 | +// Exploratory test, how is whitespace treated? |
| 69 | +tap.test('whitespace', function (assert) { |
| 70 | + assert.plan(1); |
| 71 | + |
| 72 | + var verify = function (output) { |
| 73 | + assert.equal(output.toString('utf8'), [ |
| 74 | + 'TAP version 13', |
| 75 | + '# whitespace', |
| 76 | + '# ', |
| 77 | + '# a', |
| 78 | + '# a', |
| 79 | + '# a', |
| 80 | + '', |
| 81 | + '1..0', |
| 82 | + '# tests 0', |
| 83 | + '# pass 0', |
| 84 | + '', |
| 85 | + '# ok', |
| 86 | + '' |
| 87 | + ].join('\n')); |
| 88 | + }; |
| 89 | + |
| 90 | + var test = tape.createHarness(); |
| 91 | + test.createStream().pipe(concat(verify)); |
| 92 | + test('whitespace', function (t) { |
| 93 | + t.comment(' '); |
| 94 | + t.comment(' a'); |
| 95 | + t.comment('a '); |
| 96 | + t.comment(' a '); |
| 97 | + t.end(); |
| 98 | + }); |
| 99 | +}); |
| 100 | + |
| 101 | +// Exploratory test, how about passing types other than strings? |
| 102 | +tap.test('non-string types', function (assert) { |
| 103 | + assert.plan(1); |
| 104 | + |
| 105 | + var verify = function (output) { |
| 106 | + assert.equal(output.toString('utf8'), [ |
| 107 | + 'TAP version 13', |
| 108 | + '# non-string types', |
| 109 | + '# true', |
| 110 | + '# false', |
| 111 | + '# 42', |
| 112 | + '# 6.66', |
| 113 | + '# [object Object]', |
| 114 | + '# [object Object]', |
| 115 | + '# [object Object]', |
| 116 | + '# function ConstructorFunction() {}', |
| 117 | + '', |
| 118 | + '1..0', |
| 119 | + '# tests 0', |
| 120 | + '# pass 0', |
| 121 | + '', |
| 122 | + '# ok', |
| 123 | + '' |
| 124 | + ].join('\n')); |
| 125 | + }; |
| 126 | + |
| 127 | + var test = tape.createHarness(); |
| 128 | + test.createStream().pipe(concat(verify)); |
| 129 | + test('non-string types', function (t) { |
| 130 | + t.comment(true); |
| 131 | + t.comment(false); |
| 132 | + t.comment(42); |
| 133 | + t.comment(6.66); |
| 134 | + t.comment({}); |
| 135 | + t.comment({"answer": 42}); |
| 136 | + function ConstructorFunction() {} |
| 137 | + t.comment(new ConstructorFunction()); |
| 138 | + t.comment(ConstructorFunction); |
| 139 | + t.end(); |
| 140 | + }); |
| 141 | +}); |
0 commit comments