Skip to content

Commit 6218f71

Browse files
committed
HACK: test: add terrible hack to work around node.js assert bug
Waiting for this issue to be fixed: nodejs/node#8001
1 parent d27c3ad commit 6218f71

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test/node/test-buffer-badhex.js

+41
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,47 @@ var Buffer = require('../../').Buffer;
55
var assert = require('assert');
66
var Buffer = require('../../').Buffer;
77

8+
/**
9+
* TEMPORARY HACK UNTIL THIS ASSERT BUG IS FIXED IN NODE CORE
10+
* https://github.com/nodejs/node/issues/8001
11+
*/
12+
var pToString = function (obj) { return Object.prototype.toString.call(obj) }
13+
var _deepStrictEqual = assert.deepStrictEqual
14+
assert.deepStrictEqual = function (actual, expected, msg) {
15+
if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(actual) &&
16+
ArrayBuffer.isView(expected) && !require('buffer').Buffer.isBuffer(actual) &&
17+
!require('buffer').Buffer.isBuffer(expected) && pToString(actual) === pToString(expected) &&
18+
!(actual instanceof Float32Array || actual instanceof Float64Array)) {
19+
assert.equal(Buffer.compare(Buffer.from(actual.buffer,
20+
actual.byteOffset,
21+
actual.byteLength),
22+
Buffer.from(expected.buffer,
23+
expected.byteOffset,
24+
expected.byteLength)), 0);
25+
} else {
26+
_deepStrictEqual.call(assert, actual, expected, msg)
27+
}
28+
}
29+
var _deepEqual = assert.deepEqual
30+
assert.deepEqual = function (actual, expected, msg) {
31+
if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView(actual) &&
32+
ArrayBuffer.isView(expected) && !require('buffer').Buffer.isBuffer(actual) &&
33+
!require('buffer').Buffer.isBuffer(expected) && pToString(actual) === pToString(expected) &&
34+
!(actual instanceof Float32Array || actual instanceof Float64Array)) {
35+
assert.ok(Buffer.compare(Buffer.from(actual.buffer,
36+
actual.byteOffset,
37+
actual.byteLength),
38+
Buffer.from(expected.buffer,
39+
expected.byteOffset,
40+
expected.byteLength)) === 0);
41+
} else {
42+
_deepEqual.call(assert, actual, expected, msg)
43+
}
44+
}
45+
/**
46+
* END HACK
47+
*/
48+
849
// Test hex strings and bad hex strings
950
{
1051
var buf1 = Buffer.alloc(4);

0 commit comments

Comments
 (0)