]> jfr.im git - irc/evilnet/node-irc-nefarious.git/commitdiff
Fix tests not closing properly
authorHalf-Shot <redacted>
Thu, 1 Jun 2023 22:20:53 +0000 (23:20 +0100)
committerHalf-Shot <redacted>
Thu, 1 Jun 2023 22:20:53 +0000 (23:20 +0100)
test/test-433-before-001.spec.ts
test/test-auditorium.spec.ts
test/test-double-crlf.spec.ts
test/test-irc.spec.ts

index 58b281e4b5367d860e4ec2921371eb6a356d3764..831b70d687f1f213daaf725f0276e2db9fc9298d 100644 (file)
@@ -24,12 +24,12 @@ test('connect and sets hostmask when nick in use', async () => {
     });
 
     mock.on('end', function() {
+        mock.close();
         const msgs = mock.getIncomingMsgs();
 
         for (let i = 0; i < msgs.length; i++) {
             expect(msgs[i]).toEqual(fixtures.sent[i][0]);
         }
-        mock.close();
 
         expect.assertions(fixtures.sent.length + fixtures.received.length + fixtures.clientInfo.length);
     });
index 68a25177d0e534f4862580c361a3d407443bdfae..e8ae63a0ef24b7fcbc10682d0e0e9d2058d17fd1 100644 (file)
@@ -6,13 +6,8 @@ test('user gets opped in auditorium', async () => {
     const mock = new MockIrcd();
     const client = new Client('localhost', 'testbot', {debug: true, port: await mock.listen()});
 
-    const modehandler = jest.fn((channel: string, by: string, mode: string, argument?: string) => {
-        if (channel === '#auditorium' && argument === 'user') {
-            client.disconnect();
-        }
-    });
+    const modehandler = jest.fn();
 
-    client.on('+mode', modehandler);
 
     mock.server.on('connection', function() {
         // Initiate connection
@@ -30,6 +25,15 @@ test('user gets opped in auditorium', async () => {
 
     mock.on('end', function() {
         mock.close();
-        expect(modehandler).toBeCalled();
     });
+
+    await new Promise<void>((resolve) => {
+        client.on('+mode', (channel: string, by: string, mode: string, argument?: string) => {
+            if (channel === '#auditorium' && argument === 'user') {
+                resolve();
+            }
+        });
+    });
+
+    client.disconnect();
 });
index 7e6ae710a823e31318a6e4b14e42483a2aa7751b..a0a63cce2471130fc343234314c7eee5c855dc14 100644 (file)
@@ -21,12 +21,12 @@ test('sent messages ending with double CRLF', async () => {
     });
 
     mock.on('end', function() {
+        mock.close();
         const msgs = mock.getIncomingMsgs();
 
         for (let i = 0; i < msgs.length; i++) {
             expect(msgs[i]).toEqual(expected.sent[i][0]);
         }
-        mock.close();
 
         expect.assertions(expected.sent.length + expected.received.length);
     });
index 39138d5246f293179fd6005ff0824c6ecc6b16dc..ccac11e51678a2a3bec0a5d50b484f69413b9d4d 100644 (file)
@@ -48,12 +48,12 @@ describe('IRC client basics', () => {
         });
 
         mock.on('end', function() {
+            mock.close();
             const msgs = mock.getIncomingMsgs();
 
             for (let i = 0; i < msgs.length; i++) {
                 expect(msgs[i]).toEqual(expected.sent[i][0]);
             }
-            mock.close();
 
             expect.assertions(expected.sent.length + expected.received.length);
         });