Skip to content

Commit 4a9360d

Browse files
committed
test: fail on unhandled rejections and uncaught exceptions
1 parent 3acc4fc commit 4a9360d

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

packages/tests/tests/waku.node.spec.ts

+40-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
createEncoder,
1313
generateSymmetricKey
1414
} from "@waku/message-encryption/symmetric";
15-
import { createLightNode, createRelayNode } from "@waku/sdk";
15+
import {
16+
createLightNode,
17+
createEncoder as createPlainEncoder,
18+
createRelayNode
19+
} from "@waku/sdk";
1620
import { bytesToUtf8, utf8ToBytes } from "@waku/utils/bytes";
1721
import { expect } from "chai";
1822

@@ -25,6 +29,8 @@ import {
2529

2630
const TestContentTopic = "/test/1/waku/utf8";
2731

32+
const TestEncoder = createPlainEncoder({ contentTopic: TestContentTopic });
33+
2834
describe("Waku Dial [node only]", function () {
2935
describe("Interop: NimGoNode", function () {
3036
let waku: Waku;
@@ -60,6 +66,39 @@ describe("Waku Dial [node only]", function () {
6066
const nimPeerId = await nwaku.getPeerId();
6167
expect(await waku.libp2p.peerStore.has(nimPeerId)).to.be.true;
6268
});
69+
70+
it("Does not throw an exception when node disconnects", async function () {
71+
this.timeout(20_000);
72+
73+
process.on("unhandledRejection", (e) =>
74+
expect.fail("unhandledRejection", e)
75+
);
76+
process.on("uncaughtException", (e) =>
77+
expect.fail("uncaughtException", e)
78+
);
79+
80+
nwaku = new NimGoNode(makeLogFileName(this));
81+
await nwaku.start({
82+
filter: true,
83+
store: true,
84+
lightpush: true
85+
});
86+
const multiAddrWithId = await nwaku.getMultiaddrWithId();
87+
88+
waku = await createLightNode({
89+
staticNoiseKey: NOISE_KEY_1
90+
});
91+
await waku.start();
92+
await waku.dial(multiAddrWithId);
93+
await nwaku.stop();
94+
try {
95+
await waku.lightPush?.send(TestEncoder, {
96+
payload: utf8ToBytes("hello world")
97+
});
98+
} catch (e) {
99+
// We are not checking this exception
100+
}
101+
});
63102
});
64103

65104
describe("Bootstrap", function () {

0 commit comments

Comments
 (0)