Skip to content

Commit

Permalink
fix: legacy stream support and classless compare (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
seriousme authored May 3, 2022
1 parent a26e117 commit a08890c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function abstractPersistence (opts) {

// legacy third party streams are typically not iterable
function iterableStream (stream) {
if (typeof stream[Symbol.iterator] !== 'function') {
if (typeof stream[Symbol.asyncIterator] !== 'function') {
return new Readable({ objectMode: true }).wrap(stream)
}
return stream
Expand Down Expand Up @@ -127,6 +127,10 @@ function abstractPersistence (opts) {
t.deepLooseEqual(packet, expected, 'must return the packet')
}

function deClassed (obj) {
return Object.assign({}, obj)
}

test('store and look up retained messages', t => {
matchRetainedWithPattern(t, 'hello/world')
})
Expand Down Expand Up @@ -949,8 +953,8 @@ function abstractPersistence (opts) {
streamForEach(stream, clearQueue).then(function done () {
t.equal(queue.length, 2)
if (queue.length === 2) {
t.deepEqual(queue[0], updated1)
t.deepEqual(queue[1], updated2)
t.deepEqual(deClassed(queue[0]), deClassed(updated1))
t.deepEqual(deClassed(queue[1]), deClassed(updated2))
}
instance.destroy(t.end.bind(t))
})
Expand Down Expand Up @@ -1095,7 +1099,8 @@ function abstractPersistence (opts) {
getArrayFromStream(stream).then(list => {
delete list[0].messageId
t.notEqual(list[0], updated, 'must not be the same object')
t.deepEqual(list, [updated], 'must return the packet')
t.deepEqual(deClassed(list[0]), deClassed(updated), 'must return the packet')
t.equal(list.length, 1, 'must return only one packet')
instance.destroy(t.end.bind(t))
})
})
Expand Down Expand Up @@ -1143,7 +1148,8 @@ function abstractPersistence (opts) {
getArrayFromStream(stream).then(list => {
delete list[0].messageId
t.notEqual(list[0], updated2, 'must not be the same object')
t.deepEqual(list, [updated2], 'must return the packet')
t.deepEqual(deClassed(list[0]), deClassed(updated2), 'must return the packet')
t.equal(list.length, 1, 'must return only one packet')
instance.destroy(t.end.bind(t))
})
})
Expand Down

0 comments on commit a08890c

Please sign in to comment.