Skip to content

Commit e894980

Browse files
Copilotmetcoder95
andcommitted
Migrate from tap tests to node:test
Co-authored-by: metcoder95 <[email protected]>
1 parent 1cb23b5 commit e894980

File tree

4 files changed

+70
-81
lines changed

4 files changed

+70
-81
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ package-lock.json
55
dist
66
coverage
77
build
8+
prebuilds

.taprc

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"build": "npm run prebuildify && tsup",
3434
"build:ci": "npm run prebuildify:ci && tsup",
3535
"lint": "standardx \"**/*.{ts,mjs,js,cjs}\" | snazzy",
36-
"test-only": "tap --ts",
36+
"test-only": "node --import tsx --test test/locks.ts",
3737
"test": "npm run lint && npm run build && npm run test-only",
3838
"test:ci": "npm run lint && npm run build:ci && npm run test-only",
3939
"prepack": "npm run build"
@@ -79,9 +79,8 @@
7979
"prebuildify": "^6.0.1",
8080
"snazzy": "^9.0.0",
8181
"standardx": "^7.0.0",
82-
"tap": "^15.0.6",
83-
"ts-node": "^10.9.2",
8482
"tsup": "^8.2.4",
83+
"tsx": "^4.19.2",
8584
"typescript": "^5.3.3"
8685
},
8786
"dependencies": {

test/locks.ts

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { test } from 'tap';
1+
import { test } from 'node:test';
2+
import assert from 'node:assert';
23
import { version as _version } from '../package.json';
34
import { EventEmitter } from 'events';
45
import { AbortController } from 'abort-controller';
@@ -14,101 +15,101 @@ function sleep (n : number) {
1415
});
1516
}
1617

