Skip to content

Commit

Permalink
fix node streams
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Nov 26, 2024
1 parent 30de3c5 commit d7e456e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions bindings_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib"]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
hex.workspace = true
napi = { version = "2.12.2", default-features = false, features = [
"napi4",
"napi6",
"async",
] }
Expand Down
5 changes: 4 additions & 1 deletion bindings_node/test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
createRegisteredClient,
createUser,
encodeTextMessage,
sleep,
} from '@test/helpers'
import {
ConsentEntityType,
Expand Down Expand Up @@ -257,7 +258,7 @@ describe('Client', () => {
})

describe('Streams', () => {
it.only('should stream all messages', async () => {
it('should stream all messages', async () => {
const user = createUser()
const client1 = await createRegisteredClient(user)

Expand All @@ -272,6 +273,7 @@ describe('Streams', () => {
const group2 = client2.conversations().findGroupById(group.id())

let messages = new Array()
client2.conversations().syncAllConversations()
let stream = client2.conversations().streamAllMessages((msg) => {
console.log('Message', msg)
messages.push(msg)
Expand All @@ -281,6 +283,7 @@ describe('Streams', () => {
group.send(encodeTextMessage('Test2'))
group.send(encodeTextMessage('Test3'))
group.send(encodeTextMessage('Test4'))
await sleep(1000)
await stream.endAndWait()
expect(messages.length).toBe(4)
})
Expand Down
6 changes: 6 additions & 0 deletions bindings_node/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ export const encodeTextMessage = (text: string) => {
content: new TextEncoder().encode(text),
}
}

export function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms)
})
}

0 comments on commit d7e456e

Please sign in to comment.