fix: hasBinary flakiness (#16641)

This commit is contained in:
Kukhyeon Heo
2021-05-26 23:15:33 +09:00
committed by GitHub
parent 46de81e75f
commit 7dfd845b62
2 changed files with 42 additions and 3 deletions

View File

@@ -115,7 +115,7 @@ index 0ef9f80..4cd787e 100644
catch (e) {
return false;
diff --git a/node_modules/socket.io-parser/dist/is-binary.js b/node_modules/socket.io-parser/dist/is-binary.js
index 4b7c234..95469f7 100644
index 4b7c234..15ed5b1 100644
--- a/node_modules/socket.io-parser/dist/is-binary.js
+++ b/node_modules/socket.io-parser/dist/is-binary.js
@@ -1,6 +1,7 @@
@@ -126,7 +126,7 @@ index 4b7c234..95469f7 100644
const withNativeArrayBuffer = typeof ArrayBuffer === "function";
const isView = (obj) => {
return typeof ArrayBuffer.isView === "function"
@@ -22,13 +23,18 @@ const withNativeFile = typeof File === "function" ||
@@ -22,16 +23,21 @@ const withNativeFile = typeof File === "function" ||
function isBinary(obj) {
return ((withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj))) ||
(withNativeBlob && obj instanceof Blob) ||
@@ -146,7 +146,11 @@ index 4b7c234..95469f7 100644
+ known.push(obj)
if (Array.isArray(obj)) {
for (let i = 0, l = obj.length; i < l; i++) {
if (hasBinary(obj[i])) {
- if (hasBinary(obj[i])) {
+ if (hasBinary(obj[i], known)) {
return true;
}
}
@@ -43,10 +49,10 @@ function hasBinary(obj, toJSON) {
if (obj.toJSON &&
typeof obj.toJSON === "function" &&

View File

@@ -114,6 +114,41 @@ describe('Socket', function () {
}
})
it('correctly encodes and decodes circular data in array', (done) => {
const encoder = new parser.Encoder()
const circularObj = {
foo: {},
}
circularObj.foo.circularArray = [circularObj, circularObj]
const obj = {
type: PacketType.EVENT,
data: ['a', circularObj],
id: 23,
nsp: '/cool',
}
const originalData = obj.data
const encodedPackets = encoder.encode(obj)
const decoder = new parser.Decoder()
decoder.on('decoded', (packet) => {
obj.data = originalData
expect(packet.data[1] === packet.data[1].foo.circularArray[0]).to.be.true
expect(packet.data[1] === packet.data[1].foo.circularArray[1]).to.be.true
expect(packet).to.eql(obj)
done()
})
for (let i = 0; i < encodedPackets.length; i++) {
decoder.add(encodedPackets[i])
}
})
it('correctly encodes and decodes circular data containing binary', (done) => {
const encoder = new parser.Encoder()