17-
test('request and query are exposed on export', async ({ equal }) => {
18-
equal(typeof request, 'function');
19-
equal(typeof query, 'function');
20-
equal(version, _version);
18+
test('request and query are exposed on export', async () => {
19+
assert.strictEqual(typeof request, 'function');
20+
assert.strictEqual(typeof query, 'function');
21+
assert.strictEqual(version, _version);
2122
});
2223

23-
test('basically works', async ({ equal }) => {
24+
test('basically works', async () => {
2425
const ret = await request('test1', async (lock) => {
25-
equal(lock.name, 'test1');
26-
equal(lock.mode, 'exclusive');
26+
assert.strictEqual(lock.name, 'test1');
27+
assert.strictEqual(lock.mode, 'exclusive');
2728
return 1;
2829
});
29-
equal(ret, 1);
30+
assert.strictEqual(ret, 1);
3031
});
3132

32-
test('shared locks work', async ({ resolves }) => {
33+
test('shared locks work', async () => {
3334
const p1 = request('hello', { mode: 'shared' }, async () => {
3435
await sleep(10);
3536
});
3637
const p2 = request('hello', { mode: 'shared' }, async () => {
3738
await sleep(10);
3839
});
39-
await resolves(Promise.all([p1, p2]));
40+
await Promise.all([p1, p2]);
4041
});
4142

42-
test('shared locks work reentrantly', async ({ equal }) => {
43+
test('shared locks work reentrantly', async () => {
4344
const ret = await request('shared', { mode: 'shared' }, async () => {
4445
await request('shared', { mode: 'shared' }, async () => {
4546
await sleep(10);
4647
});
4748
return 1;
4849
});
49-
equal(ret, 1);
50+
assert.strictEqual(ret, 1);
5051
});
5152

52-
test('exclusive locks work non-reentrantly', async ({ rejects }) => {
53+
test('exclusive locks work non-reentrantly', async () => {
5354
const ac = new AbortController();
5455
const p = request('exclusive', async () => {
5556
await request('exclusive', { signal: ac.signal as any, mode: 'shared' }, async () => {
5657
await sleep(10);
5758
});
5859
});
5960
setTimeout(() => ac.abort(), 100);
60-
await rejects(p, /aborted/);
61+
await assert.rejects(p, /aborted/);
6162
});
6263

63-
test('validates lock name is string', async ({ rejects }) => {
64-
rejects(() => request((Symbol('') as any), () => {}),
64+
test('validates lock name is string', async () => {
65+
await assert.rejects(() => request((Symbol('') as any), () => {}),
6566
/Cannot convert a Symbol/);
6667
});
6768

68-
test('validates callback is given', async ({ rejects }) => {
69-
rejects(() => request(''), TypeError);
69+
test('validates callback is given', async () => {
70+
await assert.rejects(() => request(''), TypeError);
7071
});
7172

72-
test('validates options is an object', async ({ rejects }) => {
73-
rejects(() => request('', 'hi' as any, () => {}), TypeError);
74-
rejects(() => request('', 1 as any, () => {}), TypeError);
75-
rejects(() => request('', null as any, () => {}), TypeError);
76-
rejects(() => request('', undefined, () => {}), TypeError);
77-
rejects(() => request('', true as any, () => {}), TypeError);
73+
test('validates options is an object', async () => {
74+
await assert.rejects(() => request('', 'hi' as any, () => {}), TypeError);
75+
await assert.rejects(() => request('', 1 as any, () => {}), TypeError);
76+
await assert.rejects(() => request('', null as any, () => {}), TypeError);
77+
await assert.rejects(() => request('', undefined, () => {}), TypeError);
78+
await assert.rejects(() => request('', true as any, () => {}), TypeError);
7879
});
7980

80-
test('validates options types', async ({ rejects }) => {
81-
rejects(() => request('', { mode: 1 as any }, () => {}), RangeError);
82-
rejects(() => request('', { mode: 'foo' as any }, () => {}), RangeError);
83-
rejects(() => request('', { mode: true as any }, () => {}), RangeError);
84-
rejects(() => request('', { ifAvailable: 'yes' as any }, () => {}), TypeError);
85-
rejects(() => request('', { ifAvailable: 1 as any }, () => {}), TypeError);
86-
rejects(() => request('', { ifAvailable: {} as any }, () => {}), TypeError);
87-
rejects(() => request('', { steal: 1 as any }, () => {}), TypeError);
88-
rejects(() => request('', { steal: 'hi' as any }, () => {}), TypeError);
89-
rejects(() => request('', { steal: {} as any }, () => {}), TypeError);
81+
test('validates options types', async () => {
82+
await assert.rejects(() => request('', { mode: 1 as any }, () => {}), RangeError);
83+
await assert.rejects(() => request('', { mode: 'foo' as any }, () => {}), RangeError);
84+
await assert.rejects(() => request('', { mode: true as any }, () => {}), RangeError);
85+
await assert.rejects(() => request('', { ifAvailable: 'yes' as any }, () => {}), TypeError);
86+
await assert.rejects(() => request('', { ifAvailable: 1 as any }, () => {}), TypeError);
87+
await assert.rejects(() => request('', { ifAvailable: {} as any }, () => {}), TypeError);
88+
await assert.rejects(() => request('', { steal: 1 as any }, () => {}), TypeError);
89+
await assert.rejects(() => request('', { steal: 'hi' as any }, () => {}), TypeError);
90+
await assert.rejects(() => request('', { steal: {} as any }, () => {}), TypeError);
9091
});
9192

92-
test('generates a summary', async ({ equal, ok }) => {
93+
test('generates a summary', async () => {
9394
const summary = query();
94-
equal(typeof summary, 'object');
95-
ok(Array.isArray(summary.pending));
96-
ok(Array.isArray(summary.held));
95+
assert.strictEqual(typeof summary, 'object');
96+
assert.ok(Array.isArray(summary.pending));
97+
assert.ok(Array.isArray(summary.held));
9798
});
9899

99-
test('waits for lock to free', async ({ resolves, ok }) => {
100+
test('waits for lock to free', async () => {
100101
let check : boolean = false;
101102
const p1 = request('hello', async () => {
102103
await sleep(10);
103104
check = true;
104105
});
105106
const p2 = request('hello', async () => {
106-
ok(check);
107+
assert.ok(check);
107108
});
108-
await resolves(Promise.all([p1, p2]));
109+
await Promise.all([p1, p2]);
109110
});
110111

111-
test('waits for multiple locks to free', async ({ resolves, ok }) => {
112+
test('waits for multiple locks to free', async () => {
112113
let firstCheck : boolean = false;
113114
let secondCheck : boolean = false;
114115
const p0 = request('hello', async () => {
@@ -120,59 +121,60 @@ test('waits for multiple locks to free', async ({ resolves, ok }) => {
120121
secondCheck = true;
121122
});
122123
const p2 = request('hello', async () => {
123-
ok(firstCheck);
124-
ok(secondCheck);
124+
assert.ok(firstCheck);
125+
assert.ok(secondCheck);
125126
});
126-
await resolves(Promise.all([p0, p1, p2]));
127+
await Promise.all([p0, p1, p2]);
127128
});
128129

129-
test('cancels with AbortError', async ({ resolves, rejects, equal }) => {
130+
test('cancels with AbortError', async () => {
130131
const unusedSignal = new EventEmitter();
131132
const p1 = request('hello', { signal: unusedSignal }, async () => {
132133
await sleep(10);
133134
});
134135
const signal = new EventEmitter();
135136
const p2 = request('hello', { signal }, async () => {});
137+
138+
// We need to set up the rejection handler before emitting abort
139+
const p2Rejection = assert.rejects(p2, /aborted/);
140+
136141
signal.emit('abort');
137142

138-
await Promise.all([
139-
resolves(p1),
140-
rejects(p2, /aborted/)
141-
]);
143+
await p1;
144+
await p2Rejection;
142145

143-
equal(unusedSignal.listenerCount('abort'), 0);
146+
assert.strictEqual(unusedSignal.listenerCount('abort'), 0);
144147
});
145148

146-
test('cancels with AbortError (2)', async ({ resolves, rejects }) => {
149+
test('cancels with AbortError (2)', async () => {
147150
const unusedAc = new AbortController();
148151
const p1 = request('hello', { signal: unusedAc.signal as any }, async () => {
149152
await sleep(10);
150153
});
151154
const ac = new AbortController();
152155
const p2 = request('hello', { signal: ac.signal as any }, async () => {});
156+
157+
// We need to set up the rejection handler before aborting
158+
const p2Rejection = assert.rejects(p2, /aborted/);
159+
153160
ac.abort();
154161

155-
await Promise.all([
156-
resolves(p1),
157-
rejects(p2, /aborted/)
158-
]);
162+
await p1;
163+
await p2Rejection;
159164
});
160165

161-
test('fails when already aborted', async ({ rejects }) => {
166+
test('fails when already aborted', async () => {
162167
const p1 = request('hello', { signal: { aborted: true } as any }, async () => {});
163-
await rejects(p1, /aborted/);
168+
await assert.rejects(p1, /aborted/);
164169
});
165170

166-
test('lock null when not available', async ({ resolves, equal }) => {
171+
test('lock null when not available', async () => {
167172
const p1 = request('hello', async () => {
168173
await sleep(10);
169174
});
170175
const p2 = request('hello', { ifAvailable: true }, async (lock) => {
171-
equal(lock, null);
176+
assert.strictEqual(lock, null);
172177
});
173178

174-
await Promise.all([
175-
resolves(p1),
176-
resolves(p2)
177-
]);
179+
await Promise.all([p1, p2]);
178180
});

0 commit comments

Comments
 (0)