Skip to content

Commit fdce43a

Browse files
author
Marco Crespi
committed
chore: Add possible dispose test for windows
1 parent 53f4d81 commit fdce43a

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/dipose.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const { HciNoble, DbusNoble } = require('../lib');
2+
3+
const USAGE = `
4+
Usage:
5+
node ./tests/dispose.js <bindings>
6+
Arguments:
7+
bindings: Bindings to use: "hci" or "dbus"
8+
`;
9+
10+
const BINDINGS = process.argv[2];
11+
12+
const printUsage = () => console.log(USAGE);
13+
14+
const main = async () => {
15+
if (!BINDINGS) {
16+
throw new Error(printUsage());
17+
}
18+
19+
console.log('Initializing noble...');
20+
21+
const noble = BINDINGS === 'hci' ? new HciNoble() : BINDINGS === 'dbus' ? new DbusNoble() : null;
22+
if (!noble) {
23+
throw new Error(`Could not find requested bindings ${BINDINGS}`);
24+
}
25+
26+
console.log('Getting adapters...');
27+
28+
const adapters = await noble.getAdapters();
29+
if (adapters.length === 0) {
30+
throw new Error('No adapters found');
31+
}
32+
33+
console.log('Using all adapters...');
34+
35+
for (const adapter of adapters) {
36+
await adapter.startScanning();
37+
await adapter.stopScanning();
38+
}
39+
40+
await noble.dispose();
41+
42+
console.log('Done');
43+
};
44+
45+
main()
46+
.then(() => process.exit(0))
47+
.catch((err) => {
48+
console.error(err);
49+
process.exit(1);
50+
});

0 commit comments

Comments
 (0)