Skip to content

Commit

Permalink
feat: support Node.js 20
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchini committed Aug 11, 2023
1 parent cbd16ef commit 9f1d249
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jobs:
- 14.x
- 16.x
- 18.x
- 20.x
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
Expand Down
35 changes: 30 additions & 5 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,9 @@ test('fire event on error', function(t) {
});
});

test('error handler defers "after" event', function(t) {
test('error handler defers "after" event', async function(t) {
let afterResolve;
let clientResolve;
t.expect(9);
SERVER.once('NotFound', function(req, res, err, cb) {
t.ok(req);
Expand All @@ -1107,7 +1109,7 @@ test('error handler defers "after" event', function(t) {
SERVER.once('after', function(req2, res2) {
t.ok(req2);
t.ok(res2);
t.end();
afterResolve();
});
return cb();
});
Expand All @@ -1118,8 +1120,18 @@ test('error handler defers "after" event', function(t) {
CLIENT.get('/' + uuid.v4(), function(err, _, res) {
t.ok(err);
t.equal(res.statusCode, 404);
t.end();
clientResolve();
});

await Promise.all([
new Promise(resolve => {
afterResolve = resolve;
}),
new Promise(resolve => {
clientResolve = resolve;
})
]);
t.end();
});

// eslint-disable-next-line
Expand Down Expand Up @@ -1916,7 +1928,9 @@ test("should emit 'close' on server close", function(t) {
});
});

test('should cleanup inflight requests count for 404s', function(t) {
test('should cleanup inflight requests count for 404s', async function(t) {
let afterResolve;
let clientResolve;
SERVER.get('/foo1', function(req, res, next) {
t.equal(SERVER.inflightRequests(), 1);
res.send();
Expand All @@ -1926,7 +1940,7 @@ test('should cleanup inflight requests count for 404s', function(t) {
SERVER.on('after', function(req) {
if (req.path() === '/doesnotexist') {
t.equal(SERVER.inflightRequests(), 0);
t.end();
afterResolve();
}
});

Expand All @@ -1939,8 +1953,19 @@ test('should cleanup inflight requests count for 404s', function(t) {
t.ok(err2);
t.equal(res2.statusCode, 404);
t.equal(SERVER.inflightRequests(), 0);
clientResolve();
});
});

await Promise.all([
new Promise(resolve => {
afterResolve = resolve;
}),
new Promise(resolve => {
clientResolve = resolve;
})
]);
t.end();
});

test('should cleanup inflight requests count for timeouts', function(t) {
Expand Down

0 comments on commit 9f1d249

Please sign in to comment.