Skip to content

Commit

Permalink
fix(tests): make tests exit
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Feb 12, 2024
1 parent 96a39af commit bb1edf1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
7 changes: 5 additions & 2 deletions test/Metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) => {
Expand Down Expand Up @@ -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();
});
15 changes: 9 additions & 6 deletions test/deprecated.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,16 @@ 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);

t.is(options.onAddItem.callCount, 1);
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) => {
Expand Down Expand Up @@ -133,15 +134,16 @@ 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);

t.is(options.onAddItem.callCount, 0);
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) => {
Expand Down Expand Up @@ -205,13 +207,14 @@ 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);

t.is(options.onAddItem.callCount, 0);
t.is(options.onItem.callCount, 1);
t.is(options.onChangeItem.callCount, 1);
t.is(options.onRemoveItem.callCount, 0);

await watch.stop();
});
15 changes: 11 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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');
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();
});
6 changes: 6 additions & 0 deletions test/promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -181,4 +185,6 @@ test('it should detect modified item', async (t) => {

await t.notThrowsAsync(modified);
await t.notThrowsAsync(item);

await watch.stop();
});

0 comments on commit bb1edf1

Please sign in to comment.