Skip to content

Commit b90c61c

Browse files
committed
chore: swap test runner
1 parent c575213 commit b90c61c

File tree

3 files changed

+105
-110
lines changed

3 files changed

+105
-110
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"node": ">= 8"
2323
},
2424
"scripts": {
25-
"test": "tape test/*.js | tap-spec"
25+
"test": "uvu test -i fixtures"
2626
},
2727
"dependencies": {
2828
"kleur": "^3.0.3",
@@ -31,7 +31,6 @@
3131
"totalist": "^1.0.1"
3232
},
3333
"devDependencies": {
34-
"tap-spec": "5.0.0",
35-
"tape": "4.13.0"
34+
"uvu": "0.3.3"
3635
}
3736
}

test/index.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
const test = require('tape');
1+
const { test } = require('uvu');
2+
const assert = require('uvu/assert');
23
const ley = require('..');
34

4-
test('exports', t => {
5-
t.is(typeof ley, 'object');
6-
t.is(typeof ley.up, 'function');
7-
t.is(typeof ley.down, 'function');
8-
t.end();
5+
test('exports', () => {
6+
assert.type(ley, 'object');
7+
assert.type(ley.up, 'function');
8+
assert.type(ley.down, 'function');
99
});
10+
11+
test.run();

test/util.js

+95-101
Original file line numberDiff line numberDiff line change
@@ -1,240 +1,234 @@
1-
const test = require('tape');
2-
const { join, resolve, isAbsolute } = require('path');
1+
const { test } = require('uvu');
2+
const assert = require('uvu/assert');
3+
const { join, isAbsolute } = require('path');
34
const $ = require('../lib/util');
45

5-
const cwd = join(__dirname, 'pg');
6+
const cwd = join(__dirname, 'fixtures', 'pg');
67
const dir = join(cwd, 'migrations');
78

8-
test('(utils) glob', async t => {
9+
test('(utils) glob', async () => {
910
const out = await $.glob(dir);
10-
t.true(Array.isArray(out), 'returns Promise<Array>');
11-
t.is(out.length, 6, '~> has 6 items');
11+
assert.ok(Array.isArray(out), 'returns Promise<Array>');
12+
assert.is(out.length, 6, '~> has 6 items');
1213

1314
const first = out[0];
14-
t.is(typeof first, 'object', 'items are objects');
15-
t.is(typeof first.name, 'string', '~> has "name" string');
16-
t.is(typeof first.abs, 'string', '~> has "abs" string');
17-
t.true(isAbsolute(first.abs), '~~> is absolute path');
15+
assert.type(first, 'object', 'items are objects');
16+
assert.type(first.name, 'string', '~> has "name" string');
17+
assert.type(first.abs, 'string', '~> has "abs" string');
18+
assert.ok(isAbsolute(first.abs), '~~> is absolute path');
1819

1920
const names = out.map(x => x.name);
2021
const expects = ['001.js', '002.js', '003.js', '004.js', '005.js', '006.js'];
21-
t.same(names, expects, '~> file order is expected');
22-
23-
t.end();
22+
assert.equal(names, expects, '~> file order is expected');
2423
});
2524

2625

27-
test('(utils) glob :: throws', async t => {
28-
t.plan(3);
26+
test('(utils) glob :: throws', async () => {
27+
let caught = false;
2928

3029
try {
3130
await $.glob(join(cwd, 'foobar'));
32-
t.pass('should not run');
31+
assert.unreachable('should not run');
3332
} catch (err) {
34-
t.true(err instanceof Error, 'throws an Error');
35-
t.is(err.code, 'ENOENT', '~> is "ENOENT" code');
36-
t.true(err.stack.includes('no such file or directory'), '~> has detail');
33+
assert.instance(err, Error, 'throws an Error');
34+
assert.is(err.code, 'ENOENT', '~> is "ENOENT" code');
35+
assert.ok(err.stack.includes('no such file or directory'), '~> has detail');
36+
caught = true;
3737
}
38+
39+
assert.ok(caught);
3840
});
3941

4042

41-
test('(utils) diff', t => {
43+
test('(utils) diff', () => {
4244
const exists = ['001', '002', '003'].map(name => ({ name }));
4345
const locals = ['001', '002', '003', '004', '005'].map(name => ({ name }));
4446

4547
const output = $.diff(exists, locals);
46-
t.true(Array.isArray(output), 'returns an Array');
47-
t.true(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');
48-
t.is(output.length, 2, '~> has 2 NEW items');
48+
assert.ok(Array.isArray(output), 'returns an Array');
49+
assert.ok(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');
50+
assert.is(output.length, 2, '~> has 2 NEW items');
4951

5052
const names = output.map(x => x.name);
51-
t.same(names, ['004', '005']);
52-
53-
t.end();
53+
assert.equal(names, ['004', '005']);
5454
});
5555

5656

57-
test('(utils) diff :: identical', t => {
57+
test('(utils) diff :: identical', () => {
5858
const exists = ['001', '002', '003'].map(name => ({ name }));
5959
const locals = ['001', '002', '003'].map(name => ({ name }));
6060

6161
const output = $.diff(exists, locals);
62-
t.true(Array.isArray(output), 'returns an Array');
63-
t.is(output.length, 0, '~> has 0 NEW items');
64-
65-
t.end();
62+
assert.ok(Array.isArray(output), 'returns an Array');
63+
assert.is(output.length, 0, '~> has 0 NEW items');
6664
});
6765

6866

69-
test('(utils) diff :: throws sequence error', t => {
70-
t.plan(3);
67+
test('(utils) diff :: throws sequence error', () => {
68+
let caught = false;
7169

7270
try {
7371
const exists = ['001', '003'].map(name => ({ name }));
7472
const locals = ['001', '002', '003'].map(name => ({ name }));
7573

7674
$.diff(exists, locals);
77-
t.pass('SHOULD NOT REACH');
75+
assert.unreachable('SHOULD NOT REACH');
7876
} catch (err) {
79-
t.true(err instanceof Error, 'throws an Error');
80-
t.is(err.message, `Cannot run "002" after "003" has been applied`);
81-
t.true(err.stack.length > err.message.length, '~> has "stack" details');
77+
caught = true;
78+
assert.instance(err, Error, 'throws an Error');
79+
assert.is(err.message, `Cannot run "002" after "003" has been applied`);
80+
assert.ok(err.stack.length > err.message.length, '~> has "stack" details');
8281
}
82+
83+
assert.ok(caught);
8384
});
8485

8586

8687
// Note: Arrays are received in reverse
87-
test('(utils) pluck', t => {
88+
test('(utils) pluck', () => {
8889
// should return everything, in sync
8990
const foobar = ['003', '002', '001'];
9091

9192
const exists = foobar.map(name => ({ name }));
9293
const locals = foobar.map(name => ({ name }));
9394

9495
const output = $.pluck(exists, locals);
95-
t.true(Array.isArray(output), 'returns an Array');
96-
t.true(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');
97-
t.is(output.length, 3, '~> has 3 candidates');
96+
assert.ok(Array.isArray(output), 'returns an Array');
97+
assert.ok(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');
98+
assert.is(output.length, 3, '~> has 3 candidates');
9899

99100
const names = output.map(x => x.name);
100-
t.same(names, foobar);
101-
102-
t.end();
101+
assert.equal(names, foobar);
103102
});
104103

105104

106105
// Note: Arrays are received in reverse
107-
test('(utils) pluck :: locals >> exists', t => {
106+
test('(utils) pluck :: locals >> exists', () => {
108107
// should NOT return items that don't exist yet
109108
const exists = ['003', '002', '001'].map(name => ({ name }));
110109
const locals = ['005', '004', '003', '002', '001'].map(name => ({ name }));
111110

112111
const output = $.pluck(exists, locals);
113-
t.true(Array.isArray(output), 'returns an Array');
114-
t.true(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');
115-
t.is(output.length, 3, '~> has 3 candidates');
112+
assert.ok(Array.isArray(output), 'returns an Array');
113+
assert.ok(output.every(x => locals.includes(x)), '~> only returns items from `locals` list');
114+
assert.is(output.length, 3, '~> has 3 candidates');
116115

117116
const names = output.map(x => x.name);
118-
t.same(names, ['003', '002', '001']);
119-
120-
t.end();
117+
assert.equal(names, ['003', '002', '001']);
121118
});
122119

123120

124121
// Note: Arrays are received in reverse
125-
test('(utils) pluck :: exists >> locals :: throws', t => {
126-
t.plan(3);
122+
test('(utils) pluck :: exists >> locals :: throws', () => {
123+
let caught = false;
127124

128125
try {
129126
// throws error because we don't have 005 definitions
130127
const exists = ['005', '004', '003', '002', '001'].map(name => ({ name }));
131128
const locals = ['003', '002', '001'].map(name => ({ name }));
132129

133130
$.pluck(exists, locals);
134-
t.pass('SHOULD NOT REACH');
131+
assert.unreachable('SHOULD NOT REACH');
135132
} catch (err) {
136-
t.true(err instanceof Error, 'throws an Error');
137-
t.is(err.message, `Cannot find "005" migration file`);
138-
t.true(err.stack.length > err.message.length, '~> has "stack" details');
133+
caught = true;
134+
assert.instance(err, Error, 'throws an Error');
135+
assert.is(err.message, `Cannot find "005" migration file`);
136+
assert.ok(err.stack.length > err.message.length, '~> has "stack" details');
139137
}
138+
139+
assert.ok(caught);
140140
});
141141

142142

143-
test('(utils) exists :: success', t => {
144-
const output = $.exists('tape');
145-
t.is(typeof output, 'string', 'returns string (success)');
146-
t.is(output, require.resolve('tape'));
147-
t.end();
143+
test('(utils) exists :: success', () => {
144+
const output = $.exists('uvu');
145+
assert.type(output, 'string', 'returns string (success)');
146+
assert.is(output, require.resolve('uvu'))
148147
});
149148

150149

151-
test('(utils) exists :: failure', t => {
150+
test('(utils) exists :: failure', () => {
152151
const output = $.exists('foobar');
153-
t.is(typeof output, 'boolean', 'returns boolean (fail)');
154-
t.is(output, false);
155-
t.end();
152+
assert.type(output, 'boolean', 'returns boolean (fail)');
153+
assert.is(output, false)
156154
});
157155

158156

159-
test('(utils) exists :: failure :: relative', t => {
157+
test('(utils) exists :: failure :: relative', () => {
160158
const output = $.exists('./foobar');
161-
t.is(typeof output, 'boolean', 'returns boolean (fail)');
162-
t.is(output, false);
163-
t.end();
159+
assert.type(output, 'boolean', 'returns boolean (fail)');
160+
assert.is(output, false)
164161
});
165162

166163

167-
test('(utils) detect', t => {
164+
test('(utils) detect', () => {
168165
const ORDER = ['postgres', 'pg', 'mysql', 'mysql2', 'better-sqlite3'];
169166

170167
const seen = [];
171168
const prev = $.exists;
172169

170+
// @ts-ignore
173171
$.exists = x => {
174172
seen.push(x);
175173
}
176174

177175
const foo = $.detect();
178-
t.is(foo, undefined, 'returns undefined (failure)');
179-
t.same(seen, ORDER, '~> looks for drivers (ordered)');
176+
assert.is(foo, undefined, 'returns undefined (failure)');
177+
assert.equal(seen, ORDER, '~> looks for drivers (ordered)');
180178

179+
// @ts-ignore
181180
$.exists = x => x === 'pg';
182181
const bar = $.detect();
183-
t.is(bar, 'pg', '~> found "pg" (mock)');
182+
assert.is(bar, 'pg', '~> found "pg" (mock)');
184183

185184
$.exists = prev;
186-
t.end();
187185
});
188186

189187

190-
test('(utils) local :: success', t => {
188+
test('(utils) local :: success', () => {
191189
const output = $.local('index.js'); // root/index.js
192-
t.is(typeof output, 'object', '~> returns _something_ if exists');
193-
t.true(!!output.down, '~> had "down" export');
194-
t.true(!!output.up, '~> had "up" export');
195-
t.end();
190+
assert.type(output, 'object', '~> returns _something_ if exists');
191+
assert.type(output.down, 'function', '~> had "down" export');
192+
assert.type(output.up, 'function', '~> had "up" export')
196193
});
197194

198195

199-
test('(utils) local :: success w/ cwd', t => {
196+
test('(utils) local :: success w/ cwd', () => {
200197
const output = $.local('util.js', __dirname); // this file
201-
t.is(typeof output, 'object', '~> returns _something_ if exists');
202-
t.end();
198+
assert.type(output, 'object', '~> returns _something_ if exists')
203199
});
204200

205201

206-
test('(utils) local :: failure', t => {
202+
test('(utils) local :: failure', () => {
207203
const output = $.local('foobar.ts'); // root dir
208-
t.is(output, false, '~> returns `false` if not found');
209-
t.end();
204+
assert.is(output, false, '~> returns `false` if not found')
210205
});
211206

212207

213-
test('(utils) local :: failure w/ cwd', t => {
208+
test('(utils) local :: failure w/ cwd', () => {
214209
const output = $.local('index.js', dir); // => pg/migrations/index.js
215-
t.is(output, false, '~> returns `false` if not found');
216-
t.end();
210+
assert.is(output, false, '~> returns `false` if not found')
217211
});
218212

219213

220-
test('(utils) MigrationError', t => {
214+
test('(utils) MigrationError', () => {
221215
const original = new Error('hello world');
222216
const migration = { name: '000.js', abs: 'path/to/000.js' };
223217
Object.assign(original, { code: 42703, position: 8, foobar: undefined });
224218

225219
const error = new $.MigrationError(original, migration);
226-
t.true(error instanceof $.MigrationError, 'is MigrationError');
227-
t.true(error instanceof Error, '~> still inherits Error class');
220+
assert.instance(error, $.MigrationError, 'is MigrationError');
221+
assert.instance(error, Error, '~> still inherits Error class');
228222

229-
t.true(error.stack.length > 0, 'has "stack" trace');
230-
t.true(error.stack.length > original.stack.length, '~> is longer than original trace');
231-
t.true(error.stack.includes(original.stack), '~> contains original trace');
223+
assert.ok(error.stack.length > 0, 'has "stack" trace');
224+
assert.ok(error.stack.length > original.stack.length, '~> is longer than original trace');
225+
assert.ok(error.stack.includes(original.stack), '~> contains original trace');
232226

233-
t.is(error.code, original.code, 'inherits original "code" property (custom)');
234-
t.is(error.foobar, original.foobar, 'inherits original "foobar" property (custom)');
235-
t.is(error.position, original.position, 'inherits original "position" property (custom)');
227+
assert.is(error.code, original.code, 'inherits original "code" property (custom)');
228+
assert.is(error.foobar, original.foobar, 'inherits original "foobar" property (custom)');
229+
assert.is(error.position, original.position, 'inherits original "position" property (custom)');
236230

237-
t.same(error.migration, migration, 'attaches custom "migration" key w/ file data');
238-
239-
t.end();
231+
assert.equal(error.migration, migration, 'attaches custom "migration" key w/ file data');
240232
});
233+
234+
test.run();

0 commit comments

Comments
 (0)