Skip to content

Commit 8994082

Browse files
test(express-wrapper): replace ava with node:test
1 parent aefa927 commit 8994082

File tree

3 files changed

+39
-46
lines changed

3 files changed

+39
-46
lines changed

packages/express-wrapper/package.json

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"clean": "rm -rf -- dist",
1515
"format": "prettier --check .",
1616
"format:fix": "prettier --write .",
17-
"test": "c8 --all ava"
17+
"test": "c8 --all node --loader tsx --test test/*.ts"
1818
},
1919
"dependencies": {
2020
"@api-ts/io-ts-http": "0.0.0-semantically-released",
@@ -25,23 +25,10 @@
2525
"devDependencies": {
2626
"@api-ts/superagent-wrapper": "0.0.0-semantically-released",
2727
"@api-ts/typed-express-router": "0.0.0-semantically-released",
28-
"@ava/typescript": "3.0.1",
2928
"@types/express": "4.17.17",
30-
"ava": "5.2.0",
3129
"c8": "7.13.0",
32-
"ts-node": "10.9.1",
33-
"typescript": "4.7.4"
34-
},
35-
"ava": {
36-
"typescript": {
37-
"compile": false,
38-
"extensions": [
39-
"ts"
40-
],
41-
"rewritePaths": {
42-
"test/": "dist/test/"
43-
}
44-
}
30+
"typescript": "4.7.4",
31+
"tsx": "3.12.7"
4532
},
4633
"publishConfig": {
4734
"access": "public"

packages/express-wrapper/test/middleware.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import test from 'ava';
1+
import test from 'node:test';
2+
import { strict as assert } from 'node:assert';
3+
24
import express from 'express';
35

46
import { middlewareFn, runMiddlewareChain } from '../src/middleware';
@@ -27,65 +29,65 @@ const addAltParamMiddleware = middlewareFn(async () => ({
2729
addedValue: 'hello',
2830
}));
2931

30-
test('should work with normal express middleware', async (t) => {
32+
test('should work with normal express middleware', async () => {
3133
const result = await runMiddlewareChain({ foo: 'test' }, [noopMiddleware], REQ, RES);
32-
t.deepEqual(result, { foo: 'test' });
34+
assert.deepEqual(result, { foo: 'test' });
3335
});
3436

35-
test('should handle errors passed to next()', async (t) => {
36-
await t.throwsAsync(
37+
test('should handle errors passed to next()', async () => {
38+
await assert.rejects(
3739
runMiddlewareChain({ foo: 'test' }, [errorMiddleware], null as any, null as any),
3840
);
3941
});
4042

41-
test('should work with middleware that return values', async (t) => {
43+
test('should work with middleware that return values', async () => {
4244
const result = await runMiddlewareChain(
4345
{ foo: 'test' },
4446
[addParamMiddleware],
4547
REQ,
4648
RES,
4749
);
48-
t.deepEqual(result, { foo: 'test', addedValue: 1337 });
50+
assert.deepEqual(result, { foo: 'test', addedValue: 1337 });
4951
});
5052

51-
test('express and value-producing middleware should work together in any order', async (t) => {
53+
test('express and value-producing middleware should work together in any order', async () => {
5254
const result = await runMiddlewareChain(
5355
{ foo: 'test' },
5456
[noopMiddleware, addParamMiddleware],
5557
REQ,
5658
RES,
5759
);
58-
t.deepEqual(result, { foo: 'test', addedValue: 1337 });
60+
assert.deepEqual(result, { foo: 'test', addedValue: 1337 });
5961

6062
const resultB = await runMiddlewareChain(
6163
{ foo: 'test' },
6264
[addParamMiddleware, noopMiddleware],
6365
REQ,
6466
RES,
6567
);
66-
t.deepEqual(resultB, { foo: 'test', addedValue: 1337 });
68+
assert.deepEqual(resultB, { foo: 'test', addedValue: 1337 });
6769
});
6870

69-
test('middlewares that set the same value should use the last one in the chain', async (t) => {
71+
test('middlewares that set the same value should use the last one in the chain', async () => {
7072
const result = await runMiddlewareChain(
7173
{ foo: 'test' },
7274
[addParamMiddleware, addAltParamMiddleware],
7375
REQ,
7476
RES,
7577
);
76-
t.deepEqual(result, { foo: 'test', addedValue: 'hello' });
78+
assert.deepEqual(result, { foo: 'test', addedValue: 'hello' });
7779

7880
const resultB = await runMiddlewareChain(
7981
{ foo: 'test' },
8082
[addAltParamMiddleware, addParamMiddleware],
8183
REQ,
8284
RES,
8385
);
84-
t.deepEqual(resultB, { foo: 'test', addedValue: 1337 });
86+
assert.deepEqual(resultB, { foo: 'test', addedValue: 1337 });
8587
});
8688

87-
test('error-producing middleware should not run subsequent middleware', async (t) => {
88-
await t.throwsAsync(
89+
test('error-producing middleware should not run subsequent middleware', async () => {
90+
await assert.rejects(
8991
runMiddlewareChain(
9092
{ foo: 'test' },
9193
[errorMiddleware, altErrorMiddleware],

packages/express-wrapper/test/server.test.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import test from 'ava';
1+
import test from 'node:test';
2+
import { strict as assert } from 'node:assert';
23

34
import * as t from 'io-ts';
45
import express from 'express';
@@ -101,7 +102,7 @@ const GetHelloWorld = async (params: { id: string }) =>
101102
payload: params,
102103
} as const);
103104

104-
test('should offer a delightful developer experience', async (t) => {
105+
test('should offer a delightful developer experience', async () => {
105106
const app = createServer(ApiSpec, (app: express.Application) => {
106107
// Configure app-level middleware
107108
app.use(express.json());
@@ -128,10 +129,10 @@ test('should offer a delightful developer experience', async (t) => {
128129
.decodeExpecting(200)
129130
.then((res) => res.body);
130131

131-
t.like(response, { message: "Who's there?" });
132+
assert.equal(response.message, "Who's there?");
132133
});
133134

134-
test('should handle io-ts-http formatted path parameters', async (t) => {
135+
test('should handle io-ts-http formatted path parameters', async () => {
135136
const app = createServer(ApiSpec, (app: express.Application) => {
136137
app.use(express.json());
137138
app.use(appMiddleware);
@@ -151,10 +152,10 @@ test('should handle io-ts-http formatted path parameters', async (t) => {
151152
.decodeExpecting(200)
152153
.then((res) => res.body);
153154

154-
t.like(response, { id: '1337' });
155+
assert.equal(response.id, '1337');
155156
});
156157

157-
test('should invoke app-level middleware', async (t) => {
158+
test('should invoke app-level middleware', async () => {
158159
const app = createServer(ApiSpec, (app: express.Application) => {
159160
// Configure app-level middleware
160161
app.use(express.json());
@@ -175,10 +176,11 @@ test('should invoke app-level middleware', async (t) => {
175176
.decodeExpecting(200)
176177
.then((res) => res.body);
177178

178-
t.like(response, { message: "Who's there?", appMiddlewareRan: true });
179+
assert.equal(response.message, "Who's there?");
180+
assert.equal(response.appMiddlewareRan, true);
179181
});
180182

181-
test('should invoke route-level middleware', async (t) => {
183+
test('should invoke route-level middleware', async () => {
182184
const app = createServer(ApiSpec, (app: express.Application) => {
183185
// Configure app-level middleware
184186
app.use(express.json());
@@ -198,10 +200,11 @@ test('should invoke route-level middleware', async (t) => {
198200
.decodeExpecting(200)
199201
.then((res) => res.body);
200202

201-
t.like(response, { message: "Who's there?", routeMiddlewareRan: true });
203+
assert.equal(response.message, "Who's there?");
204+
assert.equal(response.routeMiddlewareRan, true);
202205
});
203206

204-
test('should not add parameters from middleware unless routeHandler() is used', async (t) => {
207+
test('should not add parameters from middleware unless routeHandler() is used', async () => {
205208
const app = createServer(ApiSpec, (app: express.Application) => {
206209
// Configure app-level middleware
207210
app.use(express.json());
@@ -221,10 +224,11 @@ test('should not add parameters from middleware unless routeHandler() is used',
221224
.decodeExpecting(200)
222225
.then((res) => res.body);
223226

224-
t.like(response, { message: "Who's there?", routeMiddlewareRan: false });
227+
assert.equal(response.message, "Who's there?");
228+
assert.equal(response.routeMiddlewareRan, false);
225229
});
226230

227-
test('should infer status code from response type', async (t) => {
231+
test('should infer status code from response type', async () => {
228232
const app = createServer(ApiSpec, (app: express.Application) => {
229233
// Configure app-level middleware
230234
app.use(express.json());
@@ -244,10 +248,10 @@ test('should infer status code from response type', async (t) => {
244248
.decodeExpecting(400)
245249
.then((res) => res.body);
246250

247-
t.like(response, { errors: 'Please do not tell me zero! I will now explode' });
251+
assert.equal(response.errors, 'Please do not tell me zero! I will now explode');
248252
});
249253

250-
test('should return a 400 when request fails to decode', async (t) => {
254+
test('should return a 400 when request fails to decode', async () => {
251255
const app = createServer(ApiSpec, (app: express.Application) => {
252256
// Configure app-level middleware
253257
app.use(express.json());
@@ -264,5 +268,5 @@ test('should return a 400 when request fails to decode', async (t) => {
264268
.set('Content-Type', 'application/json')
265269
.expect(400);
266270

267-
t.true(response.body.error.startsWith('Invalid value undefined supplied to'));
271+
assert(response.body.error.startsWith('Invalid value undefined supplied to'));
268272
});

0 commit comments

Comments
 (0)