UNPKG

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