|
| 1 | +/* global test, expect, beforeAll, afterAll */ |
| 2 | +const { getTestDevice } = require('./e2e-test-utils.js') |
| 3 | +const { createBluetooth } = require('..') |
| 4 | + |
| 5 | +const TEST_DEVICE = getTestDevice() |
| 6 | + |
| 7 | +let bluetooth, destroy, adapter, device |
| 8 | + |
| 9 | +beforeAll(async () => { |
| 10 | + ({ bluetooth, destroy } = createBluetooth()) |
| 11 | + adapter = await bluetooth.defaultAdapter() |
| 12 | + if (!await adapter.isDiscovering()) await adapter.startDiscovery() |
| 13 | +}, 20 * 1000) |
| 14 | + |
| 15 | +afterAll(async () => { |
| 16 | + await adapter.stopDiscovery() |
| 17 | + destroy() |
| 18 | +}) |
| 19 | + |
| 20 | +test.each(['#1', '#2', '#3'])('gatt e2e %s', async (attempt) => { |
| 21 | + expect(TEST_DEVICE).not.toBeUndefined() |
| 22 | + device = await adapter.waitDevice(TEST_DEVICE) |
| 23 | + device.on('connect', () => console.log({ attempt, event: 'connect' })) |
| 24 | + device.on('disconnect', () => console.log({ attempt, event: 'disconnect' })) |
| 25 | + await device.connect() |
| 26 | + |
| 27 | + const dbus = bluetooth.dbus |
| 28 | + const name = `/org/bluez/${device.adapter}/${device.device}` |
| 29 | + // console.log(dbus._signals._events) |
| 30 | + const listenerCount = dbus._signals.listenerCount(`{"path":"${name}","interface":"org.freedesktop.DBus.Properties","member":"PropertiesChanged"}`) |
| 31 | + expect(listenerCount).toBe(1) |
| 32 | + await device.disconnect() |
| 33 | +}, 10 * 1000) |
0 commit comments