From 7db963d9d6fdc136d72aca92b18f81e7130aab36 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Fri, 20 Sep 2024 14:28:25 -0400 Subject: [PATCH 1/3] test: tap ifError -> error The ifError alias for error in tapjs appears to no longer exist. --- test/accept-encoding.test.js | 4 ++-- test/cache.test.js | 12 ++++++------ test/check-headers.js | 2 +- test/compression.test.js | 12 ++++++------ test/cors.test.js | 8 ++++---- test/custom-content-type-file-secret.test.js | 2 +- test/custom-content-type-file.test.js | 2 +- test/custom-content-type.test.js | 2 +- test/default-default-ext.test.js | 2 +- test/enotdir.test.js | 2 +- test/escaping.test.js | 2 +- test/illegal-access-date.test.js | 2 +- test/malformed-dir.test.js | 2 +- test/malformed.test.js | 2 +- test/range.test.js | 12 ++++++------ test/trailing-slash.test.js | 2 +- 16 files changed, 35 insertions(+), 35 deletions(-) diff --git a/test/accept-encoding.test.js b/test/accept-encoding.test.js index e6fb17f72..d4e2ba3b2 100644 --- a/test/accept-encoding.test.js +++ b/test/accept-encoding.test.js @@ -26,7 +26,7 @@ test('properly handles whitespace in accept-encoding', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], 'gzip'); }); @@ -55,7 +55,7 @@ test('properly handles single accept-encoding entry', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], 'gzip'); }); diff --git a/test/cache.test.js b/test/cache.test.js index 5784cc12f..6021db605 100644 --- a/test/cache.test.js +++ b/test/cache.test.js @@ -22,7 +22,7 @@ test('custom cache option number', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/a.txt`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200, 'a.txt should be found'); t.equal(res.headers['cache-control'], 'max-age=3600'); server.close(() => { t.end(); }); @@ -47,7 +47,7 @@ test('custom cache option string', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/a.txt`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200, 'a.txt should be found'); t.equal(res.headers['cache-control'], 'max-whatever=3600'); server.close(() => { t.end(); }); @@ -76,12 +76,12 @@ test('custom cache option function returning a number', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/a.txt`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200, 'a.txt should be found'); t.equal(res.headers['cache-control'], 'max-age=1'); request.get(`http://localhost:${port}/a.txt`, (err2, res2) => { - t.ifError(err2); + t.error(err2); t.equal(res2.statusCode, 200, 'a.txt should be found'); t.equal(res2.headers['cache-control'], 'max-age=2'); server.close(() => { t.end(); }); @@ -111,12 +111,12 @@ test('custom cache option function returning a string', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/a.txt`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200, 'a.txt should be found'); t.equal(res.headers['cache-control'], 'max-meh=1'); request.get(`http://localhost:${port}/a.txt`, (err2, res2) => { - t.ifError(err2); + t.error(err2); t.equal(res2.statusCode, 200, 'a.txt should be found'); t.equal(res2.headers['cache-control'], 'max-meh=2'); server.close(() => { t.end(); }); diff --git a/test/check-headers.js b/test/check-headers.js index bd8840cdb..a17026976 100644 --- a/test/check-headers.js +++ b/test/check-headers.js @@ -6,7 +6,7 @@ module.exports = (t, server, path, check) => { const uri = `http://localhost:${port}/${path}`; request.get({ uri }, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); check(t, res.headers); }); diff --git a/test/compression.test.js b/test/compression.test.js index 332fcb491..d2475a971 100644 --- a/test/compression.test.js +++ b/test/compression.test.js @@ -26,7 +26,7 @@ test('serves brotli-encoded file when available', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], 'br'); }); @@ -56,7 +56,7 @@ test('serves gzip-encoded file when brotli not available', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], 'gzip'); }); @@ -86,7 +86,7 @@ test('serves gzip-encoded file when brotli not accepted', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], 'gzip'); }); @@ -116,7 +116,7 @@ test('serves gzip-encoded file when brotli not enabled', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], 'gzip'); }); @@ -146,7 +146,7 @@ test('serves unencoded file when compression not accepted', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], undefined); }); @@ -176,7 +176,7 @@ test('serves unencoded file when compression not enabled', (t) => { }; request.get(options, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['content-encoding'], undefined); }); diff --git a/test/cors.test.js b/test/cors.test.js index 09db6cd71..cbfe558fe 100644 --- a/test/cors.test.js +++ b/test/cors.test.js @@ -24,7 +24,7 @@ test('cors defaults to false', (t) => { const uri = `http://localhost:${port}/subdir/index.html`; request.get({ uri }, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.type(res.headers['access-control-allow-origin'], 'undefined'); t.type(res.headers['access-control-allow-headers'], 'undefined'); @@ -52,7 +52,7 @@ test('cors set to false', (t) => { const uri = `http://localhost:${port}/subdir/index.html`; request.get({ uri }, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.type(res.headers['access-control-allow-origin'], 'undefined'); t.type(res.headers['access-control-allow-headers'], 'undefined'); @@ -79,7 +79,7 @@ test('cors set to true', (t) => { const port = httpServer.address().port; const uri = `http://localhost:${port}/subdir/index.html`; request.get({ uri }, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['access-control-allow-origin'], '*'); t.equal(res.headers['access-control-allow-headers'], 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since'); @@ -106,7 +106,7 @@ test('CORS set to true', (t) => { const port = httpServer.address().port; const uri = `http://localhost:${port}/subdir/index.html`; request.get({ uri }, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(res.headers['access-control-allow-origin'], '*'); t.equal(res.headers['access-control-allow-headers'], 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since'); diff --git a/test/custom-content-type-file-secret.test.js b/test/custom-content-type-file-secret.test.js index 655a56c9c..99044b523 100644 --- a/test/custom-content-type-file-secret.test.js +++ b/test/custom-content-type-file-secret.test.js @@ -22,7 +22,7 @@ test('custom contentType via .types file', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/custom_mime_type.opml`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found'); t.equal(res.headers['content-type'], 'application/secret'); server.close(() => { t.end(); }); diff --git a/test/custom-content-type-file.test.js b/test/custom-content-type-file.test.js index c4d5aea45..d76efbc41 100644 --- a/test/custom-content-type-file.test.js +++ b/test/custom-content-type-file.test.js @@ -38,7 +38,7 @@ test('custom contentType via .types file', (t) => { const port = server.address().port; request.get(`http://localhost:${port}/custom_mime_type.opml`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found'); t.equal(res.headers['content-type'], 'application/foo'); server.close(() => { t.end(); }); diff --git a/test/custom-content-type.test.js b/test/custom-content-type.test.js index 9b77226d2..184c3244a 100644 --- a/test/custom-content-type.test.js +++ b/test/custom-content-type.test.js @@ -24,7 +24,7 @@ test('custom contentType', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/custom_mime_type.opml`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200, 'custom_mime_type.opml should be found'); t.equal(res.headers['content-type'], 'application/jon'); server.close(() => { t.end(); }); diff --git a/test/default-default-ext.test.js b/test/default-default-ext.test.js index 68e85761a..55b9c34ff 100644 --- a/test/default-default-ext.test.js +++ b/test/default-default-ext.test.js @@ -13,7 +13,7 @@ test('default defaultExt', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}`, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(eol.lf(body), 'index!!!\n'); server.close(() => { t.end(); }); diff --git a/test/enotdir.test.js b/test/enotdir.test.js index d6778dee0..b7f0a9815 100644 --- a/test/enotdir.test.js +++ b/test/enotdir.test.js @@ -12,7 +12,7 @@ test('should handle ENOTDIR as 404', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/index.html/hello`, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 404); t.equal(body, 'File not found. :('); }); diff --git a/test/escaping.test.js b/test/escaping.test.js index e1ff8ef8e..3f7663ad6 100644 --- a/test/escaping.test.js +++ b/test/escaping.test.js @@ -12,7 +12,7 @@ test('escaping special characters', (t) => { server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/curimit%40gmail.com%20(40%25)`, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); t.equal(eol.lf(body), 'index!!!\n'); server.close(() => { t.end(); }); diff --git a/test/illegal-access-date.test.js b/test/illegal-access-date.test.js index 3721f3c0f..7be8d28e3 100644 --- a/test/illegal-access-date.test.js +++ b/test/illegal-access-date.test.js @@ -18,7 +18,7 @@ test('if-modified-since illegal access date', (t) => { headers: { 'if-modified-since': '275760-09-24' }, }; request.get(opts, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 200); server.close(() => { t.end(); }); }); diff --git a/test/malformed-dir.test.js b/test/malformed-dir.test.js index 4b2615688..889566bee 100644 --- a/test/malformed-dir.test.js +++ b/test/malformed-dir.test.js @@ -12,7 +12,7 @@ test('malformed showdir uri', (t) => { server.listen(0, () => { request.get(`http://localhost:${server.address().port}/?%`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 400); server.close(() => { t.end(); }); }); diff --git a/test/malformed.test.js b/test/malformed.test.js index 11c37c848..195157484 100644 --- a/test/malformed.test.js +++ b/test/malformed.test.js @@ -12,7 +12,7 @@ test('malformed uri', (t) => { server.listen(0, () => { request.get(`http://localhost:${server.address().port}/%`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 400); server.close(() => { t.end(); }); }); diff --git a/test/range.test.js b/test/range.test.js index 45fa42be7..44ed965b7 100644 --- a/test/range.test.js +++ b/test/range.test.js @@ -18,7 +18,7 @@ test('range', (t) => { headers: { range: '3-5' }, }; request.get(opts, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 206, 'partial content status code'); t.equal(body, 'e!!'); t.equal(parseInt(res.headers['content-length'], 10), body.length); @@ -38,7 +38,7 @@ test('range past the end', (t) => { headers: { range: '3-500' }, }; request.get(opts, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 206, 'partial content status code'); t.equal(eol.lf(body), 'e!!\n'); t.equal(parseInt(res.headers['content-length'], 10), body.length); @@ -58,7 +58,7 @@ test('NaN range', (t) => { headers: { range: 'abc-def' }, }; request.get(opts, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 416, 'range error status code'); t.equal(body, 'Requested range not satisfiable'); }); @@ -77,7 +77,7 @@ test('flipped range', (t) => { headers: { range: '333-222' }, }; request.get(opts, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 416, 'range error status code'); t.equal(body, 'Requested range not satisfiable'); }); @@ -97,7 +97,7 @@ test('partial range', (t) => { headers: { range: '3-' }, }; request.get(opts, (err, res, body) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 206, 'partial content status code'); t.equal(eol.lf(body), 'e!!\n'); t.equal(parseInt(res.headers['content-length'], 10), body.length); @@ -122,7 +122,7 @@ test('include last-modified, etag and cache-control headers', (t) => { headers: { range: '3-5' }, }; request.get(opts, (err, res) => { - t.ifError(err); + t.error(err); t.ok(res.headers['cache-control']); t.ok(res.headers['last-modified']); t.ok(res.headers.etag); diff --git a/test/trailing-slash.test.js b/test/trailing-slash.test.js index e1b61c23e..fc2130e36 100644 --- a/test/trailing-slash.test.js +++ b/test/trailing-slash.test.js @@ -18,7 +18,7 @@ test('should not add trailing slash when showDir and autoIndex are off', (t) => server.listen(0, () => { const port = server.address().port; request.get(`http://localhost:${port}/subdir`, (err, res) => { - t.ifError(err); + t.error(err); t.equal(res.statusCode, 404); t.equal(res.body, 'File not found. :('); }); From 2386d801fb7760e54145d3357a1fa4968920370d Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Fri, 20 Sep 2024 15:41:31 -0400 Subject: [PATCH 2/3] test: avoid conflicting http servers in 304 test This one was rather strange. These tests fail even if parallel test running is disabled (tap --jobs=1). Explicitly listening to a different port on each test case solved the issue. I then tried waiting for the next event cycle using a setTimeout(..., 0) on t.end and this actually worked. I suspect then that the server doesn't really "close" until the event loop turns once more - very interesting. --- test/304.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/304.test.js b/test/304.test.js index 5dda54851..8d30d3cda 100644 --- a/test/304.test.js +++ b/test/304.test.js @@ -51,7 +51,7 @@ test('304_not_modified_strong', (t) => { t.equal(res2.statusCode, 304, 'second request should be a 304'); t.equal(res2.headers.etag.indexOf('"'), 0, 'should return a strong etag'); server.close(); - t.end(); + setTimeout(() => { t.end(); }, 0); }); }); }); @@ -97,7 +97,7 @@ test('304_not_modified_weak', (t) => { t.equal(res2.statusCode, 304, 'second request should be a 304'); t.equal(res2.headers.etag.indexOf('W/'), 0, 'should return a weak etag'); server.close(); - t.end(); + setTimeout(() => { t.end(); }, 0); }); }); }); @@ -164,7 +164,7 @@ test('304_not_modified_strong_compare', (t) => { // https://www.ietf.org/rfc/rfc2616.txt t.equal(res3.statusCode, 200, 'third request with a weak etag should be 200'); server.close(); - t.end(); + setTimeout(() => { t.end(); }, 0); }); }); }); @@ -227,7 +227,7 @@ test('304_not_modified_weak_compare', (t) => { t.equal(res3.statusCode, 304, 'third request with a weak etag should be 304'); server.close(); - t.end(); + setTimeout(() => { t.end(); }, 0); }); }); }); From ce22bd9df4673947ee0ee49642788f98e2032c92 Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Fri, 20 Sep 2024 15:52:02 -0400 Subject: [PATCH 3/3] test: update remaining tap asserts After the previous changes there were a few lingering asserts that didn't match the names in the newest version of tap. These were relatively trivial to fix, although interestingly the meaning of the 'includes' synonym changed at some point from "match" to "has"; these tests were written at the time "includes" meant "match". --- test/cli.test.js | 2 +- test/main.test.js | 4 ++-- test/process-env-port.test.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/cli.test.js b/test/cli.test.js index 3520f442f..cecc593ca 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -34,7 +34,7 @@ function checkServerIsRunning(url, msg, t, _cb) { } function tearDown(ps, t) { - t.tearDown(() => { + t.teardown(() => { ps.kill('SIGTERM'); }); } diff --git a/test/main.test.js b/test/main.test.js index df4c65b8f..ebff0563f 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -57,8 +57,8 @@ test('http-server main', (t) => { requestAsync("http://localhost:8080/").then(res => { t.ok(res); t.equal(res.statusCode, 200); - t.includes(res.body, './file'); - t.includes(res.body, './canYouSeeMe'); + t.match(res.body, './file'); + t.match(res.body, './canYouSeeMe'); // Custom headers t.equal(res.headers['access-control-allow-origin'], '*'); diff --git a/test/process-env-port.test.js b/test/process-env-port.test.js index e565a6fe2..ad2da5c22 100644 --- a/test/process-env-port.test.js +++ b/test/process-env-port.test.js @@ -40,7 +40,7 @@ function startServer(url, port, t) { }); } else { ecstatic.on('exit', (evt) => { - t.notEqual(evt.code, 0, 'err:Running on invalid port not allowed'); + t.not(evt.code, 0, 'err:Running on invalid port not allowed'); }); } }