Skip to content

Commit a97a18b

Browse files
committed
chore: swap test runner
1 parent 2e5c7f8 commit a97a18b

File tree

3 files changed

+98
-113
lines changed

3 files changed

+98
-113
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
node_modules
21
.DS_Store
2+
node_modules
3+
*-lock.*
34
*.lock
45
*.log

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
"author": {
1010
"name": "Luke Edwards",
1111
"email": "luke.edwards05@gmail.com",
12-
"url": "lukeed.com"
12+
"url": "https://lukeed.com"
1313
},
1414
"engines": {
1515
"node": ">=6"
1616
},
1717
"scripts": {
18-
"test": "tape test/*.js | tap-spec"
18+
"test": "uvu test"
1919
},
2020
"files": [
2121
"*.d.ts",
@@ -28,7 +28,6 @@
2828
"mru"
2929
],
3030
"devDependencies": {
31-
"tap-spec": "^4.1.1",
32-
"tape": "^4.8.0"
31+
"uvu": "0.3.3"
3332
}
3433
}

test/index.js

Lines changed: 93 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,107 @@
1-
const test = require('tape');
1+
const { test } = require('uvu');
2+
const assert = require('uvu/assert');
23
const Cache = require('../lib');
34

45
const sleep = ms => new Promise(r => setTimeout(r, ms));
56

