From fceca66ea4b5307416888ac8e57e2bcd5e1230c9 Mon Sep 17 00:00:00 2001 From: Nathan Friedly Date: Thu, 16 Nov 2023 10:19:30 -0500 Subject: [PATCH] update tests to work with newer tap version --- .gitignore | 1 + package.json | 2 +- test/cookies_spec.js | 4 ++-- test/decompress_spec.js | 18 +++--------------- test/unblocker_spec.js | 16 ++++++++-------- test/websockets_spec.js | 8 ++++---- 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 8a8b87b5..a016b86d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules/ .nyc_output/ .vscode/ examples/*/package-lock.json +.tap/ diff --git a/package.json b/package.json index 4e761a89..9cfc0cd6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "pre-commit": "npm run autofix && npm test", "lint": "eslint .", "autofix": "eslint . --fix", - "test-spec": "tap --no-coverage test/*spec.js", + "test-spec": "tap --allow-incomplete-coverage test/*spec.js", "test-perf": "node test/performance.js" }, "license": "AGPL-3.0", diff --git a/test/cookies_spec.js b/test/cookies_spec.js index ea156cf3..0875973f 100644 --- a/test/cookies_spec.js +++ b/test/cookies_spec.js @@ -108,7 +108,7 @@ test("should rewrite urls that change subdomain or protocol (but not domain)", f }); data.stream = sourceStream; instance.handleResponse(data); - t.notEqual( + t.not( data.stream, sourceStream, "cookies.handleResponse should create a new stream to process content" @@ -158,6 +158,6 @@ test("should work with SameSite attributes", function (t) { instance.handleResponse(data); var actual = data.headers["set-cookie"][0]; console.log(actual); - t.assert(actual.toLowerCase().indexOf("samesite=none") > -1); + t.ok(actual.toLowerCase().indexOf("samesite=none") > -1); t.end(); }); diff --git a/test/decompress_spec.js b/test/decompress_spec.js index 8f642131..14712a79 100644 --- a/test/decompress_spec.js +++ b/test/decompress_spec.js @@ -24,11 +24,7 @@ test("should decompress data compressed with gzip", function (t) { decompress(defaultConfig).handleResponse(data); - t.notEqual( - source, - data.stream, - "it should create a new stream for decompression" - ); + t.not(source, data.stream, "it should create a new stream for decompression"); t.notOk( data.headers["content-encoding"], @@ -63,11 +59,7 @@ test("should decompress data compressed with deflate", function (t) { decompress(defaultConfig).handleResponse(data); - t.notEqual( - source, - data.stream, - "it should create a new stream for decompression" - ); + t.not(source, data.stream, "it should create a new stream for decompression"); t.notOk( data.headers["content-encoding"], @@ -129,11 +121,7 @@ test("should skip requests with no content, even if it can't tell ahead of time" decompress(defaultConfig).handleResponse(data); - t.notEqual( - source, - data.stream, - "it should create a new stream for decompression" - ); + t.not(source, data.stream, "it should create a new stream for decompression"); data.stream.on("end", function () { t.end(); diff --git a/test/unblocker_spec.js b/test/unblocker_spec.js index 42c890ed..10a04dd4 100644 --- a/test/unblocker_spec.js +++ b/test/unblocker_spec.js @@ -15,7 +15,7 @@ test("url_rewriting should support support all kinds of links", function (t) { getServers( { unblocker: new Unblocker({ clientScripts: false }), sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); @@ -43,7 +43,7 @@ test("should return control to parent when route doesn't match and no referer is getServers( { unblocker: new Unblocker({ clientScripts: false }), sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); @@ -72,7 +72,7 @@ test("should redirect root-relative urls when the correct target can be determin getServers( { unblocker: new Unblocker({ clientScripts: false }), sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); @@ -104,7 +104,7 @@ test("should redirect root-relative urls when the correct target can be determin getServers( { unblocker: new Unblocker({ clientScripts: false }), sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); @@ -136,7 +136,7 @@ test("should NOT redirect http urls that have had the slashes merged (http:/ ins getServers( { unblocker: new Unblocker({ clientScripts: false }), sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); @@ -159,7 +159,7 @@ test("should redirect http urls that have had the have two occurrences of /prefi getServers( { unblocker: new Unblocker({ clientScripts: false }), sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); @@ -189,7 +189,7 @@ test("should redirect http urls that end in a TLD without a /", function (t) { getServers( { unblocker: new Unblocker({ clientScripts: false }), sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); @@ -219,7 +219,7 @@ test("should redirect http urls that end in a TLD without a / when req.protocol const unblocker = new Unblocker({}); app.use(unblocker); getServers({ app, unblocker, sourceContent }, function (err, servers) { - t.ifErr(err); + t.error(err); function cleanup() { servers.kill(function () { t.end(); diff --git a/test/websockets_spec.js b/test/websockets_spec.js index 20129d6c..832ba29d 100644 --- a/test/websockets_spec.js +++ b/test/websockets_spec.js @@ -15,7 +15,7 @@ test("it should pass text messages over a websocket connection", function (t) { const wss = new WebSocket.Server({ server: servers.remoteServer }); wss.on("connection", function connection(ws) { ws.on("message", function incoming(message) { - t.equal(message, "message from client"); + t.equal(message.toString(), "message from client"); }); ws.send("message from server"); @@ -30,7 +30,7 @@ test("it should pass text messages over a websocket connection", function (t) { }); ws.on("message", function incoming(message) { - t.equal(message, "message from server"); + t.equal(message.toString(), "message from server"); ws.close(); servers.kill(function () { t.end(); @@ -137,7 +137,7 @@ test("it should forward the path in a websocket requests", function (t) { t.ok(ws, "server connection event"); ws.on("close", function (code, reason) { t.equal(code, 1008); - t.equal(reason, "Policy Violation (sent from client)"); + t.equal(reason.toString(), "Policy Violation (sent from client)"); servers.kill(function () { t.end(); }); @@ -170,7 +170,7 @@ test("it should forward the path in a websocket requests", function (t) { const wsc = new WebSocket(wsurl.href); wsc.on("close", function (code, reason) { t.equal(code, 1008); - t.equal(reason, "Policy Violation (sent from server)"); + t.equal(reason.toString(), "Policy Violation (sent from server)"); servers.kill(function () { t.end(); });