From bb1edf1177fc5a59bbecda74d838a1917e46fc72 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Mon, 12 Feb 2024 16:35:48 -0500 Subject: [PATCH] fix(tests): make tests exit --- test/Metadata.test.ts | 7 +++++-- test/deprecated.test.ts | 15 +++++++++------ test/index.test.ts | 15 +++++++++++---- test/promises.test.ts | 6 ++++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/test/Metadata.test.ts b/test/Metadata.test.ts index b3db169..55886cc 100755 --- a/test/Metadata.test.ts +++ b/test/Metadata.test.ts @@ -49,8 +49,7 @@ test('should resume from last rev', async (t) => { }, }); - // eslint-disable-next-line no-new - new ListWatch({ + const watch = new ListWatch({ path, name, conn, @@ -60,6 +59,8 @@ test('should resume from last rev', async (t) => { await setTimeout(5); t.is(conn.watch.firstCall?.args?.[0]?.rev, rev); + + await watch.stop(); }); test('should persist rev to _meta', async (t) => { @@ -116,4 +117,6 @@ test('should persist rev to _meta', async (t) => { } as PUTRequest), `conn.put calls: ${inspect(conn.put.getCalls(), false, undefined, true)}`, ); + + await watch.stop(); }); diff --git a/test/deprecated.test.ts b/test/deprecated.test.ts index 4af1f9a..85994ba 100755 --- a/test/deprecated.test.ts +++ b/test/deprecated.test.ts @@ -79,8 +79,7 @@ test('it should detect new item', async (t) => { changes: changes(), }); - // eslint-disable-next-line no-new - new ListWatch(options); + const watch = new ListWatch(options); await setTimeout(delay); @@ -88,6 +87,8 @@ test('it should detect new item', async (t) => { t.is(options.onItem.callCount, 1); t.is(options.onChangeItem.callCount, 0); t.is(options.onRemoveItem.callCount, 0); + + await watch.stop(); }); test('it should detect removed item', async (t) => { @@ -133,8 +134,7 @@ test('it should detect removed item', async (t) => { changes: changes(), }); - // eslint-disable-next-line no-new - new ListWatch(options); + const watch = new ListWatch(options); await setTimeout(delay); @@ -142,6 +142,8 @@ test('it should detect removed item', async (t) => { t.is(options.onItem.callCount, 0); t.is(options.onChangeItem.callCount, 0); t.is(options.onRemoveItem.callCount, 1); + + await watch.stop(); }); test('it should detect modified item', async (t) => { @@ -205,8 +207,7 @@ test('it should detect modified item', async (t) => { changes: changes(), }); - // eslint-disable-next-line no-new - new ListWatch(options); + const watch = new ListWatch(options); await setTimeout(delay); @@ -214,4 +215,6 @@ test('it should detect modified item', async (t) => { t.is(options.onItem.callCount, 1); t.is(options.onChangeItem.callCount, 1); t.is(options.onRemoveItem.callCount, 0); + + await watch.stop(); }); diff --git a/test/index.test.ts b/test/index.test.ts index 67c1eb4..3737742 100755 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -21,8 +21,8 @@ import test from 'ava'; import { createStub, emptyResponse } from './conn-stub.js'; -import { ChangeType, ListWatch } from '@oada/list-lib'; -import type { Change } from '@oada/list-lib'; +// eslint-disable-next-line node/no-extraneous-import +import { type Change, ChangeType, ListWatch } from '@oada/list-lib'; const name = 'oada-list-lib-test'; @@ -32,13 +32,14 @@ test('it should WATCH given path', async (t) => { const conn = createStub(); const path = '/bookmarks/foo/bar'; - // eslint-disable-next-line no-new - new ListWatch({ path, name, conn }); + const watch = new ListWatch({ path, name, conn }); t.plan(1); await setTimeout(delay); t.is(conn.watch.firstCall?.args?.[0]?.path, path); + + await watch.stop(); }); test.todo('it should reconnect WATCH'); @@ -103,6 +104,8 @@ test('it should detect new item', async (t) => { t.is(onItem.callCount, 1); t.is(onChangeItem.callCount, 0); t.is(onRemoveItem.callCount, 0); + + await watch.stop(); }); test('it should detect removed item', async (t) => { @@ -159,6 +162,8 @@ test('it should detect removed item', async (t) => { t.is(onItem.callCount, 0); t.is(onChangeItem.callCount, 0); t.is(onRemoveItem.callCount, 1); + + await watch.stop(); }); test('it should detect modified item', async (t) => { @@ -233,4 +238,6 @@ test('it should detect modified item', async (t) => { t.is(onItem.callCount, 1); t.is(onChangeItem.callCount, 1); t.is(onRemoveItem.callCount, 0); + + await watch.stop(); }); diff --git a/test/promises.test.ts b/test/promises.test.ts index fb74d87..c5207d7 100755 --- a/test/promises.test.ts +++ b/test/promises.test.ts @@ -75,6 +75,8 @@ test('it should detect new item', async (t) => { await t.notThrowsAsync(add); await t.notThrowsAsync(item); + + await watch.stop(); }); test('it should detect removed item', async (t) => { @@ -118,6 +120,8 @@ test('it should detect removed item', async (t) => { const removed = watch.once(ChangeType.ItemRemoved); await t.notThrowsAsync(removed); + + await watch.stop(); }); test('it should detect modified item', async (t) => { @@ -181,4 +185,6 @@ test('it should detect modified item', async (t) => { await t.notThrowsAsync(modified); await t.notThrowsAsync(item); + + await watch.stop(); });