|
| 1 | +var tape = require('../'); |
| 2 | +var tap = require('tap'); |
| 3 | +var concat = require('concat-stream'); |
| 4 | +var tapParser = require('tap-parser'); |
| 5 | +var common = require('./common'); |
| 6 | + |
| 7 | +var getDiag = common.getDiag; |
| 8 | +var stripFullStack = common.stripFullStack; |
| 9 | + |
| 10 | +tap.test('deep equal failure', function (assert) { |
| 11 | + var test = tape.createHarness({ exit : false }); |
| 12 | + var stream = test.createStream(); |
| 13 | + var parser = tapParser(); |
| 14 | + assert.plan(3); |
| 15 | + |
| 16 | + stream.pipe(parser); |
| 17 | + stream.pipe(concat(function (body) { |
| 18 | + assert.equal( |
| 19 | + stripFullStack(body.toString('utf8')), |
| 20 | + 'TAP version 13\n' |
| 21 | + + '# not deep equal\n' |
| 22 | + + 'not ok 1 should not be equivalent\n' |
| 23 | + + ' ---\n' |
| 24 | + + ' operator: notDeepEqual\n' |
| 25 | + + ' expected: |-\n' |
| 26 | + + ' { b: 2 }\n' |
| 27 | + + ' actual: |-\n' |
| 28 | + + ' { b: 2 }\n' |
| 29 | + + ' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' |
| 30 | + + ' stack: |-\n' |
| 31 | + + ' Error: should not be equivalent\n' |
| 32 | + + ' [... stack stripped ...]\n' |
| 33 | + + ' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' |
| 34 | + + ' [... stack stripped ...]\n' |
| 35 | + + ' ...\n' |
| 36 | + + '\n' |
| 37 | + + '1..1\n' |
| 38 | + + '# tests 1\n' |
| 39 | + + '# pass 0\n' |
| 40 | + + '# fail 1\n' |
| 41 | + ); |
| 42 | + |
| 43 | + assert.deepEqual(getDiag(body), { |
| 44 | + operator: 'notDeepEqual', |
| 45 | + expected: '{ b: 2 }', |
| 46 | + actual: '{ b: 2 }' |
| 47 | + }); |
| 48 | + })); |
| 49 | + |
| 50 | + parser.once('assert', function (data) { |
| 51 | + delete data.diag.stack; |
| 52 | + delete data.diag.at; |
| 53 | + assert.deepEqual(data, { |
| 54 | + ok: false, |
| 55 | + id: 1, |
| 56 | + name: 'should not be equivalent', |
| 57 | + diag: { |
| 58 | + operator: 'notDeepEqual', |
| 59 | + expected: '{ b: 2 }', |
| 60 | + actual: '{ b: 2 }' |
| 61 | + } |
| 62 | + }); |
| 63 | + }); |
| 64 | + |
| 65 | + test("not deep equal", function (t) { |
| 66 | + t.plan(1); |
| 67 | + t.notDeepEqual({b: 2}, {b: 2}); |
| 68 | + }); |
| 69 | +}) |
| 70 | + |
| 71 | +tap.test('not deep equal failure, depth 6, with option', function (assert) { |
| 72 | + var test = tape.createHarness({ exit : false }); |
| 73 | + var stream = test.createStream(); |
| 74 | + var parser = tapParser(); |
| 75 | + assert.plan(3); |
| 76 | + |
| 77 | + stream.pipe(parser); |
| 78 | + stream.pipe(concat(function (body) { |
| 79 | + assert.equal( |
| 80 | + stripFullStack(body.toString('utf8')), |
| 81 | + 'TAP version 13\n' |
| 82 | + + '# not deep equal\n' |
| 83 | + + 'not ok 1 should not be equivalent\n' |
| 84 | + + ' ---\n' |
| 85 | + + ' operator: notDeepEqual\n' |
| 86 | + + ' expected: |-\n' |
| 87 | + + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' |
| 88 | + + ' actual: |-\n' |
| 89 | + + ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n' |
| 90 | + + ' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' |
| 91 | + + ' stack: |-\n' |
| 92 | + + ' Error: should not be equivalent\n' |
| 93 | + + ' [... stack stripped ...]\n' |
| 94 | + + ' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' |
| 95 | + + ' [... stack stripped ...]\n' |
| 96 | + + ' ...\n' |
| 97 | + + '\n' |
| 98 | + + '1..1\n' |
| 99 | + + '# tests 1\n' |
| 100 | + + '# pass 0\n' |
| 101 | + + '# fail 1\n' |
| 102 | + ); |
| 103 | + |
| 104 | + assert.deepEqual(getDiag(body), { |
| 105 | + operator: 'notDeepEqual', |
| 106 | + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', |
| 107 | + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' |
| 108 | + }); |
| 109 | + })); |
| 110 | + |
| 111 | + parser.once('assert', function (data) { |
| 112 | + delete data.diag.stack; |
| 113 | + delete data.diag.at; |
| 114 | + assert.deepEqual(data, { |
| 115 | + ok: false, |
| 116 | + id: 1, |
| 117 | + name: 'should not be equivalent', |
| 118 | + diag: { |
| 119 | + operator: 'notDeepEqual', |
| 120 | + expected: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }', |
| 121 | + actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }' |
| 122 | + } |
| 123 | + }); |
| 124 | + }); |
| 125 | + |
| 126 | + test("not deep equal", {objectPrintDepth: 6}, function (t) { |
| 127 | + t.plan(1); |
| 128 | + t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); |
| 129 | + }); |
| 130 | +}) |
| 131 | + |
| 132 | +tap.test('not deep equal failure, depth 6, without option', function (assert) { |
| 133 | + var test = tape.createHarness({ exit : false }); |
| 134 | + var stream = test.createStream(); |
| 135 | + var parser = tapParser(); |
| 136 | + assert.plan(3); |
| 137 | + |
| 138 | + stream.pipe(parser); |
| 139 | + stream.pipe(concat(function (body) { |
| 140 | + assert.equal( |
| 141 | + stripFullStack(body.toString('utf8')), |
| 142 | + 'TAP version 13\n' |
| 143 | + + '# not deep equal\n' |
| 144 | + + 'not ok 1 should not be equivalent\n' |
| 145 | + + ' ---\n' |
| 146 | + + ' operator: notDeepEqual\n' |
| 147 | + + ' expected: |-\n' |
| 148 | + + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' |
| 149 | + + ' actual: |-\n' |
| 150 | + + ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n' |
| 151 | + + ' at: Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' |
| 152 | + + ' stack: |-\n' |
| 153 | + + ' Error: should not be equivalent\n' |
| 154 | + + ' [... stack stripped ...]\n' |
| 155 | + + ' at Test.<anonymous> ($TEST/not-deep-equal-failure.js:$LINE:$COL)\n' |
| 156 | + + ' [... stack stripped ...]\n' |
| 157 | + + ' ...\n' |
| 158 | + + '\n' |
| 159 | + + '1..1\n' |
| 160 | + + '# tests 1\n' |
| 161 | + + '# pass 0\n' |
| 162 | + + '# fail 1\n' |
| 163 | + ); |
| 164 | + |
| 165 | + assert.deepEqual(getDiag(body), { |
| 166 | + operator: 'notDeepEqual', |
| 167 | + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', |
| 168 | + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' |
| 169 | + }); |
| 170 | + })); |
| 171 | + |
| 172 | + parser.once('assert', function (data) { |
| 173 | + delete data.diag.stack; |
| 174 | + delete data.diag.at; |
| 175 | + assert.deepEqual(data, { |
| 176 | + ok: false, |
| 177 | + id: 1, |
| 178 | + name: 'should not be equivalent', |
| 179 | + diag: { |
| 180 | + operator: 'notDeepEqual', |
| 181 | + expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }', |
| 182 | + actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }' |
| 183 | + } |
| 184 | + }); |
| 185 | + }); |
| 186 | + |
| 187 | + test("not deep equal", function (t) { |
| 188 | + t.plan(1); |
| 189 | + t.notDeepEqual({ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }, { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }); |
| 190 | + }); |
| 191 | +}) |
0 commit comments