6-
test('tmp-cache', t => {
7-
t.is(typeof Cache, 'function', 'exports a function');
8-
t.throws(Cache, /TypeError/, '~> requires "new" invoke');
7+
test('tmp-cache', () => {
8+
assert.type(Cache, 'function', 'exports a function');
9+
assert.throws(Cache, `Cache cannot be invoked without 'new'`, '~> requires "new" invoke');
910

1011
let foo = new Cache();
11-
t.true(foo instanceof Cache, '~> instance of "Cache" class');
12-
t.true(foo instanceof Map, '~> instance of "Map" class');
13-
14-
t.end();
12+
assert.ok(foo instanceof Cache, '~> instance of "Cache" class');
13+
assert.ok(foo instanceof Map, '~> instance of "Map" class');
1514
});
1615

17-
test('new Cache()', t => {
16+
test('new Cache()', () => {
1817
let foo = new Cache();
19-
t.is(foo.max, Infinity, '~> "max" option is `Infinity` (default)');
20-
t.is(foo.stale, false, '~> "stale" option is `false` (default)');
21-
t.is(foo.maxAge, -1, '~> "maxAge" option is `-1` (default)');
22-
t.end();
18+
assert.is(foo.max, Infinity, '~> "max" option is `Infinity` (default)');
19+
assert.is(foo.stale, false, '~> "stale" option is `false` (default)');
20+
assert.is(foo.maxAge, -1, '~> "maxAge" option is `-1` (default)');
2321
});
2422

25-
test('new Cache(max)', t => {
23+
test('new Cache(max)', () => {
2624
let foo = new Cache(5);
27-
t.is(foo.stale, false, '~> "stale" option is `false` (default)');
28-
t.is(foo.maxAge, -1, '~> "maxAge" option is `-1` (default)');
29-
t.is(foo.max, 5, '~> "max" option is `5`');
30-
t.end();
25+
assert.is(foo.stale, false, '~> "stale" option is `false` (default)');
26+
assert.is(foo.maxAge, -1, '~> "maxAge" option is `-1` (default)');
27+
assert.is(foo.max, 5, '~> "max" option is `5`');
3128
});
3229

33-
test('new Cache({ max, maxAge, stale })', t => {
30+
test('new Cache({ max, maxAge, stale })', () => {
3431
let foo = new Cache({ max:100, stale:true, maxAge:1e3 });
35-
t.is(foo.maxAge, 1000, '~> "maxAge" option is set to `1000`');
36-
t.is(foo.stale, true, '~> "stale" option is set to `true`');
37-
t.is(foo.max, 100, '~> "max" option is set to `100`');
38-
t.end();
32+
assert.is(foo.maxAge, 1000, '~> "maxAge" option is set to `1000`');
33+
assert.is(foo.stale, true, '~> "stale" option is set to `true`');
34+
assert.is(foo.max, 100, '~> "max" option is set to `100`');
3935
});
4036

41-
test('Cache.set', t => {
37+
test('Cache.set', () => {
4238
let key=123, val=456;
4339
let foo = new Cache();
4440

4541
foo.set(key, val);
46-
t.true(foo.has(key), '~> persists key');
47-
t.is(foo.get(key), val, '~> key value is returned');
48-
t.true(foo.has(key), '~~> key is not purged');
42+
assert.ok(foo.has(key), '~> persists key');
43+
assert.is(foo.get(key), val, '~> key value is returned');
44+
assert.ok(foo.has(key), '~~> key is not purged');
4945

5046
foo.set(key, val, 1e3);
51-
t.true(foo.has(key), '~> persists key');
47+
assert.ok(foo.has(key), '~> persists key');
5248

53-
t.is(foo.get(key), val, '~> key is valid w/ content (maxAge)');
49+
assert.is(foo.get(key), val, '~> key is valid w/ content (maxAge)');
5450

5551
let obj = foo.values().next().value;
56-
t.is(typeof obj, 'object', 'entry always written as object');
57-
t.true(obj.expires !== void 0, '~> entry has "expires" key');
58-
t.is(obj.expires, false, '~~> is `false` when not configured');
59-
t.ok(obj.content, '~> entry has "content" key');
60-
t.is(obj.content, val, '~~> is the `value` provided');
52+
assert.type(obj, 'object', 'entry always written as object');
53+
assert.ok(obj.expires !== void 0, '~> entry has "expires" key');
54+
assert.is(obj.expires, false, '~~> is `false` when not configured');
55+
assert.ok(obj.content, '~> entry has "content" key');
56+
assert.is(obj.content, val, '~~> is the `value` provided');
6157

6258
let bar = new Cache({ maxAge:1 });
6359
bar.set(key, val);
6460
let { expires } = bar.values().next().value;
65-
t.true(expires !== void 0, '~> entry has "expires" key');
66-
t.is(typeof expires, 'number', '~~> is a number when set');
67-
68-
t.end();
61+
assert.ok(expires !== void 0, '~> entry has "expires" key');
62+
assert.type(expires, 'number', '~~> is a number when set');
6963
});
7064

71-
test('Cache.set (max)', t => {
65+
test('Cache.set (max)', () => {
7266
let arr, foo=new Cache(5);
7367

7468
Array.from({ length:4 }, (_, x) => foo.set(x));
75-
t.is(foo.size, 4, '~> initially 4 items');
69+
assert.is(foo.size, 4, '~> initially 4 items');
7670

7771
foo.set(10);
78-
t.is(foo.size, 5, '~> 5 items');
72+
assert.is(foo.size, 5, '~> 5 items');
7973

8074
arr = Array.from(foo.keys());
81-
t.same(arr, [0,1,2,3,10], '~> initial key list (ordered)');
75+
assert.equal(arr, [0,1,2,3,10], '~> initial key list (ordered)');
8276

8377
foo.set('cow');
84-
t.is(foo.size, 5, '~> still 5 items');
78+
assert.is(foo.size, 5, '~> still 5 items');
8579

8680
arr = Array.from(foo.keys());
87-
t.same(arr, [1,2,3,10,'cow'], '~> purged oldest key to set newest key');
88-
89-
t.end();
81+
assert.equal(arr, [1,2,3,10,'cow'], '~> purged oldest key to set newest key');
9082
});
9183

92-
test('Cache.get', async t => {
93-
t.plan(8);
84+
test('Cache.get', async () => {
9485
let key = 'hi';
9586
let foo = new Cache({ maxAge:10 });
9687
let bar = new Cache({ stale:true, maxAge:10 });
9788

9889
foo.set(key, 1);
99-
t.is(foo.get(key), 1, '~> matches value');
100-
t.is(foo.get(key), 1, '~> matches value (repeat)');
90+
assert.is(foo.get(key), 1, '~> matches value');
91+
assert.is(foo.get(key), 1, '~> matches value (repeat)');
10192
await sleep(25);
102-
t.is(foo.get(key), undefined, '~> item expired');
103-
t.false(foo.has(key), '~> item removed');
93+
assert.is(foo.get(key), undefined, '~> item expired');
94+
assert.not.ok(foo.has(key), '~> item removed');
10495

10596
bar.set(key, 1);
106-
t.is(bar.get(key), 1, '~> matches value');
107-
t.is(bar.get(key), 1, '~> matches value (repeat)');
97+
assert.is(bar.get(key), 1, '~> matches value');
98+
assert.is(bar.get(key), 1, '~> matches value (repeat)');
10899
await sleep(25);
109-
t.is(bar.get(key), 1, '~> matches value (stale)');
110-
t.false(bar.has(key), '~> item removed');
100+
assert.is(bar.get(key), 1, '~> matches value (stale)');
101+
assert.not.ok(bar.has(key), '~> item removed');
111102
});
112103

113-
test('Cache.get :: expires', async t => {
114-
t.plan(4);
104+
test('Cache.get :: expires', async () => {
115105
let key=123, val=456;
116106
let foo = new Cache({ maxAge:25 });
117107
let toObj = () => sleep(3).then(() => foo.values().next().value);
@@ -120,47 +110,45 @@ test('Cache.get :: expires', async t => {
120110
let old = await toObj();
121111

122112
await sleep(15);
123-
t.is(foo.get(key), val, '~> matches value');
113+
assert.is(foo.get(key), val, '~> matches value');
124114

125115
let x = await toObj();
126-
t.not(x.expires, old.expires, '~> updates the "expires" value');
116+
assert.is.not(x.expires, old.expires, '~> updates the "expires" value');
127117

128118
await sleep(15);
129-
t.is(foo.get(key), val, '~~> matches value');
119+
assert.is(foo.get(key), val, '~~> matches value');
130120

131121
let y = await toObj();
132-
t.not(y.expires, x.expires, '~~> updates the "expires" value');
122+
assert.is.not(y.expires, x.expires, '~~> updates the "expires" value');
133123
});
134124

135-
test('Cache.peek', t => {
125+
test('Cache.peek', () => {
136126
let key=123, val=456;
137127
let foo = new Cache();
138128
let bar = new Cache({ maxAge:0 });
139129

140130
foo.set(key, val);
141-
t.is(foo.peek(key), val, '~> receives value');
142-
t.true(foo.has(key), '~> retains key');
131+
assert.is(foo.peek(key), val, '~> receives value');
132+
assert.ok(foo.has(key), '~> retains key');
143133

144134
bar.set(key, val);
145-
t.is(bar.peek(key), undefined, '~> receives undefined (stale:false)');
146-
t.false(bar.has(key), '~> triggers key deletion');
135+
assert.is(bar.peek(key), undefined, '~> receives undefined (stale:false)');
136+
assert.not.ok(bar.has(key), '~> triggers key deletion');
147137

148-
t.end();
149138
});
150139

151-
test('Cache.peek :: stale', t => {
140+
test('Cache.peek :: stale', () => {
152141
let key=123, val=456;
153142
let foo = new Cache({ maxAge:0, stale:true });
154143

155144
foo.set(key, val);
156145
let abc = foo.peek(key);
157-
t.is(abc, val, '~> receives value (stale)');
158-
t.false(foo.has(key), '~> triggers purge');
146+
assert.is(abc, val, '~> receives value (stale)');
147+
assert.not.ok(foo.has(key), '~> triggers purge');
159148

160-
t.end();
161149
});
162150

163-
test('Cache.peek :: maxAge', t => {
151+
test('Cache.peek :: maxAge', () => {
164152
let key=123, val=456;
165153
let foo = new Cache({ maxAge:1e3 });
166154
let toObj = () => foo.values().next().value;
@@ -169,61 +157,58 @@ test('Cache.peek :: maxAge', t => {
169157
let old = toObj();
170158

171159
let abc = foo.peek(key);
172-
t.is(abc, val, '~> receives the value');
173-
t.true(foo.has(key), '~> key remains if not stale');
160+
assert.is(abc, val, '~> receives the value');
161+
assert.ok(foo.has(key), '~> key remains if not stale');
174162

175163
let x = toObj();
176-
t.is(x.expires, old.expires, '~> expiration is unchanged');
164+
assert.is(x.expires, old.expires, '~> expiration is unchanged');
177165

178166
foo.peek(key);
179167
let y = toObj();
180-
t.is(y.expires, old.expires, '~> expiration is unchanged');
168+
assert.is(y.expires, old.expires, '~> expiration is unchanged');
181169

182-
t.end();
183170
});
184171

185-
test('Cache.size', t => {
172+
test('Cache.size', () => {
186173
let foo = new Cache();
187174

188175
foo.set(1, 1, 0); // expire instantly
189-
t.is(foo.size, 1, '~> 1');
176+
assert.is(foo.size, 1, '~> 1');
190177

191178
foo.set(2, 2);
192-
t.is(foo.size, 2, '~> 2');
179+
assert.is(foo.size, 2, '~> 2');
193180

194181
foo.get(1); // expired & deleted
195-
t.is(foo.size, 1, '~> 1');
182+
assert.is(foo.size, 1, '~> 1');
196183

197-
t.end();
198184
});
199185

200-
test('least recently set', t => {
201-
let foo = new Cache(2);
202-
foo.set('a', 'A');
203-
foo.set('b', 'B');
204-
foo.set('c', 'C');
205-
t.is(foo.get('c'), 'C');
206-
t.is(foo.get('b'), 'B');
207-
t.is(foo.get('a'), undefined);
208-
t.end();
186+
test('least recently set', () => {
187+
let foo = new Cache(2);
188+
foo.set('a', 'A');
189+
foo.set('b', 'B');
190+
foo.set('c', 'C');
191+
assert.is(foo.get('c'), 'C');
192+
assert.is(foo.get('b'), 'B');
193+
assert.is(foo.get('a'), undefined);
209194
});
210195

211-
test('lru recently gotten', t => {
212-
let foo = new Cache(2);
213-
foo.set('a', 'A');
214-
foo.set('b', 'B');
215-
foo.get('a');
216-
foo.set('c', 'C');
217-
t.equal(foo.get('c'), 'C');
218-
t.equal(foo.get('b'), undefined);
219-
t.equal(foo.get('a'), 'A');
220-
t.end();
196+
test('lru recently gotten', () => {
197+
let foo = new Cache(2);
198+
foo.set('a', 'A');
199+
foo.set('b', 'B');
200+
foo.get('a');
201+
foo.set('c', 'C');
202+
assert.is(foo.get('c'), 'C');
203+
assert.is(foo.get('b'), undefined);
204+
assert.is(foo.get('a'), 'A');
221205
});
222206

223-
test('Cache.delete', t => {
224-
let foo = new Cache(2)
225-
foo.set('a', 'A');
226-
foo.delete('a');
227-
t.equal(foo.get('a'), undefined);
228-
t.end();
207+
test('Cache.delete', () => {
208+
let foo = new Cache(2)
209+
foo.set('a', 'A');
210+
foo.delete('a');
211+
assert.is(foo.get('a'), undefined);
229212
});
213+
214+
test.run();

0 commit comments

Comments
 (0)