Skip to content

Commit bb1edf1

Browse files
committed
fix(tests): make tests exit
1 parent 96a39af commit bb1edf1

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

test/Metadata.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ test('should resume from last rev', async (t) => {
4949
},
5050
});
5151

52-
// eslint-disable-next-line no-new
53-
new ListWatch({
52+
const watch = new ListWatch({
5453
path,
5554
name,
5655
conn,
@@ -60,6 +59,8 @@ test('should resume from last rev', async (t) => {
6059
await setTimeout(5);
6160

6261
t.is(conn.watch.firstCall?.args?.[0]?.rev, rev);
62+
63+
await watch.stop();
6364
});
6465

6566
test('should persist rev to _meta', async (t) => {
@@ -116,4 +117,6 @@ test('should persist rev to _meta', async (t) => {
116117
} as PUTRequest),
117118
`conn.put calls: ${inspect(conn.put.getCalls(), false, undefined, true)}`,
118119
);
120+
121+
await watch.stop();
119122
});

test/deprecated.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,16 @@ test('it should detect new item', async (t) => {
7979
changes: changes(),
8080
});
8181

82-
// eslint-disable-next-line no-new
83-
new ListWatch(options);
82+
const watch = new ListWatch(options);
8483

8584
await setTimeout(delay);
8685

8786
t.is(options.onAddItem.callCount, 1);
8887
t.is(options.onItem.callCount, 1);
8988
t.is(options.onChangeItem.callCount, 0);
9089
t.is(options.onRemoveItem.callCount, 0);
90+
91+
await watch.stop();
9192
});
9293

9394
test('it should detect removed item', async (t) => {
@@ -133,15 +134,16 @@ test('it should detect removed item', async (t) => {
133134
changes: changes(),
134135
});
135136

136-
// eslint-disable-next-line no-new
137-
new ListWatch(options);
137+
const watch = new ListWatch(options);
138138

139139
await setTimeout(delay);
140140

141141
t.is(options.onAddItem.callCount, 0);
142142
t.is(options.onItem.callCount, 0);
143143
t.is(options.onChangeItem.callCount, 0);
144144
t.is(options.onRemoveItem.callCount, 1);
145+
146+
await watch.stop();
145147
});
146148

147149
test('it should detect modified item', async (t) => {
@@ -205,13 +207,14 @@ test('it should detect modified item', async (t) => {
205207
changes: changes(),
206208
});
207209

208-
// eslint-disable-next-line no-new
209-
new ListWatch(options);
210+
const watch = new ListWatch(options);
210211

211212
await setTimeout(delay);
212213

213214
t.is(options.onAddItem.callCount, 0);
214215
t.is(options.onItem.callCount, 1);
215216
t.is(options.onChangeItem.callCount, 1);
216217
t.is(options.onRemoveItem.callCount, 0);
218+
219+
await watch.stop();
217220
});

test/index.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import test from 'ava';
2121

2222
import { createStub, emptyResponse } from './conn-stub.js';
2323

24-
import { ChangeType, ListWatch } from '@oada/list-lib';
25-
import type { Change } from '@oada/list-lib';
24+
// eslint-disable-next-line node/no-extraneous-import
25+
import { type Change, ChangeType, ListWatch } from '@oada/list-lib';
2626

2727
const name = 'oada-list-lib-test';
2828

@@ -32,13 +32,14 @@ test('it should WATCH given path', async (t) => {
3232
const conn = createStub();
3333
const path = '/bookmarks/foo/bar';
3434

35-
// eslint-disable-next-line no-new
36-
new ListWatch({ path, name, conn });
35+
const watch = new ListWatch({ path, name, conn });
3736
t.plan(1);
3837

3938
await setTimeout(delay);
4039

4140
t.is(conn.watch.firstCall?.args?.[0]?.path, path);
41+
42+
await watch.stop();
4243
});
4344

4445
test.todo('it should reconnect WATCH');
@@ -103,6 +104,8 @@ test('it should detect new item', async (t) => {
103104
t.is(onItem.callCount, 1);
104105
t.is(onChangeItem.callCount, 0);
105106
t.is(onRemoveItem.callCount, 0);
107+
108+
await watch.stop();
106109
});
107110

108111
test('it should detect removed item', async (t) => {
@@ -159,6 +162,8 @@ test('it should detect removed item', async (t) => {
159162
t.is(onItem.callCount, 0);
160163
t.is(onChangeItem.callCount, 0);
161164
t.is(onRemoveItem.callCount, 1);
165+
166+
await watch.stop();
162167
});
163168

164169
test('it should detect modified item', async (t) => {
@@ -233,4 +238,6 @@ test('it should detect modified item', async (t) => {
233238
t.is(onItem.callCount, 1);
234239
t.is(onChangeItem.callCount, 1);
235240
t.is(onRemoveItem.callCount, 0);
241+
242+
await watch.stop();
236243
});

test/promises.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ test('it should detect new item', async (t) => {
7575

7676
await t.notThrowsAsync(add);
7777
await t.notThrowsAsync(item);
78+
79+
await watch.stop();
7880
});
7981

8082
test('it should detect removed item', async (t) => {
@@ -118,6 +120,8 @@ test('it should detect removed item', async (t) => {
118120
const removed = watch.once(ChangeType.ItemRemoved);
119121

120122
await t.notThrowsAsync(removed);
123+
124+
await watch.stop();
121125
});
122126

123127
test('it should detect modified item', async (t) => {
@@ -181,4 +185,6 @@ test('it should detect modified item', async (t) => {
181185

182186
await t.notThrowsAsync(modified);
183187
await t.notThrowsAsync(item);
188+
189+
await watch.stop();
184190
});

0 commit comments

Comments
 (0)