Skip to content

Commit 45a8508

Browse files
committed
adds e2e test
1 parent 6611591 commit 45a8508

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"scripts": {
2828
"build": "npm run docs:api",
2929
"test": "npm run test:standard && npm run test:coverage && npm run test:typescript",
30-
"test:jest": "jest --testPathIgnorePatterns=e2e.spec.js",
31-
"test:coverage": "jest --testPathIgnorePatterns=e2e.spec.js --coverage",
30+
"test:jest": "jest --testPathIgnorePatterns=test-e2e/",
31+
"test:coverage": "jest --testPathIgnorePatterns=test-e2e/ --coverage",
3232
"test:e2e": "jest",
3333
"test:standard": "standard",
3434
"test:typescript": "tsc --strict src/index.d.ts",

test-e2e/multiple-attemps.spec.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

Comments
 (0)