From ee3f87c875ad41605e2b07983d83c7b123579bfd Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:29:10 +0100 Subject: [PATCH 01/26] feat: node test runner --- package.json | 8 +- test/case-insensitive.test.js | 43 +++-- test/constraint.custom-versioning.test.js | 35 ++-- test/constraint.custom.async.test.js | 19 +- test/constraint.custom.test.js | 119 ++++++------ test/constraint.default-versioning.test.js | 93 +++++----- test/constraint.host.test.js | 27 ++- test/constraints.test.js | 57 +++--- test/custom-querystring-parser.test.js | 15 +- test/errors.test.js | 83 +++++---- test/fastify-issue-3129.test.js | 11 +- test/fastify-issue-3957.test.js | 5 +- test/find-route.test.js | 57 +++--- test/find.test.js | 9 +- test/for-in-loop.test.js | 8 +- test/full-url.test.js | 20 ++- test/has-route.test.js | 35 ++-- test/host-storage.test.js | 24 +-- test/http2/constraint.host.test.js | 9 +- test/issue-101.test.js | 9 +- test/issue-104.test.js | 41 +++-- test/issue-110.test.js | 5 +- test/issue-132.test.js | 21 ++- test/issue-145.test.js | 20 +-- test/issue-149.test.js | 9 +- test/issue-151.test.js | 7 +- test/issue-154.test.js | 3 +- test/issue-161.test.js | 35 ++-- test/issue-17.test.js | 137 +++++++------- test/issue-175.test.js | 15 +- test/issue-182.test.js | 5 +- test/issue-190.test.js | 16 +- test/issue-20.test.js | 13 +- test/issue-206.test.js | 45 +++-- test/issue-221.test.js | 11 +- test/issue-234.test.js | 71 ++++---- test/issue-238.test.js | 51 +++--- test/issue-240.test.js | 32 ++-- test/issue-241.test.js | 11 +- test/issue-247.test.js | 35 ++-- test/issue-254.test.js | 5 +- test/issue-28.test.js | 55 +++--- test/issue-280.test.js | 5 +- test/issue-285.test.js | 15 +- test/issue-330.test.js | 41 +++-- test/issue-44.test.js | 17 +- test/issue-46.test.js | 29 ++- test/issue-49.test.js | 47 +++-- test/issue-59.test.js | 33 ++-- test/issue-62.test.js | 14 +- test/issue-63.test.js | 8 +- test/issue-67.test.js | 17 +- test/issue-93.test.js | 11 +- test/lookup-async.test.js | 11 +- test/lookup.test.js | 11 +- test/matching-order.test.js | 9 +- test/max-param-length.test.js | 13 +- test/methods.test.js | 199 ++++++++++----------- test/null-object.test.js | 10 +- test/on-bad-url.test.js | 11 +- test/optional-params.test.js | 51 +++--- test/params-collisions.test.js | 31 ++-- test/path-params-match.test.js | 52 +++--- test/pretty-print-tree.test.js | 95 +++++----- test/pretty-print.test.js | 107 ++++++----- test/querystring.test.js | 19 +- test/regex.test.js | 39 ++-- test/routes-registered.test.js | 8 +- test/server.test.js | 137 +++++++------- test/shorthands.test.js | 7 +- test/store.test.js | 11 +- 71 files changed, 1165 insertions(+), 1222 deletions(-) diff --git a/package.json b/package.json index e28d4e61..9b1d4e44 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "bench:cmp:ci": "node ./benchmark/compare-branches.js --ci", "test:lint": "standard", "test:typescript": "tsd", - "test": "standard && tap --allow-incomplete-coverage test/*.test.js && npm run test:typescript", - "test:report": "tap -J test/*.test.js --cov --coverage-report=html --coverage-report=cobertura | tee out.tap", - "test:reporter": "tap-mocha-reporter xunit < out.tap > test/junit-testresults.xml" + "test": "standard && node --test test/*.test.js && npm run test:typescript", + "test:report": "node --test test/*.test.js --test-reporter tap --test-reporter-destination out.tap", + "test:reporter": "node --test --test-reporter junit --test-reporter-destination test/junit-testresults.xml" }, "repository": { "type": "git", @@ -44,8 +44,6 @@ "rfdc": "^1.3.0", "simple-git": "^3.7.1", "standard": "^17.0.0", - "tap": "^21.0.1", - "tap-mocha-reporter": "^5.0.1", "tsd": "^0.31.0" }, "dependencies": { diff --git a/test/case-insensitive.test.js b/test/case-insensitive.test.js index 1fd88020..a1e5d6cb 100644 --- a/test/case-insensitive.test.js +++ b/test/case-insensitive.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('case insensitive static routes of level 1', t => { @@ -15,7 +14,7 @@ test('case insensitive static routes of level 1', t => { }) findMyWay.on('GET', '/woo', (req, res, params) => { - t.pass('we should be here') + t.assert.ok('we should be here') }) findMyWay.lookup({ method: 'GET', url: '/WOO', headers: {} }, null) @@ -32,7 +31,7 @@ test('case insensitive static routes of level 2', t => { }) findMyWay.on('GET', '/foo/woo', (req, res, params) => { - t.pass('we should be here') + t.assert.ok('we should be here') }) findMyWay.lookup({ method: 'GET', url: '/FoO/WOO', headers: {} }, null) @@ -49,7 +48,7 @@ test('case insensitive static routes of level 3', t => { }) findMyWay.on('GET', '/foo/bar/woo', (req, res, params) => { - t.pass('we should be here') + t.assert.ok('we should be here') }) findMyWay.lookup({ method: 'GET', url: '/Foo/bAR/WoO', headers: {} }, null) @@ -66,7 +65,7 @@ test('parametric case insensitive', t => { }) findMyWay.on('GET', '/foo/:param', (req, res, params) => { - t.equal(params.param, 'bAR') + t.assert.equal(params.param, 'bAR') }) findMyWay.lookup({ method: 'GET', url: '/Foo/bAR', headers: {} }, null) @@ -83,7 +82,7 @@ test('parametric case insensitive with a static part', t => { }) findMyWay.on('GET', '/foo/my-:param', (req, res, params) => { - t.equal(params.param, 'bAR') + t.assert.equal(params.param, 'bAR') }) findMyWay.lookup({ method: 'GET', url: '/Foo/MY-bAR', headers: {} }, null) @@ -100,7 +99,7 @@ test('parametric case insensitive with capital letter', t => { }) findMyWay.on('GET', '/foo/:Param', (req, res, params) => { - t.equal(params.Param, 'bAR') + t.assert.equal(params.Param, 'bAR') }) findMyWay.lookup({ method: 'GET', url: '/Foo/bAR', headers: {} }, null) @@ -117,7 +116,7 @@ test('case insensitive with capital letter in static path with param', t => { }) findMyWay.on('GET', '/Foo/bar/:param', (req, res, params) => { - t.equal(params.param, 'baZ') + t.assert.equal(params.param, 'baZ') }) findMyWay.lookup({ method: 'GET', url: '/foo/bar/baZ', headers: {} }, null) @@ -138,11 +137,11 @@ test('case insensitive with multiple paths containing capital letter in static p }) findMyWay.on('GET', '/Foo/bar/:param', (req, res, params) => { - t.equal(params.param, 'baZ') + t.assert.equal(params.param, 'baZ') }) findMyWay.on('GET', '/Foo/baz/:param', (req, res, params) => { - t.equal(params.param, 'baR') + t.assert.equal(params.param, 'baR') }) findMyWay.lookup({ method: 'GET', url: '/foo/bar/baZ', headers: {} }, null) @@ -160,8 +159,8 @@ test('case insensitive with multiple mixed-case params within same slash couple' }) findMyWay.on('GET', '/foo/:param1-:param2', (req, res, params) => { - t.equal(params.param1, 'My') - t.equal(params.param2, 'bAR') + t.assert.equal(params.param1, 'My') + t.assert.equal(params.param2, 'bAR') }) findMyWay.lookup({ method: 'GET', url: '/FOO/My-bAR', headers: {} }, null) @@ -178,8 +177,8 @@ test('case insensitive with multiple mixed-case params', t => { }) findMyWay.on('GET', '/foo/:param1/:param2', (req, res, params) => { - t.equal(params.param1, 'My') - t.equal(params.param2, 'bAR') + t.assert.equal(params.param1, 'My') + t.assert.equal(params.param2, 'bAR') }) findMyWay.lookup({ method: 'GET', url: '/FOO/My/bAR', headers: {} }, null) @@ -196,7 +195,7 @@ test('case insensitive with wildcard', t => { }) findMyWay.on('GET', '/foo/*', (req, res, params) => { - t.equal(params['*'], 'baR') + t.assert.equal(params['*'], 'baR') }) findMyWay.lookup({ method: 'GET', url: '/FOO/baR', headers: {} }, null) @@ -213,16 +212,16 @@ test('parametric case insensitive with multiple routes', t => { }) findMyWay.on('POST', '/foo/:param/Static/:userId/Save', (req, res, params) => { - t.equal(params.param, 'bAR') - t.equal(params.userId, 'one') + t.assert.equal(params.param, 'bAR') + t.assert.equal(params.userId, 'one') }) findMyWay.on('POST', '/foo/:param/Static/:userId/Update', (req, res, params) => { - t.equal(params.param, 'Bar') - t.equal(params.userId, 'two') + t.assert.equal(params.param, 'Bar') + t.assert.equal(params.userId, 'two') }) findMyWay.on('POST', '/foo/:param/Static/:userId/CANCEL', (req, res, params) => { - t.equal(params.param, 'bAR') - t.equal(params.userId, 'THREE') + t.assert.equal(params.param, 'bAR') + t.assert.equal(params.userId, 'THREE') }) findMyWay.lookup({ method: 'POST', url: '/foo/bAR/static/one/SAVE', headers: {} }, null) diff --git a/test/constraint.custom-versioning.test.js b/test/constraint.custom-versioning.test.js index e5559c14..e2e2c578 100644 --- a/test/constraint.custom-versioning.test.js +++ b/test/constraint.custom-versioning.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const noop = () => { } @@ -30,11 +29,11 @@ test('A route could support multiple versions (find) / 1', t => { findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=2' } }, noop) findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=3' } }, noop) - t.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=2' })) - t.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=3' })) - t.notOk(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=4' })) - t.notOk(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=5' })) - t.notOk(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=6' })) + t.assert.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=2' })) + t.assert.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=3' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=4' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=5' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=6' })) }) test('A route could support multiple versions (find) / 1 (add strategy outside constructor)', t => { @@ -47,11 +46,11 @@ test('A route could support multiple versions (find) / 1 (add strategy outside c findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=2' } }, noop) findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=3' } }, noop) - t.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=2' })) - t.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=3' })) - t.notOk(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=4' })) - t.notOk(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=5' })) - t.notOk(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=6' })) + t.assert.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=2' })) + t.assert.ok(findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=3' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=4' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=5' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: 'application/vnd.example.api+json;version=6' })) }) test('Overriding default strategies uses the custom deriveConstraint function', t => { @@ -60,11 +59,11 @@ test('Overriding default strategies uses the custom deriveConstraint function', const findMyWay = FindMyWay({ constraints: { version: customVersioning } }) findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=2' } }, (req, res, params) => { - t.equal(req.headers.accept, 'application/vnd.example.api+json;version=2') + t.assert.equal(req.headers.accept, 'application/vnd.example.api+json;version=2') }) findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=3' } }, (req, res, params) => { - t.equal(req.headers.accept, 'application/vnd.example.api+json;version=3') + t.assert.equal(req.headers.accept, 'application/vnd.example.api+json;version=3') }) findMyWay.lookup({ @@ -87,11 +86,11 @@ test('Overriding default strategies uses the custom deriveConstraint function (a findMyWay.addConstraintStrategy(customVersioning) findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=2' } }, (req, res, params) => { - t.equal(req.headers.accept, 'application/vnd.example.api+json;version=2') + t.assert.equal(req.headers.accept, 'application/vnd.example.api+json;version=2') }) findMyWay.on('GET', '/', { constraints: { version: 'application/vnd.example.api+json;version=3' } }, (req, res, params) => { - t.equal(req.headers.accept, 'application/vnd.example.api+json;version=3') + t.assert.equal(req.headers.accept, 'application/vnd.example.api+json;version=3') }) findMyWay.lookup({ @@ -113,7 +112,7 @@ test('Overriding custom strategies throws as error (add strategy outside constru findMyWay.addConstraintStrategy(customVersioning) - t.throws(() => findMyWay.addConstraintStrategy(customVersioning), + t.assert.throws(() => findMyWay.addConstraintStrategy(customVersioning), 'There already exists a custom constraint with the name version.' ) }) @@ -125,7 +124,7 @@ test('Overriding default strategies after defining a route with constraint', t = findMyWay.on('GET', '/', { constraints: { host: 'fastify.io', version: '1.0.0' } }, () => {}) - t.throws(() => findMyWay.addConstraintStrategy(customVersioning), + t.assert.throws(() => findMyWay.addConstraintStrategy(customVersioning), 'There already exists a route with version constraint.' ) }) diff --git a/test/constraint.custom.async.test.js b/test/constraint.custom.async.test.js index c25c42ce..36c783c1 100644 --- a/test/constraint.custom.async.test.js +++ b/test/constraint.custom.async.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const rfdc = require('rfdc')({ proto: true }) @@ -43,8 +42,8 @@ test('should derive multiple async constraints', t => { }, null, (err, result) => { - t.equal(err, null) - t.equal(result, 'asyncHandler') + t.assert.equal(err, null) + t.assert.equal(result, 'asyncHandler') } ) }) @@ -65,8 +64,8 @@ test('lookup should return an error from deriveConstraint', t => { }, null, (err, result) => { - t.same(err, new Error('wrong user-agent')) - t.equal(result, undefined) + t.assert.deepStrictEqual(err, new Error('wrong user-agent')) + t.assert.equal(result, undefined) } ) }) @@ -89,8 +88,8 @@ test('should derive sync and async constraints', t => { }, null, (err, result) => { - t.equal(err, null) - t.equal(result, 'asyncHandlerV1') + t.assert.equal(err, null) + t.assert.equal(result, 'asyncHandlerV1') } ) @@ -105,8 +104,8 @@ test('should derive sync and async constraints', t => { }, null, (err, result) => { - t.equal(err, null) - t.equal(result, 'asyncHandlerV2') + t.assert.equal(err, null) + t.assert.equal(result, 'asyncHandlerV2') } ) }) diff --git a/test/constraint.custom.test.js b/test/constraint.custom.test.js index f5e757de..aae01cf1 100644 --- a/test/constraint.custom.test.js +++ b/test/constraint.custom.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const alpha = () => { } const beta = () => { } @@ -32,9 +31,9 @@ test('A route could support a custom constraint strategy', t => { findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl' } }, alpha) findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget' } }, beta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'wget' }).handler, beta) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome' })) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'wget' }).handler, beta) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome' })) }) test('A route could support a custom constraint strategy (add strategy outside constructor)', t => { @@ -47,9 +46,9 @@ test('A route could support a custom constraint strategy (add strategy outside c findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl' } }, alpha) findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget' } }, beta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'wget' }).handler, beta) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome' })) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'wget' }).handler, beta) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome' })) }) test('A route could support a custom constraint strategy while versioned', t => { @@ -62,16 +61,16 @@ test('A route could support a custom constraint strategy while versioned', t => findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget', version: '2.0.0' } }, gamma) findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget', version: '3.0.0' } }, delta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '2.x' }).handler, gamma) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '3.x' }).handler, delta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '2.x' }).handler, gamma) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '3.x' }).handler, delta) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'wget', version: '1.x' })) }) test('A route could support a custom constraint strategy while versioned (add strategy outside constructor)', t => { @@ -86,16 +85,16 @@ test('A route could support a custom constraint strategy while versioned (add st findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget', version: '2.0.0' } }, gamma) findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget', version: '3.0.0' } }, delta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '2.x' }).handler, gamma) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '3.x' }).handler, delta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '2.x' }).handler, gamma) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '3.x' }).handler, delta) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'wget', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'wget', version: '1.x' })) }) test('A route could support a custom constraint strategy while versioned and host constrained', t => { @@ -107,16 +106,16 @@ test('A route could support a custom constraint strategy while versioned and hos findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl', version: '2.0.0', host: 'fastify.io' } }, beta) findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl', version: '2.0.0', host: 'example.io' } }, delta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'fastify.io' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'fastify.io' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'example.io' }).handler, delta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'fastify.io' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'fastify.io' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'example.io' }).handler, delta) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x', host: 'fastify.io' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'example.io' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x', host: 'fastify.io' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'example.io' })) }) test('A route could support a custom constraint strategy while versioned and host constrained (add strategy outside constructor)', t => { @@ -130,16 +129,16 @@ test('A route could support a custom constraint strategy while versioned and hos findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl', version: '2.0.0', host: 'fastify.io' } }, beta) findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl', version: '2.0.0', host: 'example.io' } }, delta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'fastify.io' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'fastify.io' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'example.io' }).handler, delta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'fastify.io' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'fastify.io' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x', host: 'example.io' }).handler, delta) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x', host: 'fastify.io' })) - t.notOk(findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'example.io' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'chrome', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '3.x', host: 'fastify.io' })) + t.assert.ok(!findMyWay.find('GET', '/', { requestedBy: 'curl', version: '1.x', host: 'example.io' })) }) test('Custom constraint strategies can set mustMatchWhenDerived flag to true which prevents matches to unconstrained routes when a constraint is derived and there are no other routes', t => { @@ -153,11 +152,11 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to true whi } }, defaultRoute (req, res) { - t.pass() + t.assert.ok('pass') } }) - findMyWay.on('GET', '/', {}, () => t.fail()) + findMyWay.on('GET', '/', {}, () => t.assert.assert.fail()) findMyWay.lookup({ method: 'GET', url: '/', headers: { 'user-agent': 'node' } }, null) }) @@ -167,7 +166,7 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to true whi const findMyWay = FindMyWay({ defaultRoute (req, res) { - t.pass() + t.assert.ok('pass') } }) @@ -176,7 +175,7 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to true whi mustMatchWhenDerived: true }) - findMyWay.on('GET', '/', {}, () => t.fail()) + findMyWay.on('GET', '/', {}, () => t.assert.assert.fail()) findMyWay.lookup({ method: 'GET', url: '/', headers: { 'user-agent': 'node' } }, null) }) @@ -192,13 +191,13 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to true whi } }, defaultRoute (req, res) { - t.pass() + t.assert.ok('pass') } }) - findMyWay.on('GET', '/', {}, () => t.fail()) - findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl' } }, () => t.fail()) - findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget' } }, () => t.fail()) + findMyWay.on('GET', '/', {}, () => t.assert.assert.fail()) + findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl' } }, () => t.assert.assert.fail()) + findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget' } }, () => t.assert.assert.fail()) findMyWay.lookup({ method: 'GET', url: '/', headers: { 'user-agent': 'node' } }, null) }) @@ -208,7 +207,7 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to true whi const findMyWay = FindMyWay({ defaultRoute (req, res) { - t.pass() + t.assert.ok('pass') } }) @@ -217,9 +216,9 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to true whi mustMatchWhenDerived: true }) - findMyWay.on('GET', '/', {}, () => t.fail()) - findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl' } }, () => t.fail()) - findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget' } }, () => t.fail()) + findMyWay.on('GET', '/', {}, () => t.assert.assert.fail()) + findMyWay.on('GET', '/', { constraints: { requestedBy: 'curl' } }, () => t.assert.assert.fail()) + findMyWay.on('GET', '/', { constraints: { requestedBy: 'wget' } }, () => t.assert.assert.fail()) findMyWay.lookup({ method: 'GET', url: '/', headers: { 'user-agent': 'node' } }, null) }) @@ -235,11 +234,11 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to false wh } }, defaultRoute (req, res) { - t.fail() + t.assert.assert.fail() } }) - findMyWay.on('GET', '/', {}, () => t.pass()) + findMyWay.on('GET', '/', {}, () => t.assert.ok('pass')) findMyWay.lookup({ method: 'GET', url: '/', headers: { 'user-agent': 'node' } }, null) }) @@ -249,7 +248,7 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to false wh const findMyWay = FindMyWay({ defaultRoute (req, res) { - t.pass() + t.assert.ok('pass') } }) @@ -258,7 +257,7 @@ test('Custom constraint strategies can set mustMatchWhenDerived flag to false wh mustMatchWhenDerived: true }) - findMyWay.on('GET', '/', {}, () => t.pass()) + findMyWay.on('GET', '/', {}, () => t.assert.ok('pass')) findMyWay.lookup({ method: 'GET', url: '/', headers: { 'user-agent': 'node' } }, null) }) @@ -268,7 +267,7 @@ test('Has constraint strategy method test', t => { const findMyWay = FindMyWay() - t.same(findMyWay.hasConstraintStrategy(customHeaderConstraint.name), false) + t.assert.deepEqual(findMyWay.hasConstraintStrategy(customHeaderConstraint.name), false) findMyWay.addConstraintStrategy(customHeaderConstraint) - t.same(findMyWay.hasConstraintStrategy(customHeaderConstraint.name), true) + t.assert.deepEqual(findMyWay.hasConstraintStrategy(customHeaderConstraint.name), true) }) diff --git a/test/constraint.default-versioning.test.js b/test/constraint.default-versioning.test.js index 6784aa2b..1bc34664 100644 --- a/test/constraint.default-versioning.test.js +++ b/test/constraint.default-versioning.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const noop = () => { } @@ -13,13 +12,13 @@ test('A route could support multiple versions (find) / 1', t => { findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, noop) findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, noop) - t.ok(findMyWay.find('GET', '/', { version: '1.x' })) - t.ok(findMyWay.find('GET', '/', { version: '1.2.3' })) - t.ok(findMyWay.find('GET', '/', { version: '3.x' })) - t.ok(findMyWay.find('GET', '/', { version: '3.2.0' })) - t.notOk(findMyWay.find('GET', '/', { version: '2.x' })) - t.notOk(findMyWay.find('GET', '/', { version: '2.3.4' })) - t.notOk(findMyWay.find('GET', '/', { version: '3.2.1' })) + t.assert.ok(findMyWay.find('GET', '/', { version: '1.x' })) + t.assert.ok(findMyWay.find('GET', '/', { version: '1.2.3' })) + t.assert.ok(findMyWay.find('GET', '/', { version: '3.x' })) + t.assert.ok(findMyWay.find('GET', '/', { version: '3.2.0' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: '2.3.4' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: '3.2.1' })) }) test('A route could support multiple versions (find) / 2', t => { @@ -30,13 +29,13 @@ test('A route could support multiple versions (find) / 2', t => { findMyWay.on('GET', '/test', { constraints: { version: '1.2.3' } }, noop) findMyWay.on('GET', '/test', { constraints: { version: '3.2.0' } }, noop) - t.ok(findMyWay.find('GET', '/test', { version: '1.x' })) - t.ok(findMyWay.find('GET', '/test', { version: '1.2.3' })) - t.ok(findMyWay.find('GET', '/test', { version: '3.x' })) - t.ok(findMyWay.find('GET', '/test', { version: '3.2.0' })) - t.notOk(findMyWay.find('GET', '/test', { version: '2.x' })) - t.notOk(findMyWay.find('GET', '/test', { version: '2.3.4' })) - t.notOk(findMyWay.find('GET', '/test', { version: '3.2.1' })) + t.assert.ok(findMyWay.find('GET', '/test', { version: '1.x' })) + t.assert.ok(findMyWay.find('GET', '/test', { version: '1.2.3' })) + t.assert.ok(findMyWay.find('GET', '/test', { version: '3.x' })) + t.assert.ok(findMyWay.find('GET', '/test', { version: '3.2.0' })) + t.assert.ok(!findMyWay.find('GET', '/test', { version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/test', { version: '2.3.4' })) + t.assert.ok(!findMyWay.find('GET', '/test', { version: '3.2.1' })) }) test('A route could support multiple versions (find) / 3', t => { @@ -48,16 +47,16 @@ test('A route could support multiple versions (find) / 3', t => { findMyWay.on('GET', '/test/:id/hello', { constraints: { version: '3.2.0' } }, noop) findMyWay.on('GET', '/test/name/hello', { constraints: { version: '4.0.0' } }, noop) - t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' })) - t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' })) - t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.x' })) - t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' })) - t.ok(findMyWay.find('GET', '/test/name/hello', { version: '4.x' })) - t.ok(findMyWay.find('GET', '/test/name/hello', { version: '3.x' })) - t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '2.x' })) - t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '2.3.4' })) - t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.1' })) - t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '4.x' })) + t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' })) + t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' })) + t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.x' })) + t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' })) + t.assert.ok(findMyWay.find('GET', '/test/name/hello', { version: '4.x' })) + t.assert.ok(findMyWay.find('GET', '/test/name/hello', { version: '3.x' })) + t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '2.3.4' })) + t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '3.2.1' })) + t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '4.x' })) }) test('A route could support multiple versions (find) / 4', t => { @@ -68,14 +67,14 @@ test('A route could support multiple versions (find) / 4', t => { findMyWay.on('GET', '/test/*', { constraints: { version: '1.2.3' } }, noop) findMyWay.on('GET', '/test/hello', { constraints: { version: '3.2.0' } }, noop) - t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' })) - t.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' })) - t.ok(findMyWay.find('GET', '/test/hello', { version: '3.x' })) - t.ok(findMyWay.find('GET', '/test/hello', { version: '3.2.0' })) - t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' })) - t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '3.x' })) - t.notOk(findMyWay.find('GET', '/test/1234/hello', { version: '2.x' })) - t.notOk(findMyWay.find('GET', '/test/hello', { version: '2.x' })) + t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.x' })) + t.assert.ok(findMyWay.find('GET', '/test/1234/hello', { version: '1.2.3' })) + t.assert.ok(findMyWay.find('GET', '/test/hello', { version: '3.x' })) + t.assert.ok(findMyWay.find('GET', '/test/hello', { version: '3.2.0' })) + t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '3.2.0' })) + t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '3.x' })) + t.assert.ok(!findMyWay.find('GET', '/test/1234/hello', { version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/test/hello', { version: '2.x' })) }) test('A route could support multiple versions (find) / 5', t => { @@ -86,7 +85,7 @@ test('A route could support multiple versions (find) / 5', t => { findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, () => false) findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, () => true) - t.ok(findMyWay.find('GET', '/', { version: '*' }).handler()) + t.assert.ok(findMyWay.find('GET', '/', { version: '*' }).handler()) }) test('Find with a version but without versioned routes', t => { @@ -96,7 +95,7 @@ test('Find with a version but without versioned routes', t => { findMyWay.on('GET', '/', noop) - t.notOk(findMyWay.find('GET', '/', { version: '1.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { version: '1.x' })) }) test('A route could support multiple versions (lookup)', t => { @@ -105,18 +104,18 @@ test('A route could support multiple versions (lookup)', t => { const findMyWay = FindMyWay({ defaultRoute: (req, res) => { const versions = ['2.x', '2.3.4', '3.2.1'] - t.ok(versions.indexOf(req.headers['accept-version']) > -1) + t.assert.ok(versions.indexOf(req.headers['accept-version']) > -1) } }) findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, (req, res) => { const versions = ['1.x', '1.2.3'] - t.ok(versions.indexOf(req.headers['accept-version']) > -1) + t.assert.ok(versions.indexOf(req.headers['accept-version']) > -1) }) findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, (req, res) => { const versions = ['3.x', '3.2.0'] - t.ok(versions.indexOf(req.headers['accept-version']) > -1) + t.assert.ok(versions.indexOf(req.headers['accept-version']) > -1) }) findMyWay.lookup({ @@ -172,11 +171,11 @@ test('It should always choose the highest version of a route', t => { }) findMyWay.on('GET', '/', { constraints: { version: '2.4.0' } }, (req, res) => { - t.pass('Yeah!') + t.assert.ok('Yeah!') }) findMyWay.on('GET', '/', { constraints: { version: '3.3.0' } }, (req, res) => { - t.pass('Yeah!') + t.assert.ok('Yeah!') }) findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, (req, res) => { @@ -192,7 +191,7 @@ test('It should always choose the highest version of a route', t => { }) findMyWay.on('GET', '/', { constraints: { version: '4.3.2' } }, (req, res) => { - t.pass('Yeah!') + t.assert.ok('Yeah!') }) findMyWay.lookup({ @@ -222,8 +221,8 @@ test('Declare the same route with and without version', t => { findMyWay.on('GET', '/', noop) findMyWay.on('GET', '/', { constraints: { version: '1.2.0' } }, noop) - t.ok(findMyWay.find('GET', '/', { version: '1.x' })) - t.ok(findMyWay.find('GET', '/', {})) + t.assert.ok(findMyWay.find('GET', '/', { version: '1.x' })) + t.assert.ok(findMyWay.find('GET', '/', {})) }) test('It should throw if you declare multiple times the same route', t => { @@ -237,7 +236,7 @@ test('It should throw if you declare multiple times the same route', t => { findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, noop) t.fail('It should throw') } catch (err) { - t.equal(err.message, 'Method \'GET\' already declared for route \'/\' with constraints \'{"version":"1.2.3"}\'') + t.assert.equal(err.message, 'Method \'GET\' already declared for route \'/\' with constraints \'{"version":"1.2.3"}\'') } }) @@ -251,7 +250,7 @@ test('Versioning won\'t work if there are no versioned routes', t => { }) findMyWay.on('GET', '/', (req, res) => { - t.pass('Yeah!') + t.assert.ok('Yeah!') }) findMyWay.lookup({ @@ -271,7 +270,7 @@ test('Unversioned routes aren\'t triggered when unknown versions are requested', const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.ok('We should be here') + t.assert.ok('We should be here') } }) diff --git a/test/constraint.host.test.js b/test/constraint.host.test.js index 5033ed45..b6c426a5 100644 --- a/test/constraint.host.test.js +++ b/test/constraint.host.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const alpha = () => { } const beta = () => { } @@ -16,10 +15,10 @@ test('A route supports multiple host constraints', t => { findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, beta) findMyWay.on('GET', '/', { constraints: { host: 'example.com' } }, gamma) - t.equal(findMyWay.find('GET', '/', {}).handler, alpha) - t.equal(findMyWay.find('GET', '/', { host: 'something-else.io' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'example.com' }).handler, gamma) + t.assert.equal(findMyWay.find('GET', '/', {}).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { host: 'something-else.io' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'example.com' }).handler, gamma) }) test('A route supports wildcard host constraints', t => { @@ -30,10 +29,10 @@ test('A route supports wildcard host constraints', t => { findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, beta) findMyWay.on('GET', '/', { constraints: { host: /.*\.fastify\.io/ } }, gamma) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'foo.fastify.io' }).handler, gamma) - t.equal(findMyWay.find('GET', '/', { host: 'bar.fastify.io' }).handler, gamma) - t.notOk(findMyWay.find('GET', '/', { host: 'example.com' })) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'foo.fastify.io' }).handler, gamma) + t.assert.equal(findMyWay.find('GET', '/', { host: 'bar.fastify.io' }).handler, gamma) + t.assert.ok(!findMyWay.find('GET', '/', { host: 'example.com' })) }) test('A route supports multiple host constraints (lookup)', t => { @@ -43,13 +42,13 @@ test('A route supports multiple host constraints (lookup)', t => { findMyWay.on('GET', '/', {}, (req, res) => {}) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, (req, res) => { - t.equal(req.headers.host, 'fastify.io') + t.assert.equal(req.headers.host, 'fastify.io') }) findMyWay.on('GET', '/', { constraints: { host: 'example.com' } }, (req, res) => { - t.equal(req.headers.host, 'example.com') + t.assert.equal(req.headers.host, 'example.com') }) findMyWay.on('GET', '/', { constraints: { host: /.+\.fancy\.ca/ } }, (req, res) => { - t.ok(req.headers.host.endsWith('.fancy.ca')) + t.assert.ok(req.headers.host.endsWith('.fancy.ca')) }) findMyWay.lookup({ @@ -85,7 +84,7 @@ test('A route supports up to 31 host constraints', (t) => { findMyWay.on('GET', '/', { constraints: { host } }, alpha) } - t.equal(findMyWay.find('GET', '/', { host: 'h01' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { host: 'h01' }).handler, alpha) }) test('A route throws when constraint limit exceeded', (t) => { diff --git a/test/constraints.test.js b/test/constraints.test.js index 13124fcb..52774fba 100644 --- a/test/constraints.test.js +++ b/test/constraints.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const alpha = () => { } const beta = () => { } @@ -15,12 +14,12 @@ test('A route could support multiple host constraints while versioned', t => { findMyWay.on('GET', '/', { constraints: { host: 'fastify.io', version: '1.1.0' } }, beta) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io', version: '2.1.0' } }, gamma) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.x' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.1.x' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.x' }).handler, gamma) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.1.x' }).handler, gamma) - t.notOk(findMyWay.find('GET', '/', { host: 'fastify.io', version: '3.x' })) - t.notOk(findMyWay.find('GET', '/', { host: 'something-else.io', version: '1.x' })) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.x' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.1.x' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.x' }).handler, gamma) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.1.x' }).handler, gamma) + t.assert.ok(!findMyWay.find('GET', '/', { host: 'fastify.io', version: '3.x' })) + t.assert.ok(!findMyWay.find('GET', '/', { host: 'something-else.io', version: '1.x' })) }) test('Constrained routes are matched before unconstrainted routes when the constrained route is added last', t => { @@ -31,9 +30,9 @@ test('Constrained routes are matched before unconstrainted routes when the const findMyWay.on('GET', '/', {}, alpha) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, beta) - t.equal(findMyWay.find('GET', '/', {}).handler, alpha) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'example.com' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', {}).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'example.com' }).handler, alpha) }) test('Constrained routes are matched before unconstrainted routes when the constrained route is added first', t => { @@ -44,9 +43,9 @@ test('Constrained routes are matched before unconstrainted routes when the const findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, beta) findMyWay.on('GET', '/', {}, alpha) - t.equal(findMyWay.find('GET', '/', {}).handler, alpha) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'example.com' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', {}).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'example.com' }).handler, alpha) }) test('Routes with multiple constraints are matched before routes with one constraint when the doubly-constrained route is added last', t => { @@ -57,9 +56,9 @@ test('Routes with multiple constraints are matched before routes with one constr findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, alpha) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io', version: '1.0.0' } }, beta) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.0.0' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.0.0' }), null) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.0.0' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.0.0' }), null) }) test('Routes with multiple constraints are matched before routes with one constraint when the doubly-constrained route is added first', t => { @@ -70,9 +69,9 @@ test('Routes with multiple constraints are matched before routes with one constr findMyWay.on('GET', '/', { constraints: { host: 'fastify.io', version: '1.0.0' } }, beta) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, alpha) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, alpha) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.0.0' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.0.0' }), null) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io' }).handler, alpha) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.0.0' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.0.0' }), null) }) test('Routes with multiple constraints are matched before routes with one constraint before unconstrained routes', t => { @@ -84,9 +83,9 @@ test('Routes with multiple constraints are matched before routes with one constr findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, alpha) findMyWay.on('GET', '/', { constraints: {} }, gamma) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.0.0' }).handler, beta) - t.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.0.0' }), null) - t.equal(findMyWay.find('GET', '/', { host: 'example.io' }).handler, gamma) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '1.0.0' }).handler, beta) + t.assert.equal(findMyWay.find('GET', '/', { host: 'fastify.io', version: '2.0.0' }), null) + t.assert.equal(findMyWay.find('GET', '/', { host: 'example.io' }).handler, gamma) }) test('Has constraint strategy method test', t => { @@ -94,16 +93,16 @@ test('Has constraint strategy method test', t => { const findMyWay = FindMyWay() - t.same(findMyWay.hasConstraintStrategy('version'), false) - t.same(findMyWay.hasConstraintStrategy('host'), false) + t.assert.deepEqual(findMyWay.hasConstraintStrategy('version'), false) + t.assert.deepEqual(findMyWay.hasConstraintStrategy('host'), false) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, () => {}) - t.same(findMyWay.hasConstraintStrategy('version'), false) - t.same(findMyWay.hasConstraintStrategy('host'), true) + t.assert.deepEqual(findMyWay.hasConstraintStrategy('version'), false) + t.assert.deepEqual(findMyWay.hasConstraintStrategy('host'), true) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io', version: '1.0.0' } }, () => {}) - t.same(findMyWay.hasConstraintStrategy('version'), true) - t.same(findMyWay.hasConstraintStrategy('host'), true) + t.assert.deepEqual(findMyWay.hasConstraintStrategy('version'), true) + t.assert.deepEqual(findMyWay.hasConstraintStrategy('host'), true) }) diff --git a/test/custom-querystring-parser.test.js b/test/custom-querystring-parser.test.js index e6792b5a..f74b766c 100644 --- a/test/custom-querystring-parser.test.js +++ b/test/custom-querystring-parser.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const querystring = require('fast-querystring') const FindMyWay = require('../') @@ -10,13 +9,13 @@ test('Custom querystring parser', t => { const findMyWay = FindMyWay({ querystringParser: function (str) { - t.equal(str, 'foo=bar&baz=faz') + t.assert.equal(str, 'foo=bar&baz=faz') return querystring.parse(str) } }) findMyWay.on('GET', '/', () => {}) - t.same(findMyWay.find('GET', '/?foo=bar&baz=faz').searchParams, { foo: 'bar', baz: 'faz' }) + t.assert.deepEqual(findMyWay.find('GET', '/?foo=bar&baz=faz').searchParams, { foo: 'bar', baz: 'faz' }) }) test('Custom querystring parser should be called also if there is nothing to parse', t => { @@ -24,13 +23,13 @@ test('Custom querystring parser should be called also if there is nothing to par const findMyWay = FindMyWay({ querystringParser: function (str) { - t.equal(str, '') + t.assert.equal(str, '') return querystring.parse(str) } }) findMyWay.on('GET', '/', () => {}) - t.same(findMyWay.find('GET', '/').searchParams, {}) + t.assert.deepEqual(findMyWay.find('GET', '/').searchParams, {}) }) test('Querystring without value', t => { @@ -38,10 +37,10 @@ test('Querystring without value', t => { const findMyWay = FindMyWay({ querystringParser: function (str) { - t.equal(str, 'foo') + t.assert.equal(str, 'foo') return querystring.parse(str) } }) findMyWay.on('GET', '/', () => {}) - t.same(findMyWay.find('GET', '/?foo').searchParams, { foo: '' }) + t.assert.deepEqual(findMyWay.find('GET', '/?foo').searchParams, { foo: '' }) }) diff --git a/test/errors.test.js b/test/errors.test.js index 6866f144..07e2a67c 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Method should be a string', t => { @@ -12,7 +11,7 @@ test('Method should be a string', t => { findMyWay.on(0, '/test', () => {}) t.fail('method shoukd be a string') } catch (e) { - t.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -24,7 +23,7 @@ test('Method should be a string [ignoreTrailingSlash=true]', t => { findMyWay.on(0, '/test', () => {}) t.fail('method shoukd be a string') } catch (e) { - t.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -36,7 +35,7 @@ test('Method should be a string [ignoreDuplicateSlashes=true]', t => { findMyWay.on(0, '/test', () => {}) t.fail('method shoukd be a string') } catch (e) { - t.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -48,7 +47,7 @@ test('Method should be a string (array)', t => { findMyWay.on(['GET', 0], '/test', () => {}) t.fail('method shoukd be a string') } catch (e) { - t.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -60,7 +59,7 @@ test('Method should be a string (array) [ignoreTrailingSlash=true]', t => { findMyWay.on(['GET', 0], '/test', () => {}) t.fail('method shoukd be a string') } catch (e) { - t.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -72,7 +71,7 @@ test('Method should be a string (array) [ignoreDuplicateSlashes=true]', t => { findMyWay.on(['GET', 0], '/test', () => {}) t.fail('method shoukd be a string') } catch (e) { - t.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -84,7 +83,7 @@ test('Path should be a string', t => { findMyWay.on('GET', 0, () => {}) t.fail('path should be a string') } catch (e) { - t.equal(e.message, 'Path should be a string') + t.assert.equal(e.message, 'Path should be a string') } }) @@ -96,7 +95,7 @@ test('Path should be a string [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', 0, () => {}) t.fail('path should be a string') } catch (e) { - t.equal(e.message, 'Path should be a string') + t.assert.equal(e.message, 'Path should be a string') } }) @@ -108,7 +107,7 @@ test('Path should be a string [ignoreDuplicateSlashes=true]', t => { findMyWay.on('GET', 0, () => {}) t.fail('path should be a string') } catch (e) { - t.equal(e.message, 'Path should be a string') + t.assert.equal(e.message, 'Path should be a string') } }) @@ -120,7 +119,7 @@ test('The path could not be empty', t => { findMyWay.on('GET', '', () => {}) t.fail('The path could not be empty') } catch (e) { - t.equal(e.message, 'The path could not be empty') + t.assert.equal(e.message, 'The path could not be empty') } }) @@ -132,7 +131,7 @@ test('The path could not be empty [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', '', () => {}) t.fail('The path could not be empty') } catch (e) { - t.equal(e.message, 'The path could not be empty') + t.assert.equal(e.message, 'The path could not be empty') } }) @@ -144,7 +143,7 @@ test('The path could not be empty [ignoreDuplicateSlashes=true]', t => { findMyWay.on('GET', '', () => {}) t.fail('The path could not be empty') } catch (e) { - t.equal(e.message, 'The path could not be empty') + t.assert.equal(e.message, 'The path could not be empty') } }) @@ -156,7 +155,7 @@ test('The first character of a path should be `/` or `*`', t => { findMyWay.on('GET', 'a', () => {}) t.fail('The first character of a path should be `/` or `*`') } catch (e) { - t.equal(e.message, 'The first character of a path should be `/` or `*`') + t.assert.equal(e.message, 'The first character of a path should be `/` or `*`') } }) @@ -168,7 +167,7 @@ test('The first character of a path should be `/` or `*` [ignoreTrailingSlash=tr findMyWay.on('GET', 'a', () => {}) t.fail('The first character of a path should be `/` or `*`') } catch (e) { - t.equal(e.message, 'The first character of a path should be `/` or `*`') + t.assert.equal(e.message, 'The first character of a path should be `/` or `*`') } }) @@ -180,7 +179,7 @@ test('The first character of a path should be `/` or `*` [ignoreDuplicateSlashes findMyWay.on('GET', 'a', () => {}) t.fail('The first character of a path should be `/` or `*`') } catch (e) { - t.equal(e.message, 'The first character of a path should be `/` or `*`') + t.assert.equal(e.message, 'The first character of a path should be `/` or `*`') } }) @@ -192,7 +191,7 @@ test('Handler should be a function', t => { findMyWay.on('GET', '/test', 0) t.fail('handler should be a function') } catch (e) { - t.equal(e.message, 'Handler should be a function') + t.assert.equal(e.message, 'Handler should be a function') } }) @@ -204,7 +203,7 @@ test('Method is not an http method.', t => { findMyWay.on('GETT', '/test', () => {}) t.fail('method is not a valid http method') } catch (e) { - t.equal(e.message, 'Method \'GETT\' is not an http method.') + t.assert.equal(e.message, 'Method \'GETT\' is not an http method.') } }) @@ -216,7 +215,7 @@ test('Method is not an http method. (array)', t => { findMyWay.on(['POST', 'GETT'], '/test', () => {}) t.fail('method is not a valid http method') } catch (e) { - t.equal(e.message, 'Method \'GETT\' is not an http method.') + t.assert.equal(e.message, 'Method \'GETT\' is not an http method.') } }) @@ -228,7 +227,7 @@ test('The default route must be a function', t => { }) t.fail('default route must be a function') } catch (e) { - t.equal(e.message, 'The default route must be a function') + t.assert.equal(e.message, 'The default route must be a function') } }) @@ -241,7 +240,7 @@ test('Method already declared', t => { findMyWay.on('GET', '/test', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } }) @@ -254,7 +253,7 @@ test('Method already declared if * is used', t => { findMyWay.on('GET', '*', () => {}) t.fail('should throw error') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') } }) @@ -267,7 +266,7 @@ test('Method already declared if /* is used', t => { findMyWay.on('GET', '/*', () => {}) t.fail('should throw error') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') } }) @@ -284,14 +283,14 @@ test('Method already declared [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', '/test', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } }) @@ -305,14 +304,14 @@ test('Method already declared [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', '/test', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } }) }) @@ -330,14 +329,14 @@ test('Method already declared [ignoreDuplicateSlashes=true]', t => { findMyWay.on('GET', '/test', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '//test', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } }) @@ -351,14 +350,14 @@ test('Method already declared [ignoreDuplicateSlashes=true]', t => { findMyWay.on('GET', '/test', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '//test', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } }) }) @@ -375,7 +374,7 @@ test('Method already declared nested route', t => { findMyWay.on('GET', '/test/hello', () => {}) t.fail('method already delcared in nested route') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } }) @@ -394,14 +393,14 @@ test('Method already declared nested route [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', '/test/hello', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/hello/', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } }) @@ -414,7 +413,7 @@ test('Method already declared nested route [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', '/test', { constraints: { host: 'fastify.io' } }, () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{"host":"fastify.io"}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{"host":"fastify.io"}\'') } }) @@ -430,14 +429,14 @@ test('Method already declared nested route [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', '/test/hello', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/hello/', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } }) }) @@ -457,14 +456,14 @@ test('Method already declared nested route [ignoreDuplicateSlashes=true]', t => findMyWay.on('GET', '/test/hello', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test//hello', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } }) @@ -480,14 +479,14 @@ test('Method already declared nested route [ignoreDuplicateSlashes=true]', t => findMyWay.on('GET', '/test/hello', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test//hello', () => {}) t.fail('method already declared') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } }) }) diff --git a/test/fastify-issue-3129.test.js b/test/fastify-issue-3129.test.js index e632074c..1a3cdaa2 100644 --- a/test/fastify-issue-3129.test.js +++ b/test/fastify-issue-3129.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('contain param and wildcard together', t => { @@ -14,13 +13,13 @@ test('contain param and wildcard together', t => { }) findMyWay.on('GET', '/:lang/item/:id', (req, res, params) => { - t.same(params.lang, 'fr') - t.same(params.id, '12345') + t.assert.deepEqual(params.lang, 'fr') + t.assert.deepEqual(params.id, '12345') }) findMyWay.on('GET', '/:lang/item/*', (req, res, params) => { - t.same(params.lang, 'fr') - t.same(params['*'], '12345/edit') + t.assert.deepEqual(params.lang, 'fr') + t.assert.deepEqual(params['*'], '12345/edit') }) findMyWay.lookup( diff --git a/test/fastify-issue-3957.test.js b/test/fastify-issue-3957.test.js index e3c944d4..ca26787c 100644 --- a/test/fastify-issue-3957.test.js +++ b/test/fastify-issue-3957.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('wildcard should not limit by maxParamLength', t => { @@ -14,7 +13,7 @@ test('wildcard should not limit by maxParamLength', t => { }) findMyWay.on('GET', '*', (req, res, params) => { - t.same(params['*'], '/portfolios/b5859fb9-6c76-4db8-b3d1-337c5be3fd8b/instruments/2a694406-b43f-439d-aa11-0c814805c930/positions') + t.assert.deepEqual(params['*'], '/portfolios/b5859fb9-6c76-4db8-b3d1-337c5be3fd8b/instruments/2a694406-b43f-439d-aa11-0c814805c930/positions') }) findMyWay.lookup( diff --git a/test/find-route.test.js b/test/find-route.test.js index 9b34e722..e522fbd9 100644 --- a/test/find-route.test.js +++ b/test/find-route.test.js @@ -1,14 +1,13 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const rfdc = require('rfdc')({ proto: true }) const FindMyWay = require('..') function equalRouters (t, router1, router2) { t.strictSame(router1._opts, router2._opts) - t.same(router1.routes, router2.routes) - t.same(router1.trees, router2.trees) + t.assert.deepEqual(router1.routes, router2.routes) + t.assert.deepEqual(router1.trees, router2.trees) t.strictSame(router1.constrainer.strategies, router2.constrainer.strategies) t.strictSame( @@ -28,7 +27,7 @@ test('findRoute returns null if there is no routes', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/example') - t.equal(route, null) + t.assert.equal(route, null) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -45,9 +44,9 @@ test('findRoute returns handler and store for a static route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/example') - t.equal(route.handler, handler) - t.equal(route.store, store) - t.same(route.params, []) + t.assert.equal(route.handler, handler) + t.assert.equal(route.store, store) + t.assert.deepEqual(route.params, []) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -63,7 +62,7 @@ test('findRoute returns null for a static route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/example1') - t.equal(route, null) + t.assert.equal(route, null) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -79,8 +78,8 @@ test('findRoute returns handler and params for a parametric route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/:param') - t.equal(route.handler, handler) - t.same(route.params, ['param']) + t.assert.equal(route.handler, handler) + t.assert.deepEqual(route.params, ['param']) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -96,7 +95,7 @@ test('findRoute returns null for a parametric route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/bar/:param') - t.equal(route, null) + t.assert.equal(route, null) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -112,8 +111,8 @@ test('findRoute returns handler and params for a parametric route with static su const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/:param-static') - t.equal(route.handler, handler) - t.same(route.params, ['param']) + t.assert.equal(route.handler, handler) + t.assert.deepEqual(route.params, ['param']) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -127,7 +126,7 @@ test('findRoute returns null for a parametric route with static suffix', (t) => const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/:param-static2') - t.equal(route, null) + t.assert.equal(route, null) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -143,8 +142,8 @@ test('findRoute returns handler and original params even if a param name differe const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/:param2') - t.equal(route.handler, handler) - t.same(route.params, ['param1']) + t.assert.equal(route.handler, handler) + t.assert.deepEqual(route.params, ['param1']) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -160,8 +159,8 @@ test('findRoute returns handler and params for a multi-parametric route', (t) => const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/:param1-:param2') - t.equal(route.handler, handler) - t.same(route.params, ['param1', 'param2']) + t.assert.equal(route.handler, handler) + t.assert.deepEqual(route.params, ['param1', 'param2']) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -175,7 +174,7 @@ test('findRoute returns null for a multi-parametric route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/foo/:param1-:param2/bar2') - t.equal(route, null) + t.assert.equal(route, null) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -191,8 +190,8 @@ test('findRoute returns handler and regexp param for a regexp route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/:param(^\\d+$)') - t.equal(route.handler, handler) - t.same(route.params, ['param']) + t.assert.equal(route.handler, handler) + t.assert.deepEqual(route.params, ['param']) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -206,7 +205,7 @@ test('findRoute returns null for a regexp route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/:file(^\\D+).png') - t.equal(route, null) + t.assert.equal(route, null) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -222,8 +221,8 @@ test('findRoute returns handler and wildcard param for a wildcard route', (t) => const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/example/*') - t.equal(route.handler, handler) - t.same(route.params, ['*']) + t.assert.equal(route.handler, handler) + t.assert.deepEqual(route.params, ['*']) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -237,7 +236,7 @@ test('findRoute returns null for a wildcard route', (t) => { const fundMyWayClone = rfdc(findMyWay) const route = findMyWay.findRoute('GET', '/foo2/*') - t.equal(route, null) + t.assert.equal(route, null) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -259,17 +258,17 @@ test('findRoute returns handler for a constrained route', (t) => { { const route = findMyWay.findRoute('GET', '/example') - t.equal(route, null) + t.assert.equal(route, null) } { const route = findMyWay.findRoute('GET', '/example', { version: '1.0.0' }) - t.equal(route.handler, handler) + t.assert.equal(route.handler, handler) } { const route = findMyWay.findRoute('GET', '/example', { version: '2.0.0' }) - t.equal(route, null) + t.assert.equal(route, null) } equalRouters(t, findMyWay, fundMyWayClone) diff --git a/test/find.test.js b/test/find.test.js index 2de277f8..812b8f5a 100644 --- a/test/find.test.js +++ b/test/find.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('find calls can pass no constraints', t => { @@ -11,7 +10,7 @@ test('find calls can pass no constraints', t => { findMyWay.on('GET', '/a', () => {}) findMyWay.on('GET', '/a/b', () => {}) - t.ok(findMyWay.find('GET', '/a')) - t.ok(findMyWay.find('GET', '/a/b')) - t.notOk(findMyWay.find('GET', '/a/b/c')) + t.assert.ok(findMyWay.find('GET', '/a')) + t.assert.ok(findMyWay.find('GET', '/a/b')) + t.assert.ok(!findMyWay.find('GET', '/a/b/c')) }) diff --git a/test/for-in-loop.test.js b/test/for-in-loop.test.js index cabe9698..93f1d481 100644 --- a/test/for-in-loop.test.js +++ b/test/for-in-loop.test.js @@ -2,10 +2,12 @@ /* eslint no-extend-native: off */ -const t = require('tap') +const { test } = require('node:test') // Something could extend the Array prototype Array.prototype.test = null -t.doesNotThrow(() => { - require('../') +test('for-in-loop', t => { + t.assert.doesNotThrow(() => { + require('../') + }) }) diff --git a/test/full-url.test.js b/test/full-url.test.js index bf094bb0..5674fbda 100644 --- a/test/full-url.test.js +++ b/test/full-url.test.js @@ -1,6 +1,6 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const FindMyWay = require('../') const findMyWay = FindMyWay({ @@ -17,12 +17,14 @@ findMyWay.on('GET', '/a/:id', (req, res) => { res.end('{"message":"hello world"}') }) -t.same(findMyWay.find('GET', 'http://localhost/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) -t.same(findMyWay.find('GET', 'http://localhost:8080/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) -t.same(findMyWay.find('GET', 'http://123.123.123.123/a', {}), findMyWay.find('GET', '/a', {})) -t.same(findMyWay.find('GET', 'https://localhost/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) +test('full-url', t => { + t.assert.deepEqual(findMyWay.find('GET', 'http://localhost/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) + t.assert.deepEqual(findMyWay.find('GET', 'http://localhost:8080/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) + t.assert.deepEqual(findMyWay.find('GET', 'http://123.123.123.123/a', {}), findMyWay.find('GET', '/a', {})) + t.assert.deepEqual(findMyWay.find('GET', 'https://localhost/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) -t.same(findMyWay.find('GET', 'http://localhost/a/100', { host: 'localhost' }), findMyWay.find('GET', '/a/100', { host: 'localhost' })) -t.same(findMyWay.find('GET', 'http://localhost:8080/a/100', { host: 'localhost' }), findMyWay.find('GET', '/a/100', { host: 'localhost' })) -t.same(findMyWay.find('GET', 'http://123.123.123.123/a/100', {}), findMyWay.find('GET', '/a/100', {})) -t.same(findMyWay.find('GET', 'https://localhost/a/100', { host: 'localhost' }), findMyWay.find('GET', '/a/100', { host: 'localhost' })) + t.assert.deepEqual(findMyWay.find('GET', 'http://localhost/a/100', { host: 'localhost' }), findMyWay.find('GET', '/a/100', { host: 'localhost' })) + t.assert.deepEqual(findMyWay.find('GET', 'http://localhost:8080/a/100', { host: 'localhost' }), findMyWay.find('GET', '/a/100', { host: 'localhost' })) + t.assert.deepEqual(findMyWay.find('GET', 'http://123.123.123.123/a/100', {}), findMyWay.find('GET', '/a/100', {})) + t.assert.deepEqual(findMyWay.find('GET', 'https://localhost/a/100', { host: 'localhost' }), findMyWay.find('GET', '/a/100', { host: 'localhost' })) +}) diff --git a/test/has-route.test.js b/test/has-route.test.js index 0904de66..df91288d 100644 --- a/test/has-route.test.js +++ b/test/has-route.test.js @@ -1,14 +1,13 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const rfdc = require('rfdc')({ proto: true }) const FindMyWay = require('..') function equalRouters (t, router1, router2) { t.strictSame(router1._opts, router2._opts) - t.same(router1.routes, router2.routes) - t.same(router1.trees, router2.trees) + t.assert.deepEqual(router1.routes, router2.routes) + t.assert.deepEqual(router1.trees, router2.trees) t.strictSame( router1.constrainer.strategies, @@ -31,7 +30,7 @@ test('hasRoute returns false if there is no routes', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/example') - t.equal(hasRoute, false) + t.assert.equal(hasRoute, false) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -45,7 +44,7 @@ test('hasRoute returns true for a static route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/example') - t.equal(hasRoute, true) + t.assert.equal(hasRoute, true) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -59,7 +58,7 @@ test('hasRoute returns false for a static route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/example1') - t.equal(hasRoute, false) + t.assert.equal(hasRoute, false) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -73,7 +72,7 @@ test('hasRoute returns true for a parametric route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/:param') - t.equal(hasRoute, true) + t.assert.equal(hasRoute, true) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -87,7 +86,7 @@ test('hasRoute returns false for a parametric route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/bar/:param') - t.equal(hasRoute, false) + t.assert.equal(hasRoute, false) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -101,7 +100,7 @@ test('hasRoute returns true for a parametric route with static suffix', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/:param-static') - t.equal(hasRoute, true) + t.assert.equal(hasRoute, true) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -115,7 +114,7 @@ test('hasRoute returns false for a parametric route with static suffix', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/:param-static2') - t.equal(hasRoute, false) + t.assert.equal(hasRoute, false) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -129,7 +128,7 @@ test('hasRoute returns true even if a param name different', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/:param2') - t.equal(hasRoute, true) + t.assert.equal(hasRoute, true) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -143,7 +142,7 @@ test('hasRoute returns true for a multi-parametric route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/:param1-:param2') - t.equal(hasRoute, true) + t.assert.equal(hasRoute, true) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -157,7 +156,7 @@ test('hasRoute returns false for a multi-parametric route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/foo/:param1-:param2/bar2') - t.equal(hasRoute, false) + t.assert.equal(hasRoute, false) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -171,7 +170,7 @@ test('hasRoute returns true for a regexp route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/:param(^\\d+$)') - t.equal(hasRoute, true) + t.assert.equal(hasRoute, true) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -185,7 +184,7 @@ test('hasRoute returns false for a regexp route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/:file(^\\D+).png') - t.equal(hasRoute, false) + t.assert.equal(hasRoute, false) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -199,7 +198,7 @@ test('hasRoute returns true for a wildcard route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/example/*') - t.equal(hasRoute, true) + t.assert.equal(hasRoute, true) equalRouters(t, findMyWay, fundMyWayClone) }) @@ -213,7 +212,7 @@ test('hasRoute returns false for a wildcard route', t => { const fundMyWayClone = rfdc(findMyWay) const hasRoute = findMyWay.hasRoute('GET', '/foo2/*') - t.equal(hasRoute, false) + t.assert.equal(hasRoute, false) equalRouters(t, findMyWay, fundMyWayClone) }) diff --git a/test/host-storage.test.js b/test/host-storage.test.js index 0150ba2f..b14f9c00 100644 --- a/test/host-storage.test.js +++ b/test/host-storage.test.js @@ -1,27 +1,27 @@ const acceptHostStrategy = require('../lib/strategies/accept-host') -const t = require('tap') +const { test } = require('node:test') -t.test('can get hosts by exact matches', async (t) => { +test('can get hosts by exact matches', async (t) => { const storage = acceptHostStrategy.storage() - t.equal(storage.get('fastify.io'), undefined) + t.assert.equal(storage.get('fastify.io'), undefined) storage.set('fastify.io', true) - t.equal(storage.get('fastify.io'), true) + t.assert.equal(storage.get('fastify.io'), true) }) -t.test('can get hosts by regexp matches', async (t) => { +test('can get hosts by regexp matches', async (t) => { const storage = acceptHostStrategy.storage() - t.equal(storage.get('fastify.io'), undefined) + t.assert.equal(storage.get('fastify.io'), undefined) storage.set(/.+fastify\.io/, true) - t.equal(storage.get('foo.fastify.io'), true) - t.equal(storage.get('bar.fastify.io'), true) + t.assert.equal(storage.get('foo.fastify.io'), true) + t.assert.equal(storage.get('bar.fastify.io'), true) }) -t.test('exact host matches take precendence over regexp matches', async (t) => { +test('exact host matches take precendence over regexp matches', async (t) => { const storage = acceptHostStrategy.storage() storage.set(/.+fastify\.io/, 'wildcard') storage.set('auth.fastify.io', 'exact') - t.equal(storage.get('foo.fastify.io'), 'wildcard') - t.equal(storage.get('bar.fastify.io'), 'wildcard') - t.equal(storage.get('auth.fastify.io'), 'exact') + t.assert.equal(storage.get('foo.fastify.io'), 'wildcard') + t.assert.equal(storage.get('bar.fastify.io'), 'wildcard') + t.assert.equal(storage.get('auth.fastify.io'), 'exact') }) diff --git a/test/http2/constraint.host.test.js b/test/http2/constraint.host.test.js index 3a97df83..788ae8de 100644 --- a/test/http2/constraint.host.test.js +++ b/test/http2/constraint.host.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../..') test('A route supports host constraints under http2 protocol', t => { @@ -10,13 +9,13 @@ test('A route supports host constraints under http2 protocol', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/', {}, (req, res) => { - t.fail() + t.assert.assert.fail() }) findMyWay.on('GET', '/', { constraints: { host: 'fastify.io' } }, (req, res) => { - t.equal(req.headers[':authority'], 'fastify.io') + t.assert.equal(req.headers[':authority'], 'fastify.io') }) findMyWay.on('GET', '/', { constraints: { host: /.+\.de/ } }, (req, res) => { - t.ok(req.headers[':authority'].endsWith('.de')) + t.assert.ok(req.headers[':authority'].endsWith('.de')) }) findMyWay.lookup({ diff --git a/test/issue-101.test.js b/test/issue-101.test.js index e156ecfe..8c1b46af 100644 --- a/test/issue-101.test.js +++ b/test/issue-101.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Falling back for node\'s parametric brother', t => { @@ -15,17 +14,17 @@ test('Falling back for node\'s parametric brother', t => { findMyWay.on('GET', '/:namespace/:type/:id', () => {}) findMyWay.on('GET', '/:namespace/jobs/:name/run', () => {}) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test_namespace/test_type/test_id').params, { namespace: 'test_namespace', type: 'test_type', id: 'test_id' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test_namespace/jobss/test_id').params, { namespace: 'test_namespace', type: 'jobss', id: 'test_id' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test_namespace/jobs/test_id').params, { namespace: 'test_namespace', type: 'jobs', id: 'test_id' } ) diff --git a/test/issue-104.test.js b/test/issue-104.test.js index 4c3b1133..c4bf9f57 100644 --- a/test/issue-104.test.js +++ b/test/issue-104.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Nested static parametric route, url with parameter common prefix > 1', t => { @@ -28,7 +27,7 @@ test('Nested static parametric route, url with parameter common prefix > 1', t = res.end('{"message":"hello world"}') }) - t.same(findMyWay.find('DELETE', '/a/bbar').params, { id: 'bbar' }) + t.assert.deepEqual(findMyWay.find('DELETE', '/a/bbar').params, { id: 'bbar' }) }) test('Parametric route, url with parameter common prefix > 1', t => { @@ -55,7 +54,7 @@ test('Parametric route, url with parameter common prefix > 1', t => { res.end('{"message":"hello world"}') }) - t.same(findMyWay.find('GET', '/aab').params, { id: 'aab' }) + t.assert.deepEqual(findMyWay.find('GET', '/aab').params, { id: 'aab' }) }) test('Parametric route, url with multi parameter common prefix > 1', t => { @@ -82,7 +81,7 @@ test('Parametric route, url with multi parameter common prefix > 1', t => { res.end('{"message":"hello world"}') }) - t.same(findMyWay.find('GET', '/hello/aab').params, { a: 'hello', b: 'aab' }) + t.assert.deepEqual(findMyWay.find('GET', '/hello/aab').params, { a: 'hello', b: 'aab' }) }) test('Mixed routes, url with parameter common prefix > 1', t => { @@ -133,17 +132,17 @@ test('Mixed routes, url with parameter common prefix > 1', t => { res.end('{"winter":"is here"}') }) - t.same(findMyWay.find('GET', '/test').params, {}) - t.same(findMyWay.find('GET', '/testify').params, {}) - t.same(findMyWay.find('GET', '/test/hello').params, {}) - t.same(findMyWay.find('GET', '/test/hello/test').params, {}) - t.same(findMyWay.find('GET', '/te/hello').params, { a: 'hello' }) - t.same(findMyWay.find('GET', '/te/').params, { a: '' }) - t.same(findMyWay.find('GET', '/testy').params, { c: 'testy' }) - t.same(findMyWay.find('GET', '/besty').params, { c: 'besty' }) - t.same(findMyWay.find('GET', '/text/hellos/test').params, { e: 'hellos' }) - t.same(findMyWay.find('GET', '/te/hello/'), null) - t.same(findMyWay.find('GET', '/te/hellos/testy'), null) + t.assert.deepEqual(findMyWay.find('GET', '/test').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/testify').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/test/hello').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/test/hello/test').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/te/hello').params, { a: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/te/').params, { a: '' }) + t.assert.deepEqual(findMyWay.find('GET', '/testy').params, { c: 'testy' }) + t.assert.deepEqual(findMyWay.find('GET', '/besty').params, { c: 'besty' }) + t.assert.deepEqual(findMyWay.find('GET', '/text/hellos/test').params, { e: 'hellos' }) + t.assert.deepEqual(findMyWay.find('GET', '/te/hello/'), null) + t.assert.deepEqual(findMyWay.find('GET', '/te/hellos/testy'), null) }) test('Parent parametric brother should not rewrite child node parametric brother', t => { @@ -166,7 +165,7 @@ test('Parent parametric brother should not rewrite child node parametric brother res.end('{"hello":"world"}') }) - t.same(findMyWay.find('GET', '/text/hellos/test').params, { e: 'hellos' }) + t.assert.deepEqual(findMyWay.find('GET', '/text/hellos/test').params, { e: 'hellos' }) }) test('Mixed parametric routes, with last defined route being static', t => { @@ -200,8 +199,8 @@ test('Mixed parametric routes, with last defined route being static', t => { res.end('{"hello":"world"}') }) - t.same(findMyWay.find('GET', '/test/hello').params, { a: 'hello' }) - t.same(findMyWay.find('GET', '/test/hello/world/test').params, { c: 'world' }) - t.same(findMyWay.find('GET', '/test/hello/world/te').params, { c: 'world', k: 'te' }) - t.same(findMyWay.find('GET', '/test/hello/world/testy').params, { c: 'world', k: 'testy' }) + t.assert.deepEqual(findMyWay.find('GET', '/test/hello').params, { a: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/test/hello/world/test').params, { c: 'world' }) + t.assert.deepEqual(findMyWay.find('GET', '/test/hello/world/te').params, { c: 'world', k: 'te' }) + t.assert.deepEqual(findMyWay.find('GET', '/test/hello/world/testy').params, { c: 'world', k: 'testy' }) }) diff --git a/test/issue-110.test.js b/test/issue-110.test.js index 373a7bc9..b7481379 100644 --- a/test/issue-110.test.js +++ b/test/issue-110.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Nested static parametric route, url with parameter common prefix > 1', t => { @@ -28,5 +27,5 @@ test('Nested static parametric route, url with parameter common prefix > 1', t = res.end('{"message":"hello world"}') }) - t.same(findMyWay.find('GET', '/api/foo/b-123/bar').params, { id: 'b-123' }) + t.assert.deepEqual(findMyWay.find('GET', '/api/foo/b-123/bar').params, { id: 'b-123' }) }) diff --git a/test/issue-132.test.js b/test/issue-132.test.js index d24e264d..c6bda442 100644 --- a/test/issue-132.test.js +++ b/test/issue-132.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Wildcard mixed with dynamic and common prefix / 1', t => { @@ -13,19 +12,19 @@ test('Wildcard mixed with dynamic and common prefix / 1', t => { }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.on('GET', '/obj/params/*', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.on('GET', '/obj/:id', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.on('GET', '/obj_params/*', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.lookup({ method: 'OPTIONS', url: '/obj/params', headers: {} }, null) @@ -48,23 +47,23 @@ test('Wildcard mixed with dynamic and common prefix / 2', t => { }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.on('OPTIONS', '/obj/*', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.on('GET', '/obj/params/*', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.on('GET', '/obj/:id', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.on('GET', '/obj_params/*', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.lookup({ method: 'OPTIONS', url: '/obj_params/params', headers: {} }, null) diff --git a/test/issue-145.test.js b/test/issue-145.test.js index 96f865ca..90778a87 100644 --- a/test/issue-145.test.js +++ b/test/issue-145.test.js @@ -1,9 +1,9 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const FindMyWay = require('../') -t.test('issue-145', (t) => { +test('issue-145', (t) => { t.plan(8) const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) @@ -13,12 +13,12 @@ t.test('issue-145', (t) => { findMyWay.on('GET', '/a/b', fixedPath) findMyWay.on('GET', '/a/:pam/c', varPath) - t.equal(findMyWay.find('GET', '/a/b').handler, fixedPath) - t.equal(findMyWay.find('GET', '/a/b/').handler, fixedPath) - t.equal(findMyWay.find('GET', '/a/b/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a/b/c/').handler, varPath) - t.equal(findMyWay.find('GET', '/a/foo/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a/foo/c/').handler, varPath) - t.notOk(findMyWay.find('GET', '/a/c')) - t.notOk(findMyWay.find('GET', '/a/c/')) + t.assert.equal(findMyWay.find('GET', '/a/b').handler, fixedPath) + t.assert.equal(findMyWay.find('GET', '/a/b/').handler, fixedPath) + t.assert.equal(findMyWay.find('GET', '/a/b/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a/b/c/').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a/foo/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a/foo/c/').handler, varPath) + t.assert.ok(!findMyWay.find('GET', '/a/c')) + t.assert.ok(!findMyWay.find('GET', '/a/c/')) }) diff --git a/test/issue-149.test.js b/test/issue-149.test.js index e5764ecd..3feaf2dc 100644 --- a/test/issue-149.test.js +++ b/test/issue-149.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Falling back for node\'s parametric brother', t => { @@ -16,7 +15,7 @@ test('Falling back for node\'s parametric brother', t => { findMyWay.on('GET', '/foo/:color/:id', () => {}) findMyWay.on('GET', '/foo/red', () => {}) - t.same(findMyWay.find('GET', '/foo/red/123').params, { color: 'red', id: '123' }) - t.same(findMyWay.find('GET', '/foo/blue/123').params, { color: 'blue', id: '123' }) - t.same(findMyWay.find('GET', '/foo/red').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/foo/red/123').params, { color: 'red', id: '123' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo/blue/123').params, { color: 'blue', id: '123' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo/red').params, {}) }) diff --git a/test/issue-151.test.js b/test/issue-151.test.js index 121550ab..2a508b5c 100644 --- a/test/issue-151.test.js +++ b/test/issue-151.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Wildcard route should not be blocked by Parametric with different method / 1', t => { @@ -17,7 +16,7 @@ test('Wildcard route should not be blocked by Parametric with different method / }) findMyWay.on('OPTIONS', '/obj/*', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.on('GET', '/obj/:id', (req, res, params) => { @@ -40,7 +39,7 @@ test('Wildcard route should not be blocked by Parametric with different method / }) findMyWay.on('OPTIONS', '/obj/*', { version: '1.2.3' }, (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.on('GET', '/obj/:id', { version: '1.2.3' }, (req, res, params) => { diff --git a/test/issue-154.test.js b/test/issue-154.test.js index 62bc1bbf..a586cec6 100644 --- a/test/issue-154.test.js +++ b/test/issue-154.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const noop = () => {} diff --git a/test/issue-161.test.js b/test/issue-161.test.js index adcf090a..0b6d662d 100644 --- a/test/issue-161.test.js +++ b/test/issue-161.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Falling back for node\'s parametric brother without ignoreTrailingSlash', t => { @@ -17,10 +16,10 @@ test('Falling back for node\'s parametric brother without ignoreTrailingSlash', findMyWay.on('GET', '/static/param2', () => {}) findMyWay.on('GET', '/static/:paramA/next', () => {}) - t.same(findMyWay.find('GET', '/static/param1').params, {}) - t.same(findMyWay.find('GET', '/static/param2').params, {}) - t.same(findMyWay.find('GET', '/static/paramOther/next').params, { paramA: 'paramOther' }) - t.same(findMyWay.find('GET', '/static/param1/next').params, { paramA: 'param1' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/param2').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/paramOther/next').params, { paramA: 'paramOther' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next').params, { paramA: 'param1' }) }) test('Falling back for node\'s parametric brother with ignoreTrailingSlash', t => { @@ -36,10 +35,10 @@ test('Falling back for node\'s parametric brother with ignoreTrailingSlash', t = findMyWay.on('GET', '/static/param2', () => {}) findMyWay.on('GET', '/static/:paramA/next', () => {}) - t.same(findMyWay.find('GET', '/static/param1').params, {}) - t.same(findMyWay.find('GET', '/static/param2').params, {}) - t.same(findMyWay.find('GET', '/static/paramOther/next').params, { paramA: 'paramOther' }) - t.same(findMyWay.find('GET', '/static/param1/next').params, { paramA: 'param1' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/param2').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/paramOther/next').params, { paramA: 'paramOther' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next').params, { paramA: 'param1' }) }) test('Falling back for node\'s parametric brother without ignoreTrailingSlash', t => { @@ -59,10 +58,10 @@ test('Falling back for node\'s parametric brother without ignoreTrailingSlash', findMyWay.on('GET', '/static/param1/next/param4', () => {}) findMyWay.on('GET', '/static/:paramA/next/:paramB/other', () => {}) - t.same(findMyWay.find('GET', '/static/param1/next/param3').params, {}) - t.same(findMyWay.find('GET', '/static/param1/next/param4').params, {}) - t.same(findMyWay.find('GET', '/static/paramOther/next/paramOther2/other').params, { paramA: 'paramOther', paramB: 'paramOther2' }) - t.same(findMyWay.find('GET', '/static/param1/next/param3/other').params, { paramA: 'param1', paramB: 'param3' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next/param3').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next/param4').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/paramOther/next/paramOther2/other').params, { paramA: 'paramOther', paramB: 'paramOther2' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next/param3/other').params, { paramA: 'param1', paramB: 'param3' }) }) test('Falling back for node\'s parametric brother with ignoreTrailingSlash', t => { @@ -82,8 +81,8 @@ test('Falling back for node\'s parametric brother with ignoreTrailingSlash', t = findMyWay.on('GET', '/static/param1/next/param4', () => {}) findMyWay.on('GET', '/static/:paramA/next/:paramB/other', () => {}) - t.same(findMyWay.find('GET', '/static/param1/next/param3').params, {}) - t.same(findMyWay.find('GET', '/static/param1/next/param4').params, {}) - t.same(findMyWay.find('GET', '/static/paramOther/next/paramOther2/other').params, { paramA: 'paramOther', paramB: 'paramOther2' }) - t.same(findMyWay.find('GET', '/static/param1/next/param3/other').params, { paramA: 'param1', paramB: 'param3' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next/param3').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next/param4').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/static/paramOther/next/paramOther2/other').params, { paramA: 'paramOther', paramB: 'paramOther2' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/param1/next/param3/other').params, { paramA: 'param1', paramB: 'param3' }) }) diff --git a/test/issue-17.test.js b/test/issue-17.test.js index 55fc64e2..20a7ccbf 100644 --- a/test/issue-17.test.js +++ b/test/issue-17.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Parametric route, request.url contains dash', t => { @@ -13,7 +12,7 @@ test('Parametric route, request.url contains dash', t => { }) findMyWay.on('GET', '/a/:param/b', (req, res, params) => { - t.equal(params.param, 'foo-bar') + t.assert.equal(params.param, 'foo-bar') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b', headers: {} }, null) @@ -28,21 +27,21 @@ test('Parametric route with fixed suffix', t => { findMyWay.on('GET', '/a/:param-static', () => {}) findMyWay.on('GET', '/b/:param.static', () => {}) - t.same(findMyWay.find('GET', '/a/param-static', {}).params, { param: 'param' }) - t.same(findMyWay.find('GET', '/b/param.static', {}).params, { param: 'param' }) + t.assert.deepEqual(findMyWay.find('GET', '/a/param-static', {}).params, { param: 'param' }) + t.assert.deepEqual(findMyWay.find('GET', '/b/param.static', {}).params, { param: 'param' }) - t.same(findMyWay.find('GET', '/a/param-param-static', {}).params, { param: 'param-param' }) - t.same(findMyWay.find('GET', '/b/param.param.static', {}).params, { param: 'param.param' }) + t.assert.deepEqual(findMyWay.find('GET', '/a/param-param-static', {}).params, { param: 'param-param' }) + t.assert.deepEqual(findMyWay.find('GET', '/b/param.param.static', {}).params, { param: 'param.param' }) - t.same(findMyWay.find('GET', '/a/param.param-static', {}).params, { param: 'param.param' }) - t.same(findMyWay.find('GET', '/b/param-param.static', {}).params, { param: 'param-param' }) + t.assert.deepEqual(findMyWay.find('GET', '/a/param.param-static', {}).params, { param: 'param.param' }) + t.assert.deepEqual(findMyWay.find('GET', '/b/param-param.static', {}).params, { param: 'param-param' }) }) test('Regex param exceeds max parameter length', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) @@ -57,7 +56,7 @@ test('Parametric route with regexp and fixed suffix / 1', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) @@ -80,7 +79,7 @@ test('Parametric route with regexp and fixed suffix / 2', t => { }) findMyWay.on('GET', '/a/:param(^\\w{3})bar', (req, res, params) => { - t.equal(params.param, 'foo') + t.assert.equal(params.param, 'foo') }) findMyWay.lookup({ method: 'GET', url: '/a/foobar', headers: {} }, null) @@ -95,7 +94,7 @@ test('Parametric route with regexp and fixed suffix / 3', t => { }) findMyWay.on('GET', '/a/:param(^\\w{3}-\\w{3})foo', (req, res, params) => { - t.equal(params.param, 'abc-def') + t.assert.equal(params.param, 'abc-def') }) findMyWay.lookup({ method: 'GET', url: '/a/abc-deffoo', headers: {} }, null) @@ -110,13 +109,13 @@ test('Multi parametric route / 1', t => { }) findMyWay.on('GET', '/a/:p1-:p2', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') }) findMyWay.on('GET', '/b/:p1.:p2', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) @@ -132,13 +131,13 @@ test('Multi parametric route / 2', t => { }) findMyWay.on('GET', '/a/:p1-:p2', (req, res, params) => { - t.equal(params.p1, 'foo-bar') - t.equal(params.p2, 'baz') + t.assert.equal(params.p1, 'foo-bar') + t.assert.equal(params.p2, 'baz') }) findMyWay.on('GET', '/b/:p1.:p2', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar-baz') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar-baz') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz', headers: {} }, null) @@ -154,13 +153,13 @@ test('Multi parametric route / 3', t => { }) findMyWay.on('GET', '/a/:p_1-:$p', (req, res, params) => { - t.equal(params.p_1, 'foo') - t.equal(params.$p, 'bar') + t.assert.equal(params.p_1, 'foo') + t.assert.equal(params.$p, 'bar') }) findMyWay.on('GET', '/b/:p_1.:$p', (req, res, params) => { - t.equal(params.p_1, 'foo') - t.equal(params.$p, 'bar') + t.assert.equal(params.p_1, 'foo') + t.assert.equal(params.$p, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-bar', headers: {} }, null) @@ -171,7 +170,7 @@ test('Multi parametric route / 4', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) @@ -196,8 +195,8 @@ test('Multi parametric route with regexp / 1', t => { }) findMyWay.on('GET', '/at/:hour(^\\d+)h:minute(^\\d+)m', (req, res, params) => { - t.equal(params.hour, '0') - t.equal(params.minute, '42') + t.assert.equal(params.hour, '0') + t.assert.equal(params.minute, '42') }) findMyWay.lookup({ method: 'GET', url: '/at/0h42m', headers: {} }, null) @@ -212,12 +211,12 @@ test('Multi parametric route with colon separator', t => { }) findMyWay.on('GET', '/:param(.*)::suffix', (req, res, params) => { - t.equal(params.param, 'foo') + t.assert.equal(params.param, 'foo') }) findMyWay.on('GET', '/:param1(.*)::suffix1-:param2(.*)::suffix2/static', (req, res, params) => { - t.equal(params.param1, 'foo') - t.equal(params.param2, 'bar') + t.assert.equal(params.param1, 'foo') + t.assert.equal(params.param2, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/foo:suffix', headers: {} }, null) @@ -233,23 +232,23 @@ test('Multi parametric route with regexp / 2', t => { }) findMyWay.on('GET', '/a/:uuid(^[\\d-]{19})-:user(^\\w+)', (req, res, params) => { - t.equal(params.uuid, '1111-2222-3333-4444') - t.equal(params.user, 'foo') + t.assert.equal(params.uuid, '1111-2222-3333-4444') + t.assert.equal(params.user, 'foo') }) findMyWay.on('GET', '/a/:uuid(^[\\d-]{19})-:user(^\\w+)/account', (req, res, params) => { - t.equal(params.uuid, '1111-2222-3333-4445') - t.equal(params.user, 'bar') + t.assert.equal(params.uuid, '1111-2222-3333-4445') + t.assert.equal(params.user, 'bar') }) findMyWay.on('GET', '/b/:uuid(^[\\d-]{19}).:user(^\\w+)', (req, res, params) => { - t.equal(params.uuid, '1111-2222-3333-4444') - t.equal(params.user, 'foo') + t.assert.equal(params.uuid, '1111-2222-3333-4444') + t.assert.equal(params.user, 'foo') }) findMyWay.on('GET', '/b/:uuid(^[\\d-]{19}).:user(^\\w+)/account', (req, res, params) => { - t.equal(params.uuid, '1111-2222-3333-4445') - t.equal(params.user, 'bar') + t.assert.equal(params.uuid, '1111-2222-3333-4445') + t.assert.equal(params.user, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/a/1111-2222-3333-4444-foo', headers: {} }, null) @@ -268,13 +267,13 @@ test('Multi parametric route with fixed suffix', t => { }) findMyWay.on('GET', '/a/:p1-:p2-baz', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') }) findMyWay.on('GET', '/b/:p1.:p2-baz', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-bar-baz', headers: {} }, null) @@ -290,13 +289,13 @@ test('Multi parametric route with regexp and fixed suffix', t => { }) findMyWay.on('GET', '/a/:p1(^\\w+)-:p2(^\\w+)-kuux', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'barbaz') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'barbaz') }) findMyWay.on('GET', '/b/:p1(^\\w+).:p2(^\\w+)-kuux', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'barbaz') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'barbaz') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-barbaz-kuux', headers: {} }, null) @@ -312,13 +311,13 @@ test('Multi parametric route with wildcard', t => { }) findMyWay.on('GET', '/a/:p1-:p2/*', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') }) findMyWay.on('GET', '/b/:p1.:p2/*', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/baz', headers: {} }, null) @@ -334,15 +333,15 @@ test('Nested multi parametric route', t => { }) findMyWay.on('GET', '/a/:p1-:p2/b/:p3', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') - t.equal(params.p3, 'baz') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') + t.assert.equal(params.p3, 'baz') }) findMyWay.on('GET', '/b/:p1.:p2/b/:p3', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, 'bar') - t.equal(params.p3, 'baz') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, 'bar') + t.assert.equal(params.p3, 'baz') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-bar/b/baz', headers: {} }, null) @@ -358,15 +357,15 @@ test('Nested multi parametric route with regexp / 1', t => { }) findMyWay.on('GET', '/a/:p1(^\\w{3})-:p2(^\\d+)/b/:p3', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, '42') - t.equal(params.p3, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, '42') + t.assert.equal(params.p3, 'bar') }) findMyWay.on('GET', '/b/:p1(^\\w{3}).:p2(^\\d+)/b/:p3', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, '42') - t.equal(params.p3, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, '42') + t.assert.equal(params.p3, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar', headers: {} }, null) @@ -382,15 +381,15 @@ test('Nested multi parametric route with regexp / 2', t => { }) findMyWay.on('GET', '/a/:p1(^\\w{3})-:p2/b/:p3', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, '42') - t.equal(params.p3, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, '42') + t.assert.equal(params.p3, 'bar') }) findMyWay.on('GET', '/b/:p1(^\\w{3}).:p2/b/:p3', (req, res, params) => { - t.equal(params.p1, 'foo') - t.equal(params.p2, '42') - t.equal(params.p3, 'bar') + t.assert.equal(params.p1, 'foo') + t.assert.equal(params.p2, '42') + t.assert.equal(params.p3, 'bar') }) findMyWay.lookup({ method: 'GET', url: '/a/foo-42/b/bar', headers: {} }, null) diff --git a/test/issue-175.test.js b/test/issue-175.test.js index 129b1a50..98d9048c 100644 --- a/test/issue-175.test.js +++ b/test/issue-175.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('double colon is replaced with single colon, no parameters', t => { @@ -11,7 +10,7 @@ test('double colon is replaced with single colon, no parameters', t => { }) function handler (req, res, params) { - t.same(params, {}) + t.assert.deepEqual(params, {}) } findMyWay.on('GET', '/name::customVerb', handler) @@ -26,8 +25,8 @@ test('exactly one match for static route with colon', t => { function handler () {} findMyWay.on('GET', '/name::customVerb', handler) - t.equal(findMyWay.find('GET', '/name:customVerb').handler, handler) - t.equal(findMyWay.find('GET', '/name:test'), null) + t.assert.equal(findMyWay.find('GET', '/name:customVerb').handler, handler) + t.assert.equal(findMyWay.find('GET', '/name:test'), null) }) test('double colon is replaced with single colon, no parameters, same parent node name', t => { @@ -41,7 +40,7 @@ test('double colon is replaced with single colon, no parameters, same parent nod }) findMyWay.on('GET', '/name::customVerb', (req, res, params) => { - t.same(params, {}) + t.assert.deepEqual(params, {}) }) findMyWay.lookup({ method: 'GET', url: '/name:customVerb', headers: {} }, null) @@ -50,7 +49,7 @@ test('double colon is replaced with single colon, no parameters, same parent nod test('double colon is replaced with single colon, default route, same parent node name', t => { t.plan(1) const findMyWay = FindMyWay({ - defaultRoute: () => t.ok('should be default route') + defaultRoute: () => t.assert.ok('should be default route') }) findMyWay.on('GET', '/name', () => { @@ -71,7 +70,7 @@ test('double colon is replaced with single colon, with parameters', t => { }) findMyWay.on('GET', '/name1::customVerb1/:param1/name2::customVerb2:param2', (req, res, params) => { - t.same(params, { + t.assert.deepEqual(params, { param1: 'value1', param2: 'value2' }) diff --git a/test/issue-182.test.js b/test/issue-182.test.js index 869f9e74..af4c5703 100644 --- a/test/issue-182.test.js +++ b/test/issue-182.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('Set method property when splitting node', t => { @@ -9,7 +8,7 @@ test('Set method property when splitting node', t => { const findMyWay = FindMyWay() function handler (req, res, params) { - t.pass() + t.assert.ok() } findMyWay.on('GET', '/health-a/health', handler) diff --git a/test/issue-190.test.js b/test/issue-190.test.js index 25199b29..610e8cc0 100644 --- a/test/issue-190.test.js +++ b/test/issue-190.test.js @@ -1,9 +1,9 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const FindMyWay = require('../') -t.test('issue-190', (t) => { +test('issue-190', (t) => { t.plan(6) const findMyWay = FindMyWay() @@ -18,10 +18,10 @@ t.test('issue-190', (t) => { findMyWay.on('GET', '/api/users/:id', paramPath) findMyWay.on('GET', '/api/:resourceType/foo', extraPath) - t.equal(findMyWay.find('GET', '/api/users/admins').handler, staticPath) - t.equal(findMyWay.find('GET', '/api/users/award_winners').handler, staticPath) - t.equal(findMyWay.find('GET', '/api/users/a766c023-34ec-40d2-923c-e8259a28d2c5').handler, paramPath) - t.equal(findMyWay.find('GET', '/api/users/b766c023-34ec-40d2-923c-e8259a28d2c5').handler, paramPath) + t.assert.equal(findMyWay.find('GET', '/api/users/admins').handler, staticPath) + t.assert.equal(findMyWay.find('GET', '/api/users/award_winners').handler, staticPath) + t.assert.equal(findMyWay.find('GET', '/api/users/a766c023-34ec-40d2-923c-e8259a28d2c5').handler, paramPath) + t.assert.equal(findMyWay.find('GET', '/api/users/b766c023-34ec-40d2-923c-e8259a28d2c5').handler, paramPath) findMyWay.lookup({ method: 'GET', @@ -39,6 +39,6 @@ t.test('issue-190', (t) => { headers: { } }) - t.equal(staticCounter, 2) - t.equal(paramCounter, 1) + t.assert.equal(staticCounter, 2) + t.assert.equal(paramCounter, 1) }) diff --git a/test/issue-20.test.js b/test/issue-20.test.js index cc5be53f..ab9eb032 100644 --- a/test/issue-20.test.js +++ b/test/issue-20.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Standard case', t => { @@ -13,7 +12,7 @@ test('Standard case', t => { }) findMyWay.on('GET', '/a/:param', (req, res, params) => { - t.equal(params.param, 'perfectly-fine-route') + t.assert.equal(params.param, 'perfectly-fine-route') }) findMyWay.lookup({ method: 'GET', url: '/a/perfectly-fine-route', headers: {} }, null) @@ -23,7 +22,7 @@ test('Should be 404 / 1', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) @@ -38,7 +37,7 @@ test('Should be 404 / 2', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) @@ -53,7 +52,7 @@ test('Should be 404 / 3', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) @@ -73,7 +72,7 @@ test('Should get an empty parameter', t => { }) findMyWay.on('GET', '/a/:param', (req, res, params) => { - t.equal(params.param, '') + t.assert.equal(params.param, '') }) findMyWay.lookup({ method: 'GET', url: '/a/', headers: {} }, null) diff --git a/test/issue-206.test.js b/test/issue-206.test.js index 5d245751..6946bfad 100644 --- a/test/issue-206.test.js +++ b/test/issue-206.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('Decode the URL before the routing', t => { @@ -17,14 +16,14 @@ test('Decode the URL before the routing', t => { findMyWay.on('GET', '/[...]/a%20.html', percentTwenty) findMyWay.on('GET', '/[...]/a%2520.html', percentTwentyfive) - t.equal(findMyWay.find('GET', '/[...]/a .html').handler, space) - t.equal(findMyWay.find('GET', '/%5B...%5D/a .html').handler, space) - t.equal(findMyWay.find('GET', '/[...]/a%20.html').handler, space, 'a%20 decode is a ') - t.equal(findMyWay.find('GET', '/%5B...%5D/a%20.html').handler, space, 'a%20 decode is a ') - t.equal(findMyWay.find('GET', '/[...]/a%2520.html').handler, percentTwenty, 'a%2520 decode is a%20') - t.equal(findMyWay.find('GET', '/%5B...%5D/a%252520.html').handler, percentTwentyfive, 'a%252520.html is a%2520') - t.equal(findMyWay.find('GET', '/[...]/a .html'), null, 'double space') - t.equal(findMyWay.find('GET', '/static/%25E0%A4%A'), null, 'invalid encoded path param') + t.assert.equal(findMyWay.find('GET', '/[...]/a .html').handler, space) + t.assert.equal(findMyWay.find('GET', '/%5B...%5D/a .html').handler, space) + t.assert.equal(findMyWay.find('GET', '/[...]/a%20.html').handler, space, 'a%20 decode is a ') + t.assert.equal(findMyWay.find('GET', '/%5B...%5D/a%20.html').handler, space, 'a%20 decode is a ') + t.assert.equal(findMyWay.find('GET', '/[...]/a%2520.html').handler, percentTwenty, 'a%2520 decode is a%20') + t.assert.equal(findMyWay.find('GET', '/%5B...%5D/a%252520.html').handler, percentTwentyfive, 'a%252520.html is a%2520') + t.assert.equal(findMyWay.find('GET', '/[...]/a .html'), null, 'double space') + t.assert.equal(findMyWay.find('GET', '/static/%25E0%A4%A'), null, 'invalid encoded path param') }) test('double encoding', t => { @@ -32,16 +31,16 @@ test('double encoding', t => { const findMyWay = FindMyWay() function pathParam (req, res, params) { - t.same(params, this.expect, 'path param') - t.same(pathParam, this.handler, 'match handler') + t.assert.deepEqual(params, this.expect, 'path param') + t.assert.deepEqual(pathParam, this.handler, 'match handler') } function regexPathParam (req, res, params) { - t.same(params, this.expect, 'regex param') - t.same(regexPathParam, this.handler, 'match handler') + t.assert.deepEqual(params, this.expect, 'regex param') + t.assert.deepEqual(regexPathParam, this.handler, 'match handler') } function wildcard (req, res, params) { - t.same(params, this.expect, 'wildcard param') - t.same(wildcard, this.handler, 'match handler') + t.assert.deepEqual(params, this.expect, 'wildcard param') + t.assert.deepEqual(wildcard, this.handler, 'match handler') } findMyWay.on('GET', '/:pathParam', pathParam) @@ -74,16 +73,16 @@ test('Special chars on path parameter', t => { const findMyWay = FindMyWay() function pathParam (req, res, params) { - t.same(params, this.expect, 'path param') - t.same(pathParam, this.handler, 'match handler') + t.assert.deepEqual(params, this.expect, 'path param') + t.assert.deepEqual(pathParam, this.handler, 'match handler') } function regexPathParam (req, res, params) { - t.same(params, this.expect, 'regex param') - t.same(regexPathParam, this.handler, 'match handler') + t.assert.deepEqual(params, this.expect, 'regex param') + t.assert.deepEqual(regexPathParam, this.handler, 'match handler') } function staticEncoded (req, res, params) { - t.same(params, this.expect, 'static match') - t.same(staticEncoded, this.handler, 'match handler') + t.assert.deepEqual(params, this.expect, 'static match') + t.assert.deepEqual(staticEncoded, this.handler, 'match handler') } findMyWay.on('GET', '/:pathParam', pathParam) @@ -106,7 +105,7 @@ test('Multi parametric route with encoded colon separator', t => { }) findMyWay.on('GET', '/:param(.*)::suffix', (req, res, params) => { - t.equal(params.param, 'foo-bar') + t.assert.equal(params.param, 'foo-bar') }) findMyWay.lookup({ method: 'GET', url: '/foo-bar%3Asuffix', headers: {} }, null) diff --git a/test/issue-221.test.js b/test/issue-221.test.js index e28d08de..c992afce 100644 --- a/test/issue-221.test.js +++ b/test/issue-221.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('Should return correct param after switching from static route', t => { @@ -11,7 +10,7 @@ test('Should return correct param after switching from static route', t => { findMyWay.on('GET', '/prefix-:id', () => {}) findMyWay.on('GET', '/prefix-111', () => {}) - t.same(findMyWay.find('GET', '/prefix-1111').params, { id: '1111' }) + t.assert.deepEqual(findMyWay.find('GET', '/prefix-1111').params, { id: '1111' }) }) test('Should return correct param after switching from static route', t => { @@ -21,7 +20,7 @@ test('Should return correct param after switching from static route', t => { findMyWay.on('GET', '/prefix-111', () => {}) findMyWay.on('GET', '/prefix-:id/hello', () => {}) - t.same(findMyWay.find('GET', '/prefix-1111/hello').params, { id: '1111' }) + t.assert.deepEqual(findMyWay.find('GET', '/prefix-1111/hello').params, { id: '1111' }) }) test('Should return correct param after switching from parametric route', t => { @@ -32,7 +31,7 @@ test('Should return correct param after switching from parametric route', t => { findMyWay.on('GET', '/prefix-:id/hello', () => {}) findMyWay.on('GET', '/:id', () => {}) - t.same(findMyWay.find('GET', '/prefix-1111-hello').params, { id: 'prefix-1111-hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/prefix-1111-hello').params, { id: 'prefix-1111-hello' }) }) test('Should return correct params after switching from parametric route', t => { @@ -43,7 +42,7 @@ test('Should return correct params after switching from parametric route', t => findMyWay.on('GET', '/test/:param1/test/:param2/prefix-:id/hello', () => {}) findMyWay.on('GET', '/test/:param1/test/:param2/:id', () => {}) - t.same(findMyWay.find('GET', '/test/value1/test/value2/prefix-1111-hello').params, { + t.assert.deepEqual(findMyWay.find('GET', '/test/value1/test/value2/prefix-1111-hello').params, { param1: 'value1', param2: 'value2', id: 'prefix-1111-hello' diff --git a/test/issue-234.test.js b/test/issue-234.test.js index 29cafbc2..fae2bf70 100644 --- a/test/issue-234.test.js +++ b/test/issue-234.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('Match static url without encoding option', t => { @@ -13,8 +12,8 @@ test('Match static url without encoding option', t => { findMyWay.on('GET', '/🍌', handler) - t.same(findMyWay.find('GET', '/🍌').handler, handler) - t.same(findMyWay.find('GET', '/%F0%9F%8D%8C').handler, handler) + t.assert.deepEqual(findMyWay.find('GET', '/🍌').handler, handler) + t.assert.deepEqual(findMyWay.find('GET', '/%F0%9F%8D%8C').handler, handler) }) test('Match parametric url with encoding option', t => { @@ -24,8 +23,8 @@ test('Match parametric url with encoding option', t => { findMyWay.on('GET', '/🍌/:param', () => {}) - t.same(findMyWay.find('GET', '/🍌/@').params, { param: '@' }) - t.same(findMyWay.find('GET', '/%F0%9F%8D%8C/@').params, { param: '@' }) + t.assert.deepEqual(findMyWay.find('GET', '/🍌/@').params, { param: '@' }) + t.assert.deepEqual(findMyWay.find('GET', '/%F0%9F%8D%8C/@').params, { param: '@' }) }) test('Match encoded parametric url with encoding option', t => { @@ -35,8 +34,8 @@ test('Match encoded parametric url with encoding option', t => { findMyWay.on('GET', '/🍌/:param', () => {}) - t.same(findMyWay.find('GET', '/🍌/%23').params, { param: '#' }) - t.same(findMyWay.find('GET', '/%F0%9F%8D%8C/%23').params, { param: '#' }) + t.assert.deepEqual(findMyWay.find('GET', '/🍌/%23').params, { param: '#' }) + t.assert.deepEqual(findMyWay.find('GET', '/%F0%9F%8D%8C/%23').params, { param: '#' }) }) test('Decode url components', t => { @@ -46,9 +45,9 @@ test('Decode url components', t => { findMyWay.on('GET', '/:param1/:param2', () => {}) - t.same(findMyWay.find('GET', '/foo%23bar/foo%23bar').params, { param1: 'foo#bar', param2: 'foo#bar' }) - t.same(findMyWay.find('GET', '/%F0%9F%8D%8C/%F0%9F%8D%8C').params, { param1: '🍌', param2: '🍌' }) - t.same(findMyWay.find('GET', '/%F0%9F%8D%8C/foo%23bar').params, { param1: '🍌', param2: 'foo#bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%23bar/foo%23bar').params, { param1: 'foo#bar', param2: 'foo#bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/%F0%9F%8D%8C/%F0%9F%8D%8C').params, { param1: '🍌', param2: '🍌' }) + t.assert.deepEqual(findMyWay.find('GET', '/%F0%9F%8D%8C/foo%23bar').params, { param1: '🍌', param2: 'foo#bar' }) }) test('Decode url components', t => { @@ -59,11 +58,11 @@ test('Decode url components', t => { findMyWay.on('GET', '/foo🍌bar/:param1/:param2', () => {}) findMyWay.on('GET', '/user/:id', () => {}) - t.same(findMyWay.find('GET', '/foo%F0%9F%8D%8Cbar/foo%23bar/foo%23bar').params, { param1: 'foo#bar', param2: 'foo#bar' }) - t.same(findMyWay.find('GET', '/user/maintainer+tomas').params, { id: 'maintainer+tomas' }) - t.same(findMyWay.find('GET', '/user/maintainer%2Btomas').params, { id: 'maintainer+tomas' }) - t.same(findMyWay.find('GET', '/user/maintainer%20tomas').params, { id: 'maintainer tomas' }) - t.same(findMyWay.find('GET', '/user/maintainer%252Btomas').params, { id: 'maintainer%2Btomas' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%F0%9F%8D%8Cbar/foo%23bar/foo%23bar').params, { param1: 'foo#bar', param2: 'foo#bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/user/maintainer+tomas').params, { id: 'maintainer+tomas' }) + t.assert.deepEqual(findMyWay.find('GET', '/user/maintainer%2Btomas').params, { id: 'maintainer+tomas' }) + t.assert.deepEqual(findMyWay.find('GET', '/user/maintainer%20tomas').params, { id: 'maintainer tomas' }) + t.assert.deepEqual(findMyWay.find('GET', '/user/maintainer%252Btomas').params, { id: 'maintainer%2Btomas' }) }) test('Decode url components', t => { @@ -72,24 +71,24 @@ test('Decode url components', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/:param1', () => {}) - t.same(findMyWay.find('GET', '/foo%23bar').params, { param1: 'foo#bar' }) - t.same(findMyWay.find('GET', '/foo%24bar').params, { param1: 'foo$bar' }) - t.same(findMyWay.find('GET', '/foo%26bar').params, { param1: 'foo&bar' }) - t.same(findMyWay.find('GET', '/foo%2bbar').params, { param1: 'foo+bar' }) - t.same(findMyWay.find('GET', '/foo%2Bbar').params, { param1: 'foo+bar' }) - t.same(findMyWay.find('GET', '/foo%2cbar').params, { param1: 'foo,bar' }) - t.same(findMyWay.find('GET', '/foo%2Cbar').params, { param1: 'foo,bar' }) - t.same(findMyWay.find('GET', '/foo%2fbar').params, { param1: 'foo/bar' }) - t.same(findMyWay.find('GET', '/foo%2Fbar').params, { param1: 'foo/bar' }) - - t.same(findMyWay.find('GET', '/foo%3abar').params, { param1: 'foo:bar' }) - t.same(findMyWay.find('GET', '/foo%3Abar').params, { param1: 'foo:bar' }) - t.same(findMyWay.find('GET', '/foo%3bbar').params, { param1: 'foo;bar' }) - t.same(findMyWay.find('GET', '/foo%3Bbar').params, { param1: 'foo;bar' }) - t.same(findMyWay.find('GET', '/foo%3dbar').params, { param1: 'foo=bar' }) - t.same(findMyWay.find('GET', '/foo%3Dbar').params, { param1: 'foo=bar' }) - t.same(findMyWay.find('GET', '/foo%3fbar').params, { param1: 'foo?bar' }) - t.same(findMyWay.find('GET', '/foo%3Fbar').params, { param1: 'foo?bar' }) - - t.same(findMyWay.find('GET', '/foo%40bar').params, { param1: 'foo@bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%23bar').params, { param1: 'foo#bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%24bar').params, { param1: 'foo$bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%26bar').params, { param1: 'foo&bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%2bbar').params, { param1: 'foo+bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%2Bbar').params, { param1: 'foo+bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%2cbar').params, { param1: 'foo,bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%2Cbar').params, { param1: 'foo,bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%2fbar').params, { param1: 'foo/bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%2Fbar').params, { param1: 'foo/bar' }) + + t.assert.deepEqual(findMyWay.find('GET', '/foo%3abar').params, { param1: 'foo:bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%3Abar').params, { param1: 'foo:bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%3bbar').params, { param1: 'foo;bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%3Bbar').params, { param1: 'foo;bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%3dbar').params, { param1: 'foo=bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%3Dbar').params, { param1: 'foo=bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%3fbar').params, { param1: 'foo?bar' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo%3Fbar').params, { param1: 'foo?bar' }) + + t.assert.deepEqual(findMyWay.find('GET', '/foo%40bar').params, { param1: 'foo@bar' }) }) diff --git a/test/issue-238.test.js b/test/issue-238.test.js index 5885f90d..58e53978 100644 --- a/test/issue-238.test.js +++ b/test/issue-238.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Multi-parametric tricky path', t => { @@ -12,27 +11,27 @@ test('Multi-parametric tricky path', t => { findMyWay.on('GET', '/:param1-static-:param2', () => {}) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/param1-static-param2', {}).params, { param1: 'param1', param2: 'param2' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/param1.1-param1.2-static-param2.1-param2.2', {}).params, { param1: 'param1.1-param1.2', param2: 'param2.1-param2.2' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/param1-1-param1-2-static-param2-1-param2-2', {}).params, { param1: 'param1-1-param1-2', param2: 'param2-1-param2-2' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/static-static-static', {}).params, { param1: 'static', param2: 'static' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/static-static-static-static', {}).params, { param1: 'static', param2: 'static-static' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/static-static1-static-static', {}).params, { param1: 'static-static1', param2: 'static' } ) @@ -50,11 +49,11 @@ test('Multi-parametric nodes with different static ending 1', t => { findMyWay.on('GET', '/v1/foo/:code', paramHandler) findMyWay.on('GET', '/v1/foo/:code.png', multiParamHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello', {}).handler, paramHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello', {}).handler, paramHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello', {}).params, { code: 'hello' }) - t.same(findMyWay.find('GET', '/v1/foo/hello.png', {}).handler, multiParamHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.png', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png', {}).handler, multiParamHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png', {}).params, { code: 'hello' }) }) test('Multi-parametric nodes with different static ending 2', t => { @@ -69,11 +68,11 @@ test('Multi-parametric nodes with different static ending 2', t => { findMyWay.on('GET', '/v1/foo/:code.jpg', jpgHandler) findMyWay.on('GET', '/v1/foo/:code.png', pngHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.jpg', {}).handler, jpgHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.jpg', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.jpg', {}).handler, jpgHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.jpg', {}).params, { code: 'hello' }) - t.same(findMyWay.find('GET', '/v1/foo/hello.png', {}).handler, pngHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.png', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png', {}).handler, pngHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png', {}).params, { code: 'hello' }) }) test('Multi-parametric nodes with different static ending 3', t => { @@ -88,11 +87,11 @@ test('Multi-parametric nodes with different static ending 3', t => { findMyWay.on('GET', '/v1/foo/:code.jpg/bar', jpgHandler) findMyWay.on('GET', '/v1/foo/:code.png/bar', pngHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).handler, jpgHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).handler, jpgHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).params, { code: 'hello' }) - t.same(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).handler, pngHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).handler, pngHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).params, { code: 'hello' }) }) test('Multi-parametric nodes with different static ending 4', t => { @@ -109,12 +108,12 @@ test('Multi-parametric nodes with different static ending 4', t => { findMyWay.on('GET', '/v1/foo/:code.jpg/bar', jpgHandler) findMyWay.on('GET', '/v1/foo/:code.png/bar', pngHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello/bar', {}).handler, handler) - t.same(findMyWay.find('GET', '/v1/foo/hello/bar', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello/bar', {}).handler, handler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello/bar', {}).params, { code: 'hello' }) - t.same(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).handler, jpgHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).handler, jpgHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.jpg/bar', {}).params, { code: 'hello' }) - t.same(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).handler, pngHandler) - t.same(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).params, { code: 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).handler, pngHandler) + t.assert.deepEqual(findMyWay.find('GET', '/v1/foo/hello.png/bar', {}).params, { code: 'hello' }) }) diff --git a/test/issue-240.test.js b/test/issue-240.test.js index be68fc61..ada2579d 100644 --- a/test/issue-240.test.js +++ b/test/issue-240.test.js @@ -1,9 +1,9 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const FindMyWay = require('../') -t.test('issue-240: .find matching', (t) => { +test('issue-240: .find matching', (t) => { t.plan(14) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true }) @@ -13,18 +13,18 @@ t.test('issue-240: .find matching', (t) => { findMyWay.on('GET', '/a/b', fixedPath) findMyWay.on('GET', '/a/:pam/c', varPath) - t.equal(findMyWay.find('GET', '/a/b').handler, fixedPath) - t.equal(findMyWay.find('GET', '/a//b').handler, fixedPath) - t.equal(findMyWay.find('GET', '/a/b/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a//b/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a///b/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a//b//c').handler, varPath) - t.equal(findMyWay.find('GET', '/a///b///c').handler, varPath) - t.equal(findMyWay.find('GET', '/a/foo/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a//foo/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a///foo/c').handler, varPath) - t.equal(findMyWay.find('GET', '/a//foo//c').handler, varPath) - t.equal(findMyWay.find('GET', '/a///foo///c').handler, varPath) - t.notOk(findMyWay.find('GET', '/a/c')) - t.notOk(findMyWay.find('GET', '/a//c')) + t.assert.equal(findMyWay.find('GET', '/a/b').handler, fixedPath) + t.assert.equal(findMyWay.find('GET', '/a//b').handler, fixedPath) + t.assert.equal(findMyWay.find('GET', '/a/b/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a//b/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a///b/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a//b//c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a///b///c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a/foo/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a//foo/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a///foo/c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a//foo//c').handler, varPath) + t.assert.equal(findMyWay.find('GET', '/a///foo///c').handler, varPath) + t.assert.ok(!findMyWay.find('GET', '/a/c')) + t.assert.ok(!findMyWay.find('GET', '/a//c')) }) diff --git a/test/issue-241.test.js b/test/issue-241.test.js index 2d45becf..0b781594 100644 --- a/test/issue-241.test.js +++ b/test/issue-241.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('Double colon and parametric children', t => { @@ -11,8 +10,8 @@ test('Double colon and parametric children', t => { findMyWay.on('GET', '/::articles', () => {}) findMyWay.on('GET', '/:article_name', () => {}) - t.same(findMyWay.find('GET', '/:articles').params, {}) - t.same(findMyWay.find('GET', '/articles_param').params, { article_name: 'articles_param' }) + t.assert.deepEqual(findMyWay.find('GET', '/:articles').params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/articles_param').params, { article_name: 'articles_param' }) }) test('Double colon and parametric children', t => { @@ -22,11 +21,11 @@ test('Double colon and parametric children', t => { findMyWay.on('GET', '/::test::foo/:param/::articles', () => {}) findMyWay.on('GET', '/::test::foo/:param/:article_name', () => {}) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/:test:foo/param_value1/:articles').params, { param: 'param_value1' } ) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/:test:foo/param_value2/articles_param').params, { param: 'param_value2', article_name: 'articles_param' } ) diff --git a/test/issue-247.test.js b/test/issue-247.test.js index 3b23a9e8..6ed89efd 100644 --- a/test/issue-247.test.js +++ b/test/issue-247.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('If there are constraints param, router.off method support filter', t => { @@ -12,27 +11,27 @@ test('If there are constraints param, router.off method support filter', t => { findMyWay.on('GET', '/a', { constraints: { host: '2', version: '1.0.0' } }, () => {}, { name: 2 }) findMyWay.on('GET', '/a', { constraints: { host: '2', version: '2.0.0' } }, () => {}, { name: 3 }) - t.same(findMyWay.find('GET', '/a', { host: '1' }).store, { name: 1 }) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }).store, { name: 2 }) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '1' }).store, { name: 1 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }).store, { name: 2 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 }) findMyWay.off('GET', '/a', { host: '1' }) - t.same(findMyWay.find('GET', '/a', { host: '1' }), null) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }).store, { name: 2 }) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '1' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }).store, { name: 2 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 }) findMyWay.off('GET', '/a', { host: '2', version: '1.0.0' }) - t.same(findMyWay.find('GET', '/a', { host: '1' }), null) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }), null) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '1' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }).store, { name: 3 }) findMyWay.off('GET', '/a', { host: '2', version: '2.0.0' }) - t.same(findMyWay.find('GET', '/a', { host: '1' }), null) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }), null) - t.same(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '1' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '1.0.0' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2', version: '2.0.0' }), null) }) test('If there are no constraints param, router.off method remove all matched router', t => { @@ -42,11 +41,11 @@ test('If there are no constraints param, router.off method remove all matched ro findMyWay.on('GET', '/a', { constraints: { host: '1' } }, () => {}, { name: 1 }) findMyWay.on('GET', '/a', { constraints: { host: '2' } }, () => {}, { name: 2 }) - t.same(findMyWay.find('GET', '/a', { host: '1' }).store, { name: 1 }) - t.same(findMyWay.find('GET', '/a', { host: '2' }).store, { name: 2 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '1' }).store, { name: 1 }) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2' }).store, { name: 2 }) findMyWay.off('GET', '/a') - t.same(findMyWay.find('GET', '/a', { host: '1' }), null) - t.same(findMyWay.find('GET', '/a', { host: '2' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '1' }), null) + t.assert.deepEqual(findMyWay.find('GET', '/a', { host: '2' }), null) }) diff --git a/test/issue-254.test.js b/test/issue-254.test.js index 6937936b..090217db 100644 --- a/test/issue-254.test.js +++ b/test/issue-254.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('Constraints should not be overrided when multiple router is created', t => { @@ -28,5 +27,5 @@ test('Constraints should not be overrided when multiple router is created', t => router1.on('GET', '/', { constraints: { secret: 'alpha' } }, () => {}) router1.find('GET', '/', { secret: 'alpha' }) - t.pass('constraints is not overrided') + t.assert.ok('constraints is not overrided') }) diff --git a/test/issue-28.test.js b/test/issue-28.test.js index c25d3efa..49982c34 100644 --- a/test/issue-28.test.js +++ b/test/issue-28.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('wildcard (more complex test)', t => { @@ -15,13 +14,13 @@ test('wildcard (more complex test)', t => { findMyWay.on('GET', '/test/*', (req, res, params) => { switch (params['*']) { case 'hello': - t.ok('correct parameter') + t.assert.ok('correct parameter') break case 'hello/world': - t.ok('correct parameter') + t.assert.ok('correct parameter') break case '': - t.ok('correct parameter') + t.assert.ok('correct parameter') break default: t.fail('wrong parameter: ' + params['*']) @@ -53,11 +52,11 @@ test('Wildcard inside a node with a static route but different method', t => { }) findMyWay.on('GET', '/test/hello', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.lookup( @@ -76,7 +75,7 @@ test('Wildcard inside a node with a static route but different method (more comp const findMyWay = FindMyWay({ defaultRoute: (req, res) => { if (req.url === '/test/helloo' && req.method === 'GET') { - t.ok('Everything fine') + t.assert.ok('Everything fine') } else { t.fail('we should not be here, the url is: ' + req.url) } @@ -84,11 +83,11 @@ test('Wildcard inside a node with a static route but different method (more comp }) findMyWay.on('GET', '/test/hello', (req, res, params) => { - t.equal(req.method, 'GET') + t.assert.equal(req.method, 'GET') }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.lookup( @@ -134,7 +133,7 @@ test('Wildcard edge cases', t => { }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.equal(params['*'], 'test1/foo') + t.assert.equal(params['*'], 'test1/foo') }) findMyWay.lookup( @@ -152,7 +151,7 @@ test('Wildcard edge cases same method', t => { }) findMyWay.on('OPTIONS', '/test1/foo', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.on('OPTIONS', '/test2/foo', (req, res, params) => { @@ -160,7 +159,7 @@ test('Wildcard edge cases same method', t => { }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.equal(params['*'], 'test/foo') + t.assert.equal(params['*'], 'test/foo') }) findMyWay.lookup( @@ -183,7 +182,7 @@ test('Wildcard and parametric edge cases', t => { }) findMyWay.on('OPTIONS', '/test1/foo', (req, res, params) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) findMyWay.on('OPTIONS', '/test2/foo', (req, res, params) => { @@ -191,11 +190,11 @@ test('Wildcard and parametric edge cases', t => { }) findMyWay.on('GET', '/:test/foo', (req, res, params) => { - t.equal(params.test, 'example') + t.assert.equal(params.test, 'example') }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.equal(params['*'], 'test/foo/hey') + t.assert.equal(params['*'], 'test/foo/hey') }) findMyWay.lookup( @@ -235,7 +234,7 @@ test('Mixed wildcard and static with same method', t => { }) findMyWay.on('GET', '*', (req, res, params) => { - t.equal(params['*'], '/foo1/bar1/kuux') + t.assert.equal(params['*'], '/foo1/bar1/kuux') }) findMyWay.lookup( @@ -257,7 +256,7 @@ test('Nested wildcards case - 1', t => { }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.equal(params['*'], 'bar1/kuux') + t.assert.equal(params['*'], 'bar1/kuux') }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { @@ -283,7 +282,7 @@ test('Nested wildcards case - 2', t => { }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.equal(params['*'], 'bar1/kuux') + t.assert.equal(params['*'], 'bar1/kuux') }) findMyWay.on('GET', '*', (req, res, params) => { @@ -309,7 +308,7 @@ test('Nested wildcards with parametric and static - 1', t => { }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.equal(params['*'], 'bar1/kuux') + t.assert.equal(params['*'], 'bar1/kuux') }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { @@ -351,7 +350,7 @@ test('Nested wildcards with parametric and static - 2', t => { }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.equal(params.param, 'bar1') + t.assert.equal(params.param, 'bar1') }) findMyWay.on('GET', '/foo4/param', (req, res, params) => { @@ -389,7 +388,7 @@ test('Nested wildcards with parametric and static - 3', t => { }) findMyWay.on('GET', '/foo4/param', (req, res, params) => { - t.equal(req.url, '/foo4/param') + t.assert.equal(req.url, '/foo4/param') }) findMyWay.lookup( @@ -423,7 +422,7 @@ test('Nested wildcards with parametric and static - 4', t => { }) findMyWay.on('GET', '/foo1/param', (req, res, params) => { - t.equal(req.url, '/foo1/param') + t.assert.equal(req.url, '/foo1/param') }) findMyWay.lookup( @@ -445,7 +444,7 @@ test('Nested wildcards with parametric and static - 5', t => { }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.equal(params['*'], 'param/hello/test/long/routee') + t.assert.equal(params['*'], 'param/hello/test/long/routee') }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { @@ -475,7 +474,7 @@ test('Nested wildcards with parametric and static - 6', t => { }) findMyWay.on('GET', '*', (req, res, params) => { - t.equal(params['*'], '/foo4/param/hello/test/long/routee') + t.assert.equal(params['*'], '/foo4/param/hello/test/long/routee') }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { @@ -521,7 +520,7 @@ test('Nested wildcards with parametric and static - 7', t => { }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.equal(params.param, 'hello') + t.assert.equal(params.param, 'hello') }) findMyWay.on('GET', '/foo3/*', (req, res, params) => { @@ -563,7 +562,7 @@ test('Nested wildcards with parametric and static - 8', t => { }) findMyWay.on('GET', '/foo3/*', (req, res, params) => { - t.equal(params['*'], 'hello/world') + t.assert.equal(params['*'], 'hello/world') }) findMyWay.on('GET', '/foo4/param/hello/test/long/route', (req, res, params) => { @@ -585,7 +584,7 @@ test('Wildcard node with constraints', t => { }) findMyWay.on('GET', '*', { constraints: { host: 'fastify.io' } }, (req, res, params) => { - t.equal(params['*'], '/foo1/foo3') + t.assert.equal(params['*'], '/foo1/foo3') }) findMyWay.on('GET', '/foo1/*', { constraints: { host: 'something-else.io' } }, (req, res, params) => { diff --git a/test/issue-280.test.js b/test/issue-280.test.js index b1b2ec1d..23fdba3e 100644 --- a/test/issue-280.test.js +++ b/test/issue-280.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Wildcard route match when regexp route fails', (t) => { @@ -11,5 +10,5 @@ test('Wildcard route match when regexp route fails', (t) => { findMyWay.on('GET', '/:a(a)', () => {}) findMyWay.on('GET', '/*', () => {}) - t.same(findMyWay.find('GET', '/b', {}).params, { '*': 'b' }) + t.assert.deepEqual(findMyWay.find('GET', '/b', {}).params, { '*': 'b' }) }) diff --git a/test/issue-285.test.js b/test/issue-285.test.js index bdfa93d9..3c756b4b 100644 --- a/test/issue-285.test.js +++ b/test/issue-285.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Parametric regex match with similar routes', (t) => { @@ -11,8 +10,8 @@ test('Parametric regex match with similar routes', (t) => { findMyWay.on('GET', '/:a(a)', () => {}) findMyWay.on('GET', '/:param/static', () => {}) - t.same(findMyWay.find('GET', '/a', {}).params, { a: 'a' }) - t.same(findMyWay.find('GET', '/param/static', {}).params, { param: 'param' }) + t.assert.deepEqual(findMyWay.find('GET', '/a', {}).params, { a: 'a' }) + t.assert.deepEqual(findMyWay.find('GET', '/param/static', {}).params, { param: 'param' }) }) test('Parametric regex match with similar routes', (t) => { @@ -22,8 +21,8 @@ test('Parametric regex match with similar routes', (t) => { findMyWay.on('GET', '/:a(a)', () => {}) findMyWay.on('GET', '/:b(b)/static', () => {}) - t.same(findMyWay.find('GET', '/a', {}).params, { a: 'a' }) - t.same(findMyWay.find('GET', '/b/static', {}).params, { b: 'b' }) + t.assert.deepEqual(findMyWay.find('GET', '/a', {}).params, { a: 'a' }) + t.assert.deepEqual(findMyWay.find('GET', '/b/static', {}).params, { b: 'b' }) }) test('Parametric regex match with similar routes', (t) => { @@ -33,6 +32,6 @@ test('Parametric regex match with similar routes', (t) => { findMyWay.on('GET', '/:a(a)/static', { constraints: { version: '1.0.0' } }, () => {}) findMyWay.on('GET', '/:b(b)/static', { constraints: { version: '2.0.0' } }, () => {}) - t.same(findMyWay.find('GET', '/a/static', { version: '1.0.0' }).params, { a: 'a' }) - t.same(findMyWay.find('GET', '/b/static', { version: '2.0.0' }).params, { b: 'b' }) + t.assert.deepEqual(findMyWay.find('GET', '/a/static', { version: '1.0.0' }).params, { a: 'a' }) + t.assert.deepEqual(findMyWay.find('GET', '/b/static', { version: '2.0.0' }).params, { b: 'b' }) }) diff --git a/test/issue-330.test.js b/test/issue-330.test.js index 14906e13..5dc8cbf1 100644 --- a/test/issue-330.test.js +++ b/test/issue-330.test.js @@ -1,5 +1,4 @@ -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') const proxyquire = require('proxyquire') const HandlerStorage = require('../lib/handler-storage') @@ -58,9 +57,9 @@ test('case insensitive static routes', (t) => { findMyWay.on('GET', '/foo/bar', () => {}) findMyWay.on('GET', '/foo/bar/baz', () => {}) - t.ok(findMyWay.findRoute('GET', '/FoO')) - t.ok(findMyWay.findRoute('GET', '/FOo/Bar')) - t.ok(findMyWay.findRoute('GET', '/fOo/Bar/bAZ')) + t.assert.ok(findMyWay.findRoute('GET', '/FoO')) + t.assert.ok(findMyWay.findRoute('GET', '/FOo/Bar')) + t.assert.ok(findMyWay.findRoute('GET', '/fOo/Bar/bAZ')) }) test('wildcard must be the last character in the route', (t) => { @@ -84,8 +83,8 @@ test('does not find the route if maxParamLength is exceeded', t => { findMyWay.on('GET', '/:id(\\d+)', () => {}) - t.equal(findMyWay.find('GET', '/123'), null) - t.ok(findMyWay.find('GET', '/12')) + t.assert.equal(findMyWay.find('GET', '/123'), null) + t.assert.ok(findMyWay.find('GET', '/12')) }) test('Should check if a regex is safe to use', (t) => { @@ -134,13 +133,13 @@ test('Constrainer.noteUsage', (t) => { t.plan(3) const constrainer = new Constrainer() - t.equal(constrainer.strategiesInUse.size, 0) + t.assert.equal(constrainer.strategiesInUse.size, 0) constrainer.noteUsage() - t.equal(constrainer.strategiesInUse.size, 0) + t.assert.equal(constrainer.strategiesInUse.size, 0) constrainer.noteUsage({ host: 'fastify.io' }) - t.equal(constrainer.strategiesInUse.size, 1) + t.assert.equal(constrainer.strategiesInUse.size, 1) }) test('Cannot derive constraints without active strategies.', (t) => { @@ -149,20 +148,20 @@ test('Cannot derive constraints without active strategies.', (t) => { const constrainer = new Constrainer() const before = constrainer.deriveSyncConstraints constrainer._buildDeriveConstraints() - t.same(constrainer.deriveSyncConstraints, before) + t.assert.deepEqual(constrainer.deriveSyncConstraints, before) }) test('getMatchingHandler should return null if not compiled', (t) => { t.plan(1) const handlerStorage = new HandlerStorage() - t.equal(handlerStorage.getMatchingHandler({ foo: 'bar' }), null) + t.assert.equal(handlerStorage.getMatchingHandler({ foo: 'bar' }), null) }) test('safeDecodeURIComponent should replace %3x to null for every x that is not a valid lowchar', (t) => { t.plan(1) - t.equal(safeDecodeURIComponent('Hello%3xWorld'), 'HellonullWorld') + t.assert.equal(safeDecodeURIComponent('Hello%3xWorld'), 'HellonullWorld') }) test('SemVerStore version should be a string', (t) => { @@ -179,13 +178,13 @@ test('SemVerStore.maxMajor should increase automatically', (t) => { const Storage = acceptVersionStrategy.storage const storage = new Storage() - t.equal(storage.maxMajor, 0) + t.assert.equal(storage.maxMajor, 0) storage.set('2') - t.equal(storage.maxMajor, 2) + t.assert.equal(storage.maxMajor, 2) storage.set('1') - t.equal(storage.maxMajor, 2) + t.assert.equal(storage.maxMajor, 2) }) test('SemVerStore.maxPatches should increase automatically', (t) => { @@ -195,13 +194,13 @@ test('SemVerStore.maxPatches should increase automatically', (t) => { const storage = new Storage() storage.set('2.0.0') - t.same(storage.maxPatches, { '2.0': 0 }) + t.assert.deepEqual(storage.maxPatches, { '2.0': 0 }) storage.set('2.0.2') - t.same(storage.maxPatches, { '2.0': 2 }) + t.assert.deepEqual(storage.maxPatches, { '2.0': 2 }) storage.set('2.0.1') - t.same(storage.maxPatches, { '2.0': 2 }) + t.assert.deepEqual(storage.maxPatches, { '2.0': 2 }) }) test('Major version must be a numeric value', t => { @@ -218,7 +217,7 @@ test('httpMethodStrategy storage handles set and get operations correctly', (t) const storage = httpMethodStrategy.storage() - t.equal(storage.get('foo'), null) + t.assert.equal(storage.get('foo'), null) storage.set('foo', { bar: 'baz' }) t.strictSame(storage.get('foo'), { bar: 'baz' }) @@ -228,5 +227,5 @@ test('if buildPrettyMeta argument is undefined, will return an object', (t) => { t.plan(1) const findMyWay = FindMyWay() - t.same(findMyWay.buildPrettyMeta(), {}) + t.assert.deepEqual(findMyWay.buildPrettyMeta(), {}) }) diff --git a/test/issue-44.test.js b/test/issue-44.test.js index 36e70e99..6d13e530 100644 --- a/test/issue-44.test.js +++ b/test/issue-44.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Parametric and static with shared prefix / 1', t => { @@ -17,7 +16,7 @@ test('Parametric and static with shared prefix / 1', t => { }) findMyWay.on('GET', '/:param', (req, res, params) => { - t.equal(params.param, 'winter') + t.assert.equal(params.param, 'winter') }) findMyWay.lookup({ method: 'GET', url: '/winter', headers: {} }, null) @@ -32,7 +31,7 @@ test('Parametric and static with shared prefix / 2', t => { }) findMyWay.on('GET', '/woo', (req, res, params) => { - t.ok('we should be here') + t.assert.ok('we should be here') }) findMyWay.on('GET', '/:param', (req, res, params) => { @@ -46,7 +45,7 @@ test('Parametric and static with shared prefix (nested)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.ok('We should be here') + t.assert.ok('We should be here') } }) @@ -74,7 +73,7 @@ test('Parametric and static with shared prefix and different suffix', t => { }) findMyWay.on('GET', '/example/:param/nested/other', (req, res, params) => { - t.ok('We should be here') + t.assert.ok('We should be here') }) findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/other', headers: {} }, null) @@ -93,7 +92,7 @@ test('Parametric and static with shared prefix (with wildcard)', t => { }) findMyWay.on('GET', '/:param', (req, res, params) => { - t.equal(params.param, 'winter') + t.assert.equal(params.param, 'winter') }) findMyWay.on('GET', '/*', (req, res, params) => { @@ -120,7 +119,7 @@ test('Parametric and static with shared prefix (nested with wildcard)', t => { }) findMyWay.on('GET', '/*', (req, res, params) => { - t.equal(params['*'], 'winter/coming') + t.assert.equal(params['*'], 'winter/coming') }) findMyWay.lookup({ method: 'GET', url: '/winter/coming', headers: {} }, null) @@ -139,7 +138,7 @@ test('Parametric and static with shared prefix (nested with split)', t => { }) findMyWay.on('GET', '/:param', (req, res, params) => { - t.equal(params.param, 'winter') + t.assert.equal(params.param, 'winter') }) findMyWay.on('GET', '/wo', (req, res, params) => { diff --git a/test/issue-46.test.js b/test/issue-46.test.js index 963c8407..9b4f7fb3 100644 --- a/test/issue-46.test.js +++ b/test/issue-46.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('If the prefixLen is higher than the pathLen we should not save the wildcard child', t => { @@ -14,9 +13,9 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar findMyWay.get('/static/*', () => {}) - t.same(findMyWay.find('GET', '/static/').params, { '*': '' }) - t.same(findMyWay.find('GET', '/static/hello').params, { '*': 'hello' }) - t.same(findMyWay.find('GET', '/static'), null) + t.assert.deepEqual(findMyWay.find('GET', '/static/').params, { '*': '' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/hello').params, { '*': 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/static'), null) }) test('If the prefixLen is higher than the pathLen we should not save the wildcard child (mixed routes)', t => { @@ -32,9 +31,9 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar findMyWay.get('/simple/:bar', () => {}) findMyWay.get('/hello', () => {}) - t.same(findMyWay.find('GET', '/static/').params, { '*': '' }) - t.same(findMyWay.find('GET', '/static/hello').params, { '*': 'hello' }) - t.same(findMyWay.find('GET', '/static'), null) + t.assert.deepEqual(findMyWay.find('GET', '/static/').params, { '*': '' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/hello').params, { '*': 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/static'), null) }) test('If the prefixLen is higher than the pathLen we should not save the wildcard child (with a root wildcard)', t => { @@ -51,9 +50,9 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar findMyWay.get('/simple/:bar', () => {}) findMyWay.get('/hello', () => {}) - t.same(findMyWay.find('GET', '/static/').params, { '*': '' }) - t.same(findMyWay.find('GET', '/static/hello').params, { '*': 'hello' }) - t.same(findMyWay.find('GET', '/static').params, { '*': '/static' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/').params, { '*': '' }) + t.assert.deepEqual(findMyWay.find('GET', '/static/hello').params, { '*': 'hello' }) + t.assert.deepEqual(findMyWay.find('GET', '/static').params, { '*': '/static' }) }) test('If the prefixLen is higher than the pathLen we should not save the wildcard child (404)', t => { @@ -69,8 +68,8 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar findMyWay.get('/simple/:bar', () => {}) findMyWay.get('/hello', () => {}) - t.same(findMyWay.find('GET', '/stati'), null) - t.same(findMyWay.find('GET', '/staticc'), null) - t.same(findMyWay.find('GET', '/stati/hello'), null) - t.same(findMyWay.find('GET', '/staticc/hello'), null) + t.assert.deepEqual(findMyWay.find('GET', '/stati'), null) + t.assert.deepEqual(findMyWay.find('GET', '/staticc'), null) + t.assert.deepEqual(findMyWay.find('GET', '/stati/hello'), null) + t.assert.deepEqual(findMyWay.find('GET', '/staticc/hello'), null) }) diff --git a/test/issue-49.test.js b/test/issue-49.test.js index 698b331b..4719c360 100644 --- a/test/issue-49.test.js +++ b/test/issue-49.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') const noop = () => {} @@ -12,9 +11,9 @@ test('Defining static route after parametric - 1', t => { findMyWay.on('GET', '/static', noop) findMyWay.on('GET', '/:param', noop) - t.ok(findMyWay.find('GET', '/static')) - t.ok(findMyWay.find('GET', '/para')) - t.ok(findMyWay.find('GET', '/s')) + t.assert.ok(findMyWay.find('GET', '/static')) + t.assert.ok(findMyWay.find('GET', '/para')) + t.assert.ok(findMyWay.find('GET', '/s')) }) test('Defining static route after parametric - 2', t => { @@ -24,9 +23,9 @@ test('Defining static route after parametric - 2', t => { findMyWay.on('GET', '/:param', noop) findMyWay.on('GET', '/static', noop) - t.ok(findMyWay.find('GET', '/static')) - t.ok(findMyWay.find('GET', '/para')) - t.ok(findMyWay.find('GET', '/s')) + t.assert.ok(findMyWay.find('GET', '/static')) + t.assert.ok(findMyWay.find('GET', '/para')) + t.assert.ok(findMyWay.find('GET', '/s')) }) test('Defining static route after parametric - 3', t => { @@ -37,10 +36,10 @@ test('Defining static route after parametric - 3', t => { findMyWay.on('GET', '/static', noop) findMyWay.on('GET', '/other', noop) - t.ok(findMyWay.find('GET', '/static')) - t.ok(findMyWay.find('GET', '/para')) - t.ok(findMyWay.find('GET', '/s')) - t.ok(findMyWay.find('GET', '/o')) + t.assert.ok(findMyWay.find('GET', '/static')) + t.assert.ok(findMyWay.find('GET', '/para')) + t.assert.ok(findMyWay.find('GET', '/s')) + t.assert.ok(findMyWay.find('GET', '/o')) }) test('Defining static route after parametric - 4', t => { @@ -51,10 +50,10 @@ test('Defining static route after parametric - 4', t => { findMyWay.on('GET', '/other', noop) findMyWay.on('GET', '/:param', noop) - t.ok(findMyWay.find('GET', '/static')) - t.ok(findMyWay.find('GET', '/para')) - t.ok(findMyWay.find('GET', '/s')) - t.ok(findMyWay.find('GET', '/o')) + t.assert.ok(findMyWay.find('GET', '/static')) + t.assert.ok(findMyWay.find('GET', '/para')) + t.assert.ok(findMyWay.find('GET', '/s')) + t.assert.ok(findMyWay.find('GET', '/o')) }) test('Defining static route after parametric - 5', t => { @@ -65,10 +64,10 @@ test('Defining static route after parametric - 5', t => { findMyWay.on('GET', '/:param', noop) findMyWay.on('GET', '/other', noop) - t.ok(findMyWay.find('GET', '/static')) - t.ok(findMyWay.find('GET', '/para')) - t.ok(findMyWay.find('GET', '/s')) - t.ok(findMyWay.find('GET', '/o')) + t.assert.ok(findMyWay.find('GET', '/static')) + t.assert.ok(findMyWay.find('GET', '/para')) + t.assert.ok(findMyWay.find('GET', '/s')) + t.assert.ok(findMyWay.find('GET', '/o')) }) test('Should produce the same tree - 1', t => { @@ -82,7 +81,7 @@ test('Should produce the same tree - 1', t => { findMyWay2.on('GET', '/:param', noop) findMyWay2.on('GET', '/static', noop) - t.equal(findMyWay1.tree, findMyWay2.tree) + t.assert.equal(findMyWay1.tree, findMyWay2.tree) }) test('Should produce the same tree - 2', t => { @@ -103,7 +102,7 @@ test('Should produce the same tree - 2', t => { findMyWay3.on('GET', '/other', noop) findMyWay3.on('GET', '/:param', noop) - t.equal(findMyWay1.tree, findMyWay2.tree) - t.equal(findMyWay2.tree, findMyWay3.tree) - t.equal(findMyWay1.tree, findMyWay3.tree) + t.assert.equal(findMyWay1.tree, findMyWay2.tree) + t.assert.equal(findMyWay2.tree, findMyWay3.tree) + t.assert.equal(findMyWay1.tree, findMyWay3.tree) }) diff --git a/test/issue-59.test.js b/test/issue-59.test.js index 36ad29b1..66b68047 100644 --- a/test/issue-59.test.js +++ b/test/issue-59.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') const noop = () => {} @@ -12,7 +11,7 @@ test('single-character prefix', t => { findMyWay.on('GET', '/b/', noop) findMyWay.on('GET', '/b/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('multi-character prefix', t => { @@ -22,7 +21,7 @@ test('multi-character prefix', t => { findMyWay.on('GET', '/bu/', noop) findMyWay.on('GET', '/bu/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('static / 1', t => { @@ -32,7 +31,7 @@ test('static / 1', t => { findMyWay.on('GET', '/bb/', noop) findMyWay.on('GET', '/bb/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('static / 2', t => { @@ -42,8 +41,8 @@ test('static / 2', t => { findMyWay.on('GET', '/bb/ff/', noop) findMyWay.on('GET', '/bb/ff/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) - t.equal(findMyWay.find('GET', '/ff/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/ff/bulk'), null) }) test('static / 3', t => { @@ -55,7 +54,7 @@ test('static / 3', t => { findMyWay.on('GET', '/bb/ff/gg/bulk', noop) findMyWay.on('GET', '/bb/ff/bulk/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('with parameter / 1', t => { @@ -65,7 +64,7 @@ test('with parameter / 1', t => { findMyWay.on('GET', '/:foo/', noop) findMyWay.on('GET', '/:foo/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('with parameter / 2', t => { @@ -75,7 +74,7 @@ test('with parameter / 2', t => { findMyWay.on('GET', '/bb/', noop) findMyWay.on('GET', '/bb/:foo', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('with parameter / 3', t => { @@ -85,7 +84,7 @@ test('with parameter / 3', t => { findMyWay.on('GET', '/bb/ff/', noop) findMyWay.on('GET', '/bb/ff/:foo', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('with parameter / 4', t => { @@ -95,7 +94,7 @@ test('with parameter / 4', t => { findMyWay.on('GET', '/bb/:foo/', noop) findMyWay.on('GET', '/bb/:foo/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('with parameter / 5', t => { @@ -105,8 +104,8 @@ test('with parameter / 5', t => { findMyWay.on('GET', '/bb/:foo/aa/', noop) findMyWay.on('GET', '/bb/:foo/aa/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) - t.equal(findMyWay.find('GET', '/bb/foo/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bb/foo/bulk'), null) }) test('with parameter / 6', t => { @@ -116,8 +115,8 @@ test('with parameter / 6', t => { findMyWay.on('GET', '/static/:parametric/static/:parametric', noop) findMyWay.on('GET', '/static/:parametric/static/:parametric/bulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) - t.equal(findMyWay.find('GET', '/static/foo/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/static/foo/bulk'), null) t.not(findMyWay.find('GET', '/static/foo/static/bulk'), null) }) @@ -128,5 +127,5 @@ test('wildcard / 1', t => { findMyWay.on('GET', '/bb/', noop) findMyWay.on('GET', '/bb/*', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) diff --git a/test/issue-62.test.js b/test/issue-62.test.js index 70fba2cf..7e5bde7a 100644 --- a/test/issue-62.test.js +++ b/test/issue-62.test.js @@ -1,28 +1,28 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const FindMyWay = require('../') const noop = function () {} -t.test('issue-62', (t) => { +test('issue-62', (t) => { t.plan(2) const findMyWay = FindMyWay({ allowUnsafeRegex: true }) findMyWay.on('GET', '/foo/:id(([a-f0-9]{3},?)+)', noop) - t.notOk(findMyWay.find('GET', '/foo/qwerty')) - t.ok(findMyWay.find('GET', '/foo/bac,1ea')) + t.assert.ok(!findMyWay.find('GET', '/foo/qwerty')) + t.assert.ok(findMyWay.find('GET', '/foo/bac,1ea')) }) -t.test('issue-62 - escape chars', (t) => { +test('issue-62 - escape chars', (t) => { const findMyWay = FindMyWay() t.plan(2) findMyWay.get('/foo/:param(\\([a-f0-9]{3}\\))', noop) - t.notOk(findMyWay.find('GET', '/foo/abc')) - t.ok(findMyWay.find('GET', '/foo/(abc)', {})) + t.assert.ok(!findMyWay.find('GET', '/foo/abc')) + t.assert.ok(findMyWay.find('GET', '/foo/(abc)', {})) }) diff --git a/test/issue-63.test.js b/test/issue-63.test.js index 1839d86f..2becc1e5 100644 --- a/test/issue-63.test.js +++ b/test/issue-63.test.js @@ -1,11 +1,11 @@ 'use strict' -const t = require('tap') +const { test } = require('node:test') const factory = require('../') const noop = function () {} -t.test('issue-63', (t) => { +test('issue-63', (t) => { t.plan(2) const fmw = factory() @@ -16,8 +16,8 @@ t.test('issue-63', (t) => { try { fmw.on('GET', '/foo/:id(a', noop) - t.fail('should fail') + t.assert.fail('should fail') } catch (err) { - t.equal(err.message, 'Invalid regexp expression in "/foo/:id(a"') + t.assert.equal(err.message, 'Invalid regexp expression in "/foo/:id(a"') } }) diff --git a/test/issue-67.test.js b/test/issue-67.test.js index 98e852e6..9e38bdc0 100644 --- a/test/issue-67.test.js +++ b/test/issue-67.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') const noop = () => {} @@ -13,7 +12,7 @@ test('static routes', t => { findMyWay.on('GET', '/b/bulk', noop) findMyWay.on('GET', '/b/ulk', noop) - t.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) }) test('parametric routes', t => { @@ -27,11 +26,11 @@ test('parametric routes', t => { findMyWay.on('GET', '/foo/search', noop) findMyWay.on('GET', '/foo/submit', noop) - t.equal(findMyWay.find('GET', '/foo/awesome-parameter').handler, foo) - t.equal(findMyWay.find('GET', '/foo/b-first-character').handler, foo) - t.equal(findMyWay.find('GET', '/foo/s-first-character').handler, foo) - t.equal(findMyWay.find('GET', '/foo/se-prefix').handler, foo) - t.equal(findMyWay.find('GET', '/foo/sx-prefix').handler, foo) + t.assert.equal(findMyWay.find('GET', '/foo/awesome-parameter').handler, foo) + t.assert.equal(findMyWay.find('GET', '/foo/b-first-character').handler, foo) + t.assert.equal(findMyWay.find('GET', '/foo/s-first-character').handler, foo) + t.assert.equal(findMyWay.find('GET', '/foo/se-prefix').handler, foo) + t.assert.equal(findMyWay.find('GET', '/foo/sx-prefix').handler, foo) }) test('parametric with common prefix', t => { @@ -40,7 +39,7 @@ test('parametric with common prefix', t => { findMyWay.on('GET', '/test', noop) findMyWay.on('GET', '/:test', (req, res, params) => { - t.same( + t.assert.deepEqual( { test: 'text' }, params ) diff --git a/test/issue-93.test.js b/test/issue-93.test.js index 3d019637..3255ef41 100644 --- a/test/issue-93.test.js +++ b/test/issue-93.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') const noop = () => {} @@ -13,8 +12,8 @@ test('Should keep semver store when split node', t => { findMyWay.on('GET', '/t1', { constraints: { version: '1.0.0' } }, noop) findMyWay.on('GET', '/t2', { constraints: { version: '2.1.0' } }, noop) - t.ok(findMyWay.find('GET', '/t1', { version: '1.0.0' })) - t.ok(findMyWay.find('GET', '/t2', { version: '2.x' })) - t.notOk(findMyWay.find('GET', '/t1', { version: '2.x' })) - t.notOk(findMyWay.find('GET', '/t2', { version: '1.0.0' })) + t.assert.ok(findMyWay.find('GET', '/t1', { version: '1.0.0' })) + t.assert.ok(findMyWay.find('GET', '/t2', { version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/t1', { version: '2.x' })) + t.assert.ok(!findMyWay.find('GET', '/t2', { version: '1.0.0' })) }) diff --git a/test/lookup-async.test.js b/test/lookup-async.test.js index a56203ef..20a805c0 100644 --- a/test/lookup-async.test.js +++ b/test/lookup-async.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('should return result in the done callback', t => { @@ -11,8 +10,8 @@ test('should return result in the done callback', t => { router.on('GET', '/', () => 'asyncHandlerResult') router.lookup({ method: 'GET', url: '/' }, null, (err, result) => { - t.equal(err, null) - t.equal(result, 'asyncHandlerResult') + t.assert.equal(err, null) + t.assert.equal(result, 'asyncHandlerResult') }) }) @@ -24,7 +23,7 @@ test('should return an error in the done callback', t => { router.on('GET', '/', () => { throw error }) router.lookup({ method: 'GET', url: '/' }, null, (err, result) => { - t.equal(err, error) - t.equal(result, undefined) + t.assert.equal(err, error) + t.assert.equal(result, undefined) }) }) diff --git a/test/lookup.test.js b/test/lookup.test.js index dcb1175f..d6ad0888 100644 --- a/test/lookup.test.js +++ b/test/lookup.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('lookup calls route handler with no context', t => { @@ -11,7 +10,7 @@ test('lookup calls route handler with no context', t => { findMyWay.on('GET', '/example', function handle (req, res, params) { // without context, this will be the result object returned from router.find - t.equal(this.handler, handle) + t.assert.equal(this.handler, handle) }) findMyWay.lookup({ method: 'GET', url: '/example', headers: {} }, null) @@ -25,7 +24,7 @@ test('lookup calls route handler with context as scope', t => { const ctx = { foo: 'bar' } findMyWay.on('GET', '/example', function handle (req, res, params) { - t.equal(this, ctx) + t.assert.equal(this, ctx) }) findMyWay.lookup({ method: 'GET', url: '/example', headers: {} }, null, ctx) @@ -37,7 +36,7 @@ test('lookup calls default route handler with no context', t => { const findMyWay = FindMyWay({ defaultRoute (req, res) { // without context, the default route's scope is the router itself - t.equal(this, findMyWay) + t.assert.equal(this, findMyWay) } }) @@ -51,7 +50,7 @@ test('lookup calls default route handler with context as scope', t => { const findMyWay = FindMyWay({ defaultRoute (req, res) { - t.equal(this, ctx) + t.assert.equal(this, ctx) } }) diff --git a/test/matching-order.test.js b/test/matching-order.test.js index 409c1ccb..87fbe367 100644 --- a/test/matching-order.test.js +++ b/test/matching-order.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('Matching order', t => { @@ -12,7 +11,7 @@ test('Matching order', t => { findMyWay.on('GET', '/foo/bar/*', () => {}) findMyWay.on('GET', '/foo/:param/static', () => {}) - t.same(findMyWay.find('GET', '/foo/bar/static', { host: 'test' }).params, {}) - t.same(findMyWay.find('GET', '/foo/bar/static').params, { '*': 'static' }) - t.same(findMyWay.find('GET', '/foo/value/static').params, { param: 'value' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo/bar/static', { host: 'test' }).params, {}) + t.assert.deepEqual(findMyWay.find('GET', '/foo/bar/static').params, { '*': 'static' }) + t.assert.deepEqual(findMyWay.find('GET', '/foo/value/static').params, { param: 'value' }) }) diff --git a/test/max-param-length.test.js b/test/max-param-length.test.js index 40f9b4a4..46c30079 100644 --- a/test/max-param-length.test.js +++ b/test/max-param-length.test.js @@ -1,14 +1,13 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('maxParamLength default value is 500', t => { t.plan(1) const findMyWay = FindMyWay() - t.equal(findMyWay.maxParamLength, 100) + t.assert.equal(findMyWay.maxParamLength, 100) }) test('maxParamLength should set the maximum length for a parametric route', t => { @@ -16,7 +15,7 @@ test('maxParamLength should set the maximum length for a parametric route', t => const findMyWay = FindMyWay({ maxParamLength: 10 }) findMyWay.on('GET', '/test/:param', () => {}) - t.same(findMyWay.find('GET', '/test/123456789abcd'), null) + t.assert.deepEqual(findMyWay.find('GET', '/test/123456789abcd'), null) }) test('maxParamLength should set the maximum length for a parametric (regex) route', t => { @@ -25,7 +24,7 @@ test('maxParamLength should set the maximum length for a parametric (regex) rout const findMyWay = FindMyWay({ maxParamLength: 10 }) findMyWay.on('GET', '/test/:param(^\\d+$)', () => {}) - t.same(findMyWay.find('GET', '/test/123456789abcd'), null) + t.assert.deepEqual(findMyWay.find('GET', '/test/123456789abcd'), null) }) test('maxParamLength should set the maximum length for a parametric (multi) route', t => { @@ -33,7 +32,7 @@ test('maxParamLength should set the maximum length for a parametric (multi) rout const findMyWay = FindMyWay({ maxParamLength: 10 }) findMyWay.on('GET', '/test/:param-bar', () => {}) - t.same(findMyWay.find('GET', '/test/123456789abcd'), null) + t.assert.deepEqual(findMyWay.find('GET', '/test/123456789abcd'), null) }) test('maxParamLength should set the maximum length for a parametric (regex with suffix) route', t => { @@ -41,5 +40,5 @@ test('maxParamLength should set the maximum length for a parametric (regex with const findMyWay = FindMyWay({ maxParamLength: 10 }) findMyWay.on('GET', '/test/:param(^\\w{3})bar', () => {}) - t.same(findMyWay.find('GET', '/test/123456789abcd'), null) + t.assert.deepEqual(findMyWay.find('GET', '/test/123456789abcd'), null) }) diff --git a/test/methods.test.js b/test/methods.test.js index 95ad6033..64794345 100644 --- a/test/methods.test.js +++ b/test/methods.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('the router is an object with methods', t => { @@ -9,10 +8,10 @@ test('the router is an object with methods', t => { const findMyWay = FindMyWay() - t.equal(typeof findMyWay.on, 'function') - t.equal(typeof findMyWay.off, 'function') - t.equal(typeof findMyWay.lookup, 'function') - t.equal(typeof findMyWay.find, 'function') + t.assert.equal(typeof findMyWay.on, 'function') + t.assert.equal(typeof findMyWay.off, 'function') + t.assert.equal(typeof findMyWay.lookup, 'function') + t.assert.equal(typeof findMyWay.find, 'function') }) test('on throws for invalid method', t => { @@ -49,7 +48,7 @@ test('register a route', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test', () => { - t.ok('inside the handler') + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) @@ -60,7 +59,7 @@ test('register a route with multiple methods', t => { const findMyWay = FindMyWay() findMyWay.on(['GET', 'POST'], '/test', () => { - t.ok('inside the handler') + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) @@ -74,7 +73,7 @@ test('does not register /test/*/ when ignoreTrailingSlash is true', t => { }) findMyWay.on('GET', '/test/*', () => {}) - t.equal( + t.assert.equal( findMyWay.routes.filter((r) => r.path.includes('/test')).length, 1 ) @@ -118,7 +117,7 @@ test('off with nested wildcards with parametric and static', t => { }) findMyWay.on('GET', '*', (req, res, params) => { - t.equal(params['*'], '/foo2/first/second') + t.assert.equal(params['*'], '/foo2/first/second') }) findMyWay.on('GET', '/foo1/*', () => {}) findMyWay.on('GET', '/foo2/*', () => {}) @@ -127,12 +126,12 @@ test('off with nested wildcards with parametric and static', t => { findMyWay.on('GET', '/foo4/param/hello/test/long/route', () => {}) const route1 = findMyWay.find('GET', '/foo3/first/second') - t.equal(route1.params['*'], 'first/second') + t.assert.equal(route1.params['*'], 'first/second') findMyWay.off('GET', '/foo3/*') const route2 = findMyWay.find('GET', '/foo3/first/second') - t.equal(route2.params['*'], '/foo3/first/second') + t.assert.equal(route2.params['*'], '/foo3/first/second') findMyWay.off('GET', '/foo2/*') findMyWay.lookup( @@ -148,24 +147,24 @@ test('off removes all routes when ignoreTrailingSlash is true', t => { }) findMyWay.on('GET', '/test1/', () => {}) - t.equal(findMyWay.routes.length, 1) + t.assert.equal(findMyWay.routes.length, 1) findMyWay.on('GET', '/test2', () => {}) - t.equal(findMyWay.routes.length, 2) + t.assert.equal(findMyWay.routes.length, 2) findMyWay.off('GET', '/test1') - t.equal(findMyWay.routes.length, 1) - t.equal( + t.assert.equal(findMyWay.routes.length, 1) + t.assert.equal( findMyWay.routes.filter((r) => r.path === '/test2').length, 1 ) - t.equal( + t.assert.equal( findMyWay.routes.filter((r) => r.path === '/test2/').length, 0 ) findMyWay.off('GET', '/test2/') - t.equal(findMyWay.routes.length, 0) + t.assert.equal(findMyWay.routes.length, 0) }) test('off removes all routes when ignoreDuplicateSlashes is true', t => { @@ -175,24 +174,24 @@ test('off removes all routes when ignoreDuplicateSlashes is true', t => { }) findMyWay.on('GET', '//test1', () => {}) - t.equal(findMyWay.routes.length, 1) + t.assert.equal(findMyWay.routes.length, 1) findMyWay.on('GET', '/test2', () => {}) - t.equal(findMyWay.routes.length, 2) + t.assert.equal(findMyWay.routes.length, 2) findMyWay.off('GET', '/test1') - t.equal(findMyWay.routes.length, 1) - t.equal( + t.assert.equal(findMyWay.routes.length, 1) + t.assert.equal( findMyWay.routes.filter((r) => r.path === '/test2').length, 1 ) - t.equal( + t.assert.equal( findMyWay.routes.filter((r) => r.path === '//test2').length, 0 ) findMyWay.off('GET', '//test2') - t.equal(findMyWay.routes.length, 0) + t.assert.equal(findMyWay.routes.length, 0) }) test('deregister a route without children', t => { @@ -203,8 +202,8 @@ test('deregister a route without children', t => { findMyWay.on('GET', '/a/b', () => {}) findMyWay.off('GET', '/a/b') - t.ok(findMyWay.find('GET', '/a')) - t.notOk(findMyWay.find('GET', '/a/b')) + t.assert.ok(findMyWay.find('GET', '/a')) + t.assert.ok(!findMyWay.find('GET', '/a/b')) }) test('deregister a route with children', t => { @@ -215,8 +214,8 @@ test('deregister a route with children', t => { findMyWay.on('GET', '/a/b', () => {}) findMyWay.off('GET', '/a') - t.notOk(findMyWay.find('GET', '/a')) - t.ok(findMyWay.find('GET', '/a/b')) + t.assert.ok(!findMyWay.find('GET', '/a')) + t.assert.ok(findMyWay.find('GET', '/a/b')) }) test('deregister a route by method', t => { @@ -226,8 +225,8 @@ test('deregister a route by method', t => { findMyWay.on(['GET', 'POST'], '/a', () => {}) findMyWay.off('GET', '/a') - t.notOk(findMyWay.find('GET', '/a')) - t.ok(findMyWay.find('POST', '/a')) + t.assert.ok(!findMyWay.find('GET', '/a')) + t.assert.ok(findMyWay.find('POST', '/a')) }) test('deregister a route with multiple methods', t => { @@ -237,8 +236,8 @@ test('deregister a route with multiple methods', t => { findMyWay.on(['GET', 'POST'], '/a', () => {}) findMyWay.off(['GET', 'POST'], '/a') - t.notOk(findMyWay.find('GET', '/a')) - t.notOk(findMyWay.find('POST', '/a')) + t.assert.ok(!findMyWay.find('GET', '/a')) + t.assert.ok(!findMyWay.find('POST', '/a')) }) test('reset a router', t => { @@ -248,8 +247,8 @@ test('reset a router', t => { findMyWay.on(['GET', 'POST'], '/a', () => {}) findMyWay.reset() - t.notOk(findMyWay.find('GET', '/a')) - t.notOk(findMyWay.find('POST', '/a')) + t.assert.ok(!findMyWay.find('GET', '/a')) + t.assert.ok(!findMyWay.find('POST', '/a')) }) test('default route', t => { @@ -257,7 +256,7 @@ test('default route', t => { const findMyWay = FindMyWay({ defaultRoute: () => { - t.ok('inside the default route') + t.assert.ok('inside the default route') } }) @@ -269,7 +268,7 @@ test('parametric route', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:id', (req, res, params) => { - t.equal(params.id, 'hello') + t.assert.equal(params.id, 'hello') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -280,11 +279,11 @@ test('multiple parametric route', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:id', (req, res, params) => { - t.equal(params.id, 'hello') + t.assert.equal(params.id, 'hello') }) findMyWay.on('GET', '/other-test/:id', (req, res, params) => { - t.equal(params.id, 'world') + t.assert.equal(params.id, 'world') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -296,11 +295,11 @@ test('multiple parametric route with the same prefix', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:id', (req, res, params) => { - t.equal(params.id, 'hello') + t.assert.equal(params.id, 'hello') }) findMyWay.on('GET', '/test/:id/world', (req, res, params) => { - t.equal(params.id, 'world') + t.assert.equal(params.id, 'world') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -312,8 +311,8 @@ test('nested parametric route', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:hello/test/:world', (req, res, params) => { - t.equal(params.hello, 'hello') - t.equal(params.world, 'world') + t.assert.equal(params.hello, 'hello') + t.assert.equal(params.world, 'world') }) findMyWay.lookup({ method: 'GET', url: '/test/hello/test/world', headers: {} }, null) @@ -324,12 +323,12 @@ test('nested parametric route with same prefix', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test', (req, res, params) => { - t.ok('inside route') + t.assert.ok('inside route') }) findMyWay.on('GET', '/test/:hello/test/:world', (req, res, params) => { - t.equal(params.hello, 'hello') - t.equal(params.world, 'world') + t.assert.equal(params.hello, 'hello') + t.assert.equal(params.world, 'world') }) findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) @@ -341,7 +340,7 @@ test('long route', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/abc/def/ghi/lmn/opq/rst/uvz', (req, res, params) => { - t.ok('inside long path') + t.assert.ok('inside long path') }) findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null) @@ -352,9 +351,9 @@ test('long parametric route', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/abc/:def/ghi/:lmn/opq/:rst/uvz', (req, res, params) => { - t.equal(params.def, 'def') - t.equal(params.lmn, 'lmn') - t.equal(params.rst, 'rst') + t.assert.equal(params.def, 'def') + t.assert.equal(params.lmn, 'lmn') + t.assert.equal(params.rst, 'rst') }) findMyWay.lookup({ method: 'GET', url: '/abc/def/ghi/lmn/opq/rst/uvz', headers: {} }, null) @@ -373,24 +372,24 @@ test('long parametric route with common prefix', t => { }) findMyWay.on('GET', '/abc/:def', (req, res, params) => { - t.equal(params.def, 'def') + t.assert.equal(params.def, 'def') }) findMyWay.on('GET', '/abc/:def/ghi/:lmn', (req, res, params) => { - t.equal(params.def, 'def') - t.equal(params.lmn, 'lmn') + t.assert.equal(params.def, 'def') + t.assert.equal(params.lmn, 'lmn') }) findMyWay.on('GET', '/abc/:def/ghi/:lmn/opq/:rst', (req, res, params) => { - t.equal(params.def, 'def') - t.equal(params.lmn, 'lmn') - t.equal(params.rst, 'rst') + t.assert.equal(params.def, 'def') + t.assert.equal(params.lmn, 'lmn') + t.assert.equal(params.rst, 'rst') }) findMyWay.on('GET', '/abc/:def/ghi/:lmn/opq/:rst/uvz', (req, res, params) => { - t.equal(params.def, 'def') - t.equal(params.lmn, 'lmn') - t.equal(params.rst, 'rst') + t.assert.equal(params.def, 'def') + t.assert.equal(params.lmn, 'lmn') + t.assert.equal(params.rst, 'rst') }) findMyWay.lookup({ method: 'GET', url: '/abc/def', headers: {} }, null) @@ -404,19 +403,19 @@ test('common prefix', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/f', (req, res, params) => { - t.ok('inside route') + t.assert.ok('inside route') }) findMyWay.on('GET', '/ff', (req, res, params) => { - t.ok('inside route') + t.assert.ok('inside route') }) findMyWay.on('GET', '/ffa', (req, res, params) => { - t.ok('inside route') + t.assert.ok('inside route') }) findMyWay.on('GET', '/ffb', (req, res, params) => { - t.ok('inside route') + t.assert.ok('inside route') }) findMyWay.lookup({ method: 'GET', url: '/f', headers: {} }, null) @@ -430,7 +429,7 @@ test('wildcard', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/*', (req, res, params) => { - t.equal(params['*'], 'hello') + t.assert.equal(params['*'], 'hello') }) findMyWay.lookup( @@ -444,7 +443,7 @@ test('catch all wildcard', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '*', (req, res, params) => { - t.equal(params['*'], '/test/hello') + t.assert.equal(params['*'], '/test/hello') }) findMyWay.lookup( @@ -460,7 +459,7 @@ test('find should return the route', t => { findMyWay.on('GET', '/test', fn) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test'), { handler: fn, params: {}, store: null, searchParams: {} } ) @@ -473,7 +472,7 @@ test('find should return the route with params', t => { findMyWay.on('GET', '/test/:id', fn) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/hello'), { handler: fn, params: { id: 'hello' }, store: null, searchParams: {} } ) @@ -483,7 +482,7 @@ test('find should return a null handler if the route does not exist', t => { t.plan(1) const findMyWay = FindMyWay() - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test'), null ) @@ -496,7 +495,7 @@ test('should decode the uri - parametric', t => { findMyWay.on('GET', '/test/:id', fn) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/he%2Fllo'), { handler: fn, params: { id: 'he/llo' }, store: null, searchParams: {} } ) @@ -509,7 +508,7 @@ test('should decode the uri - wildcard', t => { findMyWay.on('GET', '/test/*', fn) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/he%2Fllo'), { handler: fn, params: { '*': 'he/llo' }, store: null, searchParams: {} } ) @@ -522,7 +521,7 @@ test('safe decodeURIComponent', t => { findMyWay.on('GET', '/test/:id', fn) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/hel%"Flo'), null ) @@ -535,7 +534,7 @@ test('safe decodeURIComponent - nested route', t => { findMyWay.on('GET', '/test/hello/world/:id/blah', fn) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/hello/world/hel%"Flo/blah'), null ) @@ -548,7 +547,7 @@ test('safe decodeURIComponent - wildcard', t => { findMyWay.on('GET', '/test/*', fn) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/hel%"Flo'), null ) @@ -559,7 +558,7 @@ test('static routes should be inserted before parametric / 1', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/hello', () => { - t.pass('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.on('GET', '/test/:id', () => { @@ -578,7 +577,7 @@ test('static routes should be inserted before parametric / 2', t => { }) findMyWay.on('GET', '/test/hello', () => { - t.pass('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -593,7 +592,7 @@ test('static routes should be inserted before parametric / 3', t => { }) findMyWay.on('GET', '/test', () => { - t.ok('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.on('GET', '/test/:id', () => { @@ -601,7 +600,7 @@ test('static routes should be inserted before parametric / 3', t => { }) findMyWay.on('GET', '/test/hello', () => { - t.ok('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) @@ -613,7 +612,7 @@ test('static routes should be inserted before parametric / 4', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/:id', () => { - t.ok('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.on('GET', '/test', () => { @@ -621,7 +620,7 @@ test('static routes should be inserted before parametric / 4', t => { }) findMyWay.on('GET', '/test/:id', () => { - t.ok('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.on('GET', '/test/hello', () => { @@ -637,7 +636,7 @@ test('Static parametric with shared part of the path', t => { const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.equal(req.url, '/example/shared/nested/oopss') + t.assert.equal(req.url, '/example/shared/nested/oopss') } }) @@ -646,7 +645,7 @@ test('Static parametric with shared part of the path', t => { }) findMyWay.on('GET', '/example/:param/nested/oops', (req, res, params) => { - t.equal(params.param, 'other') + t.assert.equal(params.param, 'other') }) findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/oopss', headers: {} }, null) @@ -658,11 +657,11 @@ test('parametric route with different method', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:id', (req, res, params) => { - t.equal(params.id, 'hello') + t.assert.equal(params.id, 'hello') }) findMyWay.on('POST', '/test/:other', (req, res, params) => { - t.equal(params.other, 'world') + t.assert.equal(params.other, 'world') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -677,11 +676,11 @@ test('params does not keep the object reference', t => { findMyWay.on('GET', '/test/:id', (req, res, params) => { if (first) { setTimeout(() => { - t.equal(params.id, 'hello') + t.assert.equal(params.id, 'hello') }, 10) } else { setTimeout(() => { - t.equal(params.id, 'world') + t.assert.equal(params.id, 'world') }, 10) } first = false @@ -695,7 +694,7 @@ test('Unsupported method (static)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything ok') + t.assert.ok('Everything ok') } }) @@ -710,7 +709,7 @@ test('Unsupported method (wildcard)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything ok') + t.assert.ok('Everything ok') } }) @@ -727,7 +726,7 @@ test('Unsupported method (static find)', t => { findMyWay.on('GET', '/', () => {}) - t.same(findMyWay.find('TROLL', '/'), null) + t.assert.deepEqual(findMyWay.find('TROLL', '/'), null) }) test('Unsupported method (wildcard find)', t => { @@ -736,7 +735,7 @@ test('Unsupported method (wildcard find)', t => { findMyWay.on('GET', '*', () => {}) - t.same(findMyWay.find('TROLL', '/hello/world'), null) + t.assert.deepEqual(findMyWay.find('TROLL', '/hello/world'), null) }) test('register all known HTTP methods', t => { @@ -751,14 +750,14 @@ test('register all known HTTP methods', t => { findMyWay.on(m, '/test', handlers[m]) } - t.ok(findMyWay.find('COPY', '/test')) - t.equal(findMyWay.find('COPY', '/test').handler, handlers.COPY) + t.assert.ok(findMyWay.find('COPY', '/test')) + t.assert.equal(findMyWay.find('COPY', '/test').handler, handlers.COPY) - t.ok(findMyWay.find('SUBSCRIBE', '/test')) - t.equal(findMyWay.find('SUBSCRIBE', '/test').handler, handlers.SUBSCRIBE) + t.assert.ok(findMyWay.find('SUBSCRIBE', '/test')) + t.assert.equal(findMyWay.find('SUBSCRIBE', '/test').handler, handlers.SUBSCRIBE) - t.ok(findMyWay.find('M-SEARCH', '/test')) - t.equal(findMyWay.find('M-SEARCH', '/test').handler, handlers['M-SEARCH']) + t.assert.ok(findMyWay.find('M-SEARCH', '/test')) + t.assert.equal(findMyWay.find('M-SEARCH', '/test').handler, handlers['M-SEARCH']) }) test('off removes all routes without checking constraints if no constraints are specified', t => { @@ -771,7 +770,7 @@ test('off removes all routes without checking constraints if no constraints are findMyWay.off('GET', '/test') - t.equal(findMyWay.routes.length, 0) + t.assert.equal(findMyWay.routes.length, 0) }) test('off removes only constrainted routes if constraints are specified', t => { @@ -784,8 +783,8 @@ test('off removes only constrainted routes if constraints are specified', t => { findMyWay.off('GET', '/test', { host: 'example.com' }) - t.equal(findMyWay.routes.length, 1) - t.notOk(findMyWay.routes[0].opts.constraints) + t.assert.equal(findMyWay.routes.length, 1) + t.assert.ok(!findMyWay.routes[0].opts.constraints) }) test('off removes no routes if provided constraints does not match any registered route', t => { @@ -799,7 +798,7 @@ test('off removes no routes if provided constraints does not match any registere findMyWay.off('GET', '/test', { version: '1.x' }) - t.equal(findMyWay.routes.length, 3) + t.assert.equal(findMyWay.routes.length, 3) }) test('off validates that constraints is an object or undefined', t => { @@ -825,6 +824,6 @@ test('off removes only unconstrainted route if an empty object is given as const findMyWay.off('GET', '/', {}) - t.equal(findMyWay.routes.length, 1) - t.equal(findMyWay.routes[0].opts.constraints.host, 'fastify.io') + t.assert.equal(findMyWay.routes.length, 1) + t.assert.equal(findMyWay.routes[0].opts.constraints.host, 'fastify.io') }) diff --git a/test/null-object.test.js b/test/null-object.test.js index b6d6921f..41bb5efc 100644 --- a/test/null-object.test.js +++ b/test/null-object.test.js @@ -1,13 +1,13 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const { NullObject } = require('../lib/null-object') test('NullObject', t => { t.plan(2) const nullObject = new NullObject() - t.ok(nullObject instanceof NullObject) - t.ok(typeof nullObject === 'object') + t.assert.ok(nullObject instanceof NullObject) + t.assert.ok(typeof nullObject === 'object') }) test('has no methods from generic Object class', t => { @@ -30,7 +30,7 @@ test('has no methods from generic Object class', t => { const nullObject = new NullObject() for (const propertyName of propertyNames) { - t.notOk(propertyName in nullObject, propertyName) + t.assert.ok(!propertyName in nullObject, propertyName) } - t.equal(getAllPropertyNames(nullObject).length, 0) + t.assert.equal(getAllPropertyNames(nullObject).length, 0) }) diff --git a/test/on-bad-url.test.js b/test/on-bad-url.test.js index b3beb5c4..920d137c 100644 --- a/test/on-bad-url.test.js +++ b/test/on-bad-url.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('If onBadUrl is defined, then a bad url should be handled differently (find)', t => { @@ -11,7 +10,7 @@ test('If onBadUrl is defined, then a bad url should be handled differently (find t.fail('Should not be defaultRoute') }, onBadUrl: (path, req, res) => { - t.equal(path, '/%world', { todo: 'this is not executed' }) + t.assert.equal(path, '/%world', { todo: 'this is not executed' }) } }) @@ -30,7 +29,7 @@ test('If onBadUrl is defined, then a bad url should be handled differently (look t.fail('Should not be defaultRoute') }, onBadUrl: (path, req, res) => { - t.equal(path, '/hello/%world') + t.assert.equal(path, '/hello/%world') } }) @@ -54,14 +53,14 @@ test('If onBadUrl is not defined, then we should call the defaultRoute (find)', }) const handle = findMyWay.find('GET', '/hello/%world') - t.equal(handle, null) + t.assert.equal(handle, null) }) test('If onBadUrl is not defined, then we should call the defaultRoute (lookup)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything fine') + t.assert.ok('Everything fine') } }) diff --git a/test/optional-params.test.js b/test/optional-params.test.js index 16650654..0390d878 100644 --- a/test/optional-params.test.js +++ b/test/optional-params.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('Test route with optional parameter', (t) => { @@ -14,9 +13,9 @@ test('Test route with optional parameter', (t) => { findMyWay.on('GET', '/a/:param/b/:optional?', (req, res, params) => { if (params.optional) { - t.equal(params.optional, 'foo') + t.assert.equal(params.optional, 'foo') } else { - t.equal(params.optional, undefined) + t.assert.equal(params.optional, undefined) } }) @@ -38,7 +37,7 @@ test('Test for duplicate route with optional param', (t) => { findMyWay.on('GET', '/foo', (req, res, params) => {}) t.fail('method is already declared for route with optional param') } catch (e) { - t.equal(e.message, 'Method \'GET\' already declared for route \'/foo\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/foo\' with constraints \'{}\'') } }) @@ -54,7 +53,7 @@ test('Test for param with ? not at the end', (t) => { findMyWay.on('GET', '/foo/:bar?/baz', (req, res, params) => {}) t.fail('Optional Param in the middle of the path is not allowed') } catch (e) { - t.equal(e.message, 'Optional Parameter needs to be the last parameter of the path') + t.assert.equal(e.message, 'Optional Parameter needs to be the last parameter of the path') } }) @@ -68,8 +67,8 @@ test('Multi parametric route with optional param', (t) => { findMyWay.on('GET', '/a/:p1-:p2?', (req, res, params) => { if (params.p1 && params.p2) { - t.equal(params.p1, 'foo-bar') - t.equal(params.p2, 'baz') + t.assert.equal(params.p1, 'foo-bar') + t.assert.equal(params.p2, 'baz') } }) @@ -88,9 +87,9 @@ test('Optional Parameter with ignoreTrailingSlash = true', (t) => { findMyWay.on('GET', '/test/hello/:optional?', (req, res, params) => { if (params.optional) { - t.equal(params.optional, 'foo') + t.assert.equal(params.optional, 'foo') } else { - t.equal(params.optional, undefined) + t.assert.equal(params.optional, undefined) } }) @@ -111,11 +110,11 @@ test('Optional Parameter with ignoreTrailingSlash = false', (t) => { findMyWay.on('GET', '/test/hello/:optional?', (req, res, params) => { if (req.url === '/test/hello/') { - t.same(params, { optional: '' }) + t.assert.deepEqual(params, { optional: '' }) } else if (req.url === '/test/hello') { - t.same(params, {}) + t.assert.deepEqual(params, {}) } else if (req.url === '/test/hello/foo') { - t.same(params, { optional: 'foo' }) + t.assert.deepEqual(params, { optional: 'foo' }) } }) @@ -136,9 +135,9 @@ test('Optional Parameter with ignoreDuplicateSlashes = true', (t) => { findMyWay.on('GET', '/test/hello/:optional?', (req, res, params) => { if (params.optional) { - t.equal(params.optional, 'foo') + t.assert.equal(params.optional, 'foo') } else { - t.equal(params.optional, undefined) + t.assert.equal(params.optional, undefined) } }) @@ -154,20 +153,20 @@ test('Optional Parameter with ignoreDuplicateSlashes = false', (t) => { ignoreDuplicateSlashes: false, defaultRoute: (req, res) => { if (req.url === '/test//hello') { - t.same(req.params, undefined) + t.assert.deepEqual(req.params, undefined) } else if (req.url === '/test//hello/foo') { - t.same(req.params, undefined) + t.assert.deepEqual(req.params, undefined) } } }) findMyWay.on('GET', '/test/hello/:optional?', (req, res, params) => { if (req.url === '/test/hello/') { - t.same(params, { optional: '' }) + t.assert.deepEqual(params, { optional: '' }) } else if (req.url === '/test/hello') { - t.same(params, {}) + t.assert.deepEqual(params, {}) } else if (req.url === '/test/hello/foo') { - t.same(params, { optional: 'foo' }) + t.assert.deepEqual(params, { optional: 'foo' }) } }) @@ -187,13 +186,13 @@ test('deregister a route with optional param', (t) => { findMyWay.on('GET', '/a/:param/b/:optional?', (req, res, params) => {}) - t.ok(findMyWay.find('GET', '/a/:param/b')) - t.ok(findMyWay.find('GET', '/a/:param/b/:optional')) + t.assert.ok(findMyWay.find('GET', '/a/:param/b')) + t.assert.ok(findMyWay.find('GET', '/a/:param/b/:optional')) findMyWay.off('GET', '/a/:param/b/:optional?') - t.notOk(findMyWay.find('GET', '/a/:param/b')) - t.notOk(findMyWay.find('GET', '/a/:param/b/:optional')) + t.assert.ok(!findMyWay.find('GET', '/a/:param/b')) + t.assert.ok(!findMyWay.find('GET', '/a/:param/b/:optional')) }) test('optional parameter on root', (t) => { @@ -206,9 +205,9 @@ test('optional parameter on root', (t) => { findMyWay.on('GET', '/:optional?', (req, res, params) => { if (params.optional) { - t.equal(params.optional, 'foo') + t.assert.equal(params.optional, 'foo') } else { - t.equal(params.optional, undefined) + t.assert.equal(params.optional, undefined) } }) diff --git a/test/params-collisions.test.js b/test/params-collisions.test.js index 96989991..b1c163f9 100644 --- a/test/params-collisions.test.js +++ b/test/params-collisions.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('..') test('should setup parametric and regexp node', t => { @@ -15,8 +14,8 @@ test('should setup parametric and regexp node', t => { findMyWay.on('GET', '/foo/:bar', paramHandler) findMyWay.on('GET', '/foo/:bar(123)', regexpHandler) - t.equal(findMyWay.find('GET', '/foo/value').handler, paramHandler) - t.equal(findMyWay.find('GET', '/foo/123').handler, regexpHandler) + t.assert.equal(findMyWay.find('GET', '/foo/value').handler, paramHandler) + t.assert.equal(findMyWay.find('GET', '/foo/123').handler, regexpHandler) }) test('should setup parametric and multi-parametric node', t => { @@ -30,8 +29,8 @@ test('should setup parametric and multi-parametric node', t => { findMyWay.on('GET', '/foo/:bar', paramHandler) findMyWay.on('GET', '/foo/:bar.png', regexpHandler) - t.equal(findMyWay.find('GET', '/foo/value').handler, paramHandler) - t.equal(findMyWay.find('GET', '/foo/value.png').handler, regexpHandler) + t.assert.equal(findMyWay.find('GET', '/foo/value').handler, paramHandler) + t.assert.equal(findMyWay.find('GET', '/foo/value.png').handler, regexpHandler) }) test('should throw when set upping two parametric nodes', t => { @@ -63,8 +62,8 @@ test('should set up two parametric nodes with static ending', t => { findMyWay.on('GET', '/foo/:bar.png', paramHandler1) findMyWay.on('GET', '/foo/:bar.jpeg', paramHandler2) - t.equal(findMyWay.find('GET', '/foo/value.png').handler, paramHandler1) - t.equal(findMyWay.find('GET', '/foo/value.jpeg').handler, paramHandler2) + t.assert.equal(findMyWay.find('GET', '/foo/value.png').handler, paramHandler1) + t.assert.equal(findMyWay.find('GET', '/foo/value.jpeg').handler, paramHandler2) }) test('should set up two regexp nodes with static ending', t => { @@ -78,8 +77,8 @@ test('should set up two regexp nodes with static ending', t => { findMyWay.on('GET', '/foo/:bar(123).png', paramHandler1) findMyWay.on('GET', '/foo/:bar(456).jpeg', paramHandler2) - t.equal(findMyWay.find('GET', '/foo/123.png').handler, paramHandler1) - t.equal(findMyWay.find('GET', '/foo/456.jpeg').handler, paramHandler2) + t.assert.equal(findMyWay.find('GET', '/foo/123.png').handler, paramHandler1) + t.assert.equal(findMyWay.find('GET', '/foo/456.jpeg').handler, paramHandler2) }) test('node with longer static suffix should have higher priority', t => { @@ -93,8 +92,8 @@ test('node with longer static suffix should have higher priority', t => { findMyWay.on('GET', '/foo/:bar.png', paramHandler1) findMyWay.on('GET', '/foo/:bar.png.png', paramHandler2) - t.equal(findMyWay.find('GET', '/foo/value.png').handler, paramHandler1) - t.equal(findMyWay.find('GET', '/foo/value.png.png').handler, paramHandler2) + t.assert.equal(findMyWay.find('GET', '/foo/value.png').handler, paramHandler1) + t.assert.equal(findMyWay.find('GET', '/foo/value.png.png').handler, paramHandler2) }) test('node with longer static suffix should have higher priority', t => { @@ -108,8 +107,8 @@ test('node with longer static suffix should have higher priority', t => { findMyWay.on('GET', '/foo/:bar.png.png', paramHandler2) findMyWay.on('GET', '/foo/:bar.png', paramHandler1) - t.equal(findMyWay.find('GET', '/foo/value.png').handler, paramHandler1) - t.equal(findMyWay.find('GET', '/foo/value.png.png').handler, paramHandler2) + t.assert.equal(findMyWay.find('GET', '/foo/value.png').handler, paramHandler1) + t.assert.equal(findMyWay.find('GET', '/foo/value.png.png').handler, paramHandler2) }) test('should set up regexp node and node with static ending', t => { @@ -122,6 +121,6 @@ test('should set up regexp node and node with static ending', t => { findMyWay.on('GET', '/foo/:bar(123)', regexHandler) findMyWay.on('GET', '/foo/:bar(123).jpeg', multiParamHandler) - t.equal(findMyWay.find('GET', '/foo/123.jpeg').handler, multiParamHandler) - t.equal(findMyWay.find('GET', '/foo/123').handler, regexHandler) + t.assert.equal(findMyWay.find('GET', '/foo/123.jpeg').handler, multiParamHandler) + t.assert.equal(findMyWay.find('GET', '/foo/123').handler, regexHandler) }) diff --git a/test/path-params-match.test.js b/test/path-params-match.test.js index f9e39ff6..6f635897 100644 --- a/test/path-params-match.test.js +++ b/test/path-params-match.test.js @@ -1,9 +1,9 @@ 'use strict' -const t = require('tap') +const {test} = require('node:test') const FindMyWay = require('../') -t.test('path params match', (t) => { +test('path params match', (t) => { t.plan(24) const findMyWay = FindMyWay({ ignoreTrailingSlash: true, ignoreDuplicateSlashes: true }) @@ -18,36 +18,36 @@ t.test('path params match', (t) => { findMyWay.on('GET', '/ac', cPath) findMyWay.on('GET', '/:pam', paramPath) - t.equal(findMyWay.find('GET', '/ab1').handler, b1Path) - t.equal(findMyWay.find('GET', '/ab1/').handler, b1Path) - t.equal(findMyWay.find('GET', '//ab1').handler, b1Path) - t.equal(findMyWay.find('GET', '//ab1//').handler, b1Path) - t.equal(findMyWay.find('GET', '/ab2').handler, b2Path) - t.equal(findMyWay.find('GET', '/ab2/').handler, b2Path) - t.equal(findMyWay.find('GET', '//ab2').handler, b2Path) - t.equal(findMyWay.find('GET', '//ab2//').handler, b2Path) - t.equal(findMyWay.find('GET', '/ac').handler, cPath) - t.equal(findMyWay.find('GET', '/ac/').handler, cPath) - t.equal(findMyWay.find('GET', '//ac').handler, cPath) - t.equal(findMyWay.find('GET', '//ac//').handler, cPath) - t.equal(findMyWay.find('GET', '/foo').handler, paramPath) - t.equal(findMyWay.find('GET', '/foo/').handler, paramPath) - t.equal(findMyWay.find('GET', '//foo').handler, paramPath) - t.equal(findMyWay.find('GET', '//foo//').handler, paramPath) + t.assert.equal(findMyWay.find('GET', '/ab1').handler, b1Path) + t.assert.equal(findMyWay.find('GET', '/ab1/').handler, b1Path) + t.assert.equal(findMyWay.find('GET', '//ab1').handler, b1Path) + t.assert.equal(findMyWay.find('GET', '//ab1//').handler, b1Path) + t.assert.equal(findMyWay.find('GET', '/ab2').handler, b2Path) + t.assert.equal(findMyWay.find('GET', '/ab2/').handler, b2Path) + t.assert.equal(findMyWay.find('GET', '//ab2').handler, b2Path) + t.assert.equal(findMyWay.find('GET', '//ab2//').handler, b2Path) + t.assert.equal(findMyWay.find('GET', '/ac').handler, cPath) + t.assert.equal(findMyWay.find('GET', '/ac/').handler, cPath) + t.assert.equal(findMyWay.find('GET', '//ac').handler, cPath) + t.assert.equal(findMyWay.find('GET', '//ac//').handler, cPath) + t.assert.equal(findMyWay.find('GET', '/foo').handler, paramPath) + t.assert.equal(findMyWay.find('GET', '/foo/').handler, paramPath) + t.assert.equal(findMyWay.find('GET', '//foo').handler, paramPath) + t.assert.equal(findMyWay.find('GET', '//foo//').handler, paramPath) const noTrailingSlashRet = findMyWay.find('GET', '/abcdef') - t.equal(noTrailingSlashRet.handler, paramPath) - t.same(noTrailingSlashRet.params, { pam: 'abcdef' }) + t.assert.equal(noTrailingSlashRet.handler, paramPath) + t.assert.deepEqual(noTrailingSlashRet.params, { pam: 'abcdef' }) const trailingSlashRet = findMyWay.find('GET', '/abcdef/') - t.equal(trailingSlashRet.handler, paramPath) - t.same(trailingSlashRet.params, { pam: 'abcdef' }) + t.assert.equal(trailingSlashRet.handler, paramPath) + t.assert.deepEqual(trailingSlashRet.params, { pam: 'abcdef' }) const noDuplicateSlashRet = findMyWay.find('GET', '/abcdef') - t.equal(noDuplicateSlashRet.handler, paramPath) - t.same(noDuplicateSlashRet.params, { pam: 'abcdef' }) + t.assert.equal(noDuplicateSlashRet.handler, paramPath) + t.assert.deepEqual(noDuplicateSlashRet.params, { pam: 'abcdef' }) const duplicateSlashRet = findMyWay.find('GET', '//abcdef') - t.equal(duplicateSlashRet.handler, paramPath) - t.same(duplicateSlashRet.params, { pam: 'abcdef' }) + t.assert.equal(duplicateSlashRet.handler, paramPath) + t.assert.deepEqual(duplicateSlashRet.params, { pam: 'abcdef' }) }) diff --git a/test/pretty-print-tree.test.js b/test/pretty-print-tree.test.js index ecc823c0..70ffdaac 100644 --- a/test/pretty-print-tree.test.js +++ b/test/pretty-print-tree.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('pretty print - empty tree', t => { @@ -11,8 +10,8 @@ test('pretty print - empty tree', t => { const tree = findMyWay.prettyPrint({ method: 'GET' }) const expected = '(empty tree)' - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - static routes', t => { @@ -30,8 +29,8 @@ test('pretty print - static routes', t => { │ └── /hello (GET) └── hello/world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes', t => { @@ -51,8 +50,8 @@ test('pretty print - parametric routes', t => { └── hello/ └── :world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes', t => { @@ -79,8 +78,8 @@ test('pretty print - parametric routes', t => { └── :param └── /suffix1 (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes', t => { @@ -101,8 +100,8 @@ test('pretty print - parametric routes', t => { ├── /:param1(123).:param2(456)/suffix4 (GET) └── /:param/suffix1 (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - mixed parametric routes', t => { @@ -122,8 +121,8 @@ test('pretty print - mixed parametric routes', t => { └── :hello (GET) └── /world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - wildcard routes', t => { @@ -143,8 +142,8 @@ test('pretty print - wildcard routes', t => { └── hello/ └── * (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes with same parent and followed by a static route which has the same prefix with the former routes', t => { @@ -165,8 +164,8 @@ test('pretty print - parametric routes with same parent and followed by a static │ └── :id (GET) └── world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - constrained parametric routes', t => { @@ -189,8 +188,8 @@ test('pretty print - constrained parametric routes', t => { :hello (GET) {"version":"1.1.2"} :hello (GET) {"version":"2.0.0"} ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - multiple parameters are drawn appropriately', t => { @@ -210,8 +209,8 @@ test('pretty print - multiple parameters are drawn appropriately', t => { └── /:hello/there/:ladies (GET) └── /and/:gents (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print commonPrefix - use routes array to draw flattened routes', t => { @@ -246,11 +245,11 @@ test('pretty print commonPrefix - use routes array to draw flattened routes', t └── /update (GET) ` - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixExpected) - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) }) test('pretty print commonPrefix - handle wildcard root', t => { @@ -271,8 +270,8 @@ test('pretty print commonPrefix - handle wildcard root', t => { │ └── /:param (GET) └── * (GET) ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) }) test('pretty print commonPrefix - handle wildcard root', t => { @@ -297,8 +296,8 @@ test('pretty print commonPrefix - handle wildcard root', t => { │ └── :param (GET) └── * (GET) ` - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixExpected) }) test('pretty print commonPrefix - handle constrained routes', t => { @@ -321,8 +320,8 @@ test('pretty print commonPrefix - handle constrained routes', t => { /:hello (GET) {"version":"1.1.2"} /:hello (GET) {"version":"2.0.0"} ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) }) test('pretty print includeMeta - commonPrefix: true', t => { @@ -420,14 +419,14 @@ test('pretty print includeMeta - commonPrefix: true', t => { └── :hello (GET) {"version":"1.1.2"} :hello (GET) {"version":"2.0.0"} ` - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixTreeExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixTreeExpected) - t.equal(typeof radixTreeSpecific, 'string') - t.equal(radixTreeSpecific, radixTreeSpecificExpected) + t.assert.equal(typeof radixTreeSpecific, 'string') + t.assert.equal(radixTreeSpecific, radixTreeSpecificExpected) - t.equal(typeof radixTreeNoMeta, 'string') - t.equal(radixTreeNoMeta, radixTreeNoMetaExpected) + t.assert.equal(typeof radixTreeNoMeta, 'string') + t.assert.equal(radixTreeNoMeta, radixTreeNoMetaExpected) }) test('pretty print includeMeta - commonPrefix: false', t => { @@ -517,14 +516,14 @@ test('pretty print includeMeta - commonPrefix: false', t => { /:hello (GET) {"version":"2.0.0"} ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) - t.equal(typeof arraySpecific, 'string') - t.equal(arraySpecific, arraySpecificExpected) + t.assert.equal(typeof arraySpecific, 'string') + t.assert.equal(arraySpecific, arraySpecificExpected) - t.equal(typeof arrayNoMeta, 'string') - t.equal(arrayNoMeta, arrayNoMetaExpected) + t.assert.equal(typeof arrayNoMeta, 'string') + t.assert.equal(arrayNoMeta, arrayNoMetaExpected) }) test('pretty print includeMeta - buildPrettyMeta function', t => { @@ -589,9 +588,9 @@ test('pretty print includeMeta - buildPrettyMeta function', t => { :hello (GET) {"version":"2.0.0"} • (metaKey) "/test/:hello" ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixExpected) }) diff --git a/test/pretty-print.test.js b/test/pretty-print.test.js index c265350e..8e4c8a15 100644 --- a/test/pretty-print.test.js +++ b/test/pretty-print.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('pretty print - empty tree', t => { @@ -11,8 +10,8 @@ test('pretty print - empty tree', t => { const tree = findMyWay.prettyPrint() const expected = '(empty tree)' - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - static routes', t => { @@ -30,8 +29,8 @@ test('pretty print - static routes', t => { │ └── /hello (GET) └── hello/world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes', t => { @@ -51,8 +50,8 @@ test('pretty print - parametric routes', t => { └── hello/ └── :world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes', t => { @@ -79,8 +78,8 @@ test('pretty print - parametric routes', t => { └── :param └── /suffix1 (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes', t => { @@ -101,8 +100,8 @@ test('pretty print - parametric routes', t => { ├── /:param1(123).:param2(456)/suffix4 (GET) └── /:param/suffix1 (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - mixed parametric routes', t => { @@ -122,8 +121,8 @@ test('pretty print - mixed parametric routes', t => { └── :hello (GET, POST) └── /world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - wildcard routes', t => { @@ -143,8 +142,8 @@ test('pretty print - wildcard routes', t => { └── hello/ └── * (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - parametric routes with same parent and followed by a static route which has the same prefix with the former routes', t => { @@ -165,8 +164,8 @@ test('pretty print - parametric routes with same parent and followed by a static │ └── :id (GET, POST) └── world (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - constrained parametric routes', t => { @@ -189,8 +188,8 @@ test('pretty print - constrained parametric routes', t => { :hello (GET) {"version":"1.1.2"} :hello (GET) {"version":"2.0.0"} ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - multiple parameters are drawn appropriately', t => { @@ -210,8 +209,8 @@ test('pretty print - multiple parameters are drawn appropriately', t => { └── /:hello/there/:ladies (GET) └── /and/:gents (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print - multiple parameters are drawn appropriately', t => { @@ -231,8 +230,8 @@ test('pretty print - multiple parameters are drawn appropriately', t => { └── /:hello/there/:ladies (GET) └── /and/:gents (GET) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) test('pretty print commonPrefix - use routes array to draw flattened routes', t => { @@ -267,11 +266,11 @@ test('pretty print commonPrefix - use routes array to draw flattened routes', t └── /update (PUT) ` - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixExpected) - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) }) test('pretty print commonPrefix - handle wildcard root', t => { @@ -293,8 +292,8 @@ test('pretty print commonPrefix - handle wildcard root', t => { ├── /update (PUT) └── * (OPTIONS) ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) }) test('pretty print commonPrefix - handle wildcard root', t => { @@ -320,8 +319,8 @@ test('pretty print commonPrefix - handle wildcard root', t => { │ └── update (PUT) └── * (GET) ` - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixExpected) }) test('pretty print commonPrefix - handle constrained routes', t => { @@ -344,8 +343,8 @@ test('pretty print commonPrefix - handle constrained routes', t => { /:hello (GET) {"version":"1.1.2"} /:hello (GET) {"version":"2.0.0"} ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) }) test('pretty print commonPrefix - handle method constraint', t => { @@ -384,8 +383,8 @@ test('pretty print commonPrefix - handle method constraint', t => { /:hello (GET) {"method":"bar"} /:hello (GET) {"method":"baz"} ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) }) test('pretty print includeMeta - commonPrefix: true', t => { @@ -486,14 +485,14 @@ test('pretty print includeMeta - commonPrefix: true', t => { └── :hello (GET) {"version":"1.1.2"} :hello (GET) {"version":"2.0.0"} ` - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixTreeExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixTreeExpected) - t.equal(typeof radixTreeSpecific, 'string') - t.equal(radixTreeSpecific, radixTreeSpecificExpected) + t.assert.equal(typeof radixTreeSpecific, 'string') + t.assert.equal(radixTreeSpecific, radixTreeSpecificExpected) - t.equal(typeof radixTreeNoMeta, 'string') - t.equal(radixTreeNoMeta, radixTreeNoMetaExpected) + t.assert.equal(typeof radixTreeNoMeta, 'string') + t.assert.equal(radixTreeNoMeta, radixTreeNoMetaExpected) }) test('pretty print includeMeta - commonPrefix: false', t => { @@ -585,14 +584,14 @@ test('pretty print includeMeta - commonPrefix: false', t => { /:hello (GET) {"version":"2.0.0"} ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) - t.equal(typeof arraySpecific, 'string') - t.equal(arraySpecific, arraySpecificExpected) + t.assert.equal(typeof arraySpecific, 'string') + t.assert.equal(arraySpecific, arraySpecificExpected) - t.equal(typeof arrayNoMeta, 'string') - t.equal(arrayNoMeta, arrayNoMetaExpected) + t.assert.equal(typeof arrayNoMeta, 'string') + t.assert.equal(arrayNoMeta, arrayNoMetaExpected) }) test('pretty print includeMeta - buildPrettyMeta function', t => { @@ -655,11 +654,11 @@ test('pretty print includeMeta - buildPrettyMeta function', t => { :hello (GET) {"version":"2.0.0"} • (metaKey) "/test/:hello" ` - t.equal(typeof arrayTree, 'string') - t.equal(arrayTree, arrayExpected) + t.assert.equal(typeof arrayTree, 'string') + t.assert.equal(arrayTree, arrayExpected) - t.equal(typeof radixTree, 'string') - t.equal(radixTree, radixExpected) + t.assert.equal(typeof radixTree, 'string') + t.assert.equal(radixTree, radixExpected) }) test('pretty print - print all methods', t => { @@ -676,6 +675,6 @@ M-SEARCH, MERGE, MKACTIVITY, MKCALENDAR, MKCOL, MOVE, NOTIFY, OPTIONS, PATCH, \ POST, PROPFIND, PROPPATCH, PURGE, PUT, QUERY, REBIND, REPORT, SEARCH, SOURCE, \ SUBSCRIBE, TRACE, UNBIND, UNLINK, UNLOCK, UNSUBSCRIBE) ` - t.equal(typeof tree, 'string') - t.equal(tree, expected) + t.assert.equal(typeof tree, 'string') + t.assert.equal(tree, expected) }) diff --git a/test/querystring.test.js b/test/querystring.test.js index e03020d6..01f0884c 100644 --- a/test/querystring.test.js +++ b/test/querystring.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('should sanitize the url - query', t => { @@ -9,8 +8,8 @@ test('should sanitize the url - query', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test', (req, res, params, store, query) => { - t.same(query, { hello: 'world' }) - t.ok('inside the handler') + t.assert.deepEqual(query, { hello: 'world' }) + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: 'GET', url: '/test?hello=world', headers: {} }, null) @@ -21,8 +20,8 @@ test('should sanitize the url - hash', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test', (req, res, params, store, query) => { - t.same(query, { hello: '' }) - t.ok('inside the handler') + t.assert.deepEqual(query, { hello: '' }) + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: 'GET', url: '/test#hello', headers: {} }, null) @@ -35,8 +34,8 @@ test('handles path and query separated by ; with useSemicolonDelimiter enabled', }) findMyWay.on('GET', '/test', (req, res, params, store, query) => { - t.same(query, { jsessionid: '123456' }) - t.ok('inside the handler') + t.assert.deepEqual(query, { jsessionid: '123456' }) + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: 'GET', url: '/test;jsessionid=123456', headers: {} }, null) @@ -47,8 +46,8 @@ test('handles path and query separated by ? using ; in the path', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test;jsessionid=123456', (req, res, params, store, query) => { - t.same(query, { foo: 'bar' }) - t.ok('inside the handler') + t.assert.deepEqual(query, { foo: 'bar' }) + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: 'GET', url: '/test;jsessionid=123456?foo=bar', headers: {} }, null) diff --git a/test/regex.test.js b/test/regex.test.js index 77f88c86..104f0902 100644 --- a/test/regex.test.js +++ b/test/regex.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('route with matching regex', t => { @@ -13,7 +12,7 @@ test('route with matching regex', t => { }) findMyWay.on('GET', '/test/:id(^\\d+$)', () => { - t.ok('regex match') + t.assert.ok('regex match') }) findMyWay.lookup({ method: 'GET', url: '/test/12', headers: {} }, null) @@ -23,7 +22,7 @@ test('route without matching regex', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) @@ -42,10 +41,10 @@ test('route with an extension regex 2', t => { } }) findMyWay.on('GET', '/test/S/:file(^\\S+).png', () => { - t.ok('regex match') + t.assert.ok('regex match') }) findMyWay.on('GET', '/test/D/:file(^\\D+).png', () => { - t.ok('regex match') + t.assert.ok('regex match') }) findMyWay.lookup({ method: 'GET', url: '/test/S/foo.png', headers: {} }, null) findMyWay.lookup({ method: 'GET', url: '/test/D/foo.png', headers: {} }, null) @@ -60,7 +59,7 @@ test('nested route with matching regex', t => { }) findMyWay.on('GET', '/test/:id(^\\d+$)/hello', () => { - t.ok('regex match') + t.assert.ok('regex match') }) findMyWay.lookup({ method: 'GET', url: '/test/12/hello', headers: {} }, null) @@ -75,8 +74,8 @@ test('mixed nested route with matching regex', t => { }) findMyWay.on('GET', '/test/:id(^\\d+$)/hello/:world', (req, res, params) => { - t.equal(params.id, '12') - t.equal(params.world, 'world') + t.assert.equal(params.id, '12') + t.assert.equal(params.world, 'world') }) findMyWay.lookup({ method: 'GET', url: '/test/12/hello/world', headers: {} }, null) @@ -91,8 +90,8 @@ test('mixed nested route with double matching regex', t => { }) findMyWay.on('GET', '/test/:id(^\\d+$)/hello/:world(^\\d+$)', (req, res, params) => { - t.equal(params.id, '12') - t.equal(params.world, '15') + t.assert.equal(params.id, '12') + t.assert.equal(params.world, '15') }) findMyWay.lookup({ method: 'GET', url: '/test/12/hello/15', headers: {} }, null) @@ -102,7 +101,7 @@ test('mixed nested route without double matching regex', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) @@ -122,7 +121,7 @@ test('route with an extension regex', t => { }) findMyWay.on('GET', '/test/:file(^\\d+).png', () => { - t.ok('regex match') + t.assert.ok('regex match') }) findMyWay.lookup({ method: 'GET', url: '/test/12.png', headers: {} }, null) @@ -132,7 +131,7 @@ test('route with an extension regex - no match', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) @@ -147,7 +146,7 @@ test('safe decodeURIComponent', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) @@ -155,7 +154,7 @@ test('safe decodeURIComponent', t => { t.fail('we should not be here') }) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/hel%"Flo', {}), null ) @@ -191,7 +190,7 @@ test('Should check if a regex is safe to use', t => { good.forEach(regex => { try { findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop) - t.pass('ok') + t.assert.ok('ok') findMyWay.off('GET', `/test/:id(${regex.toString()})`) } catch (err) { t.fail(err) @@ -203,7 +202,7 @@ test('Should check if a regex is safe to use', t => { findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop) t.fail('should throw') } catch (err) { - t.ok(err) + t.assert.ok(err) } }) }) @@ -238,7 +237,7 @@ test('Disable safe regex check', t => { good.forEach(regex => { try { findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop) - t.pass('ok') + t.assert.ok('ok') findMyWay.off('GET', `/test/:id(${regex.toString()})`) } catch (err) { t.fail(err) @@ -248,7 +247,7 @@ test('Disable safe regex check', t => { bad.forEach(regex => { try { findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop) - t.pass('ok') + t.assert.ok('ok') findMyWay.off('GET', `/test/:id(${regex.toString()})`) } catch (err) { t.fail(err) diff --git a/test/routes-registered.test.js b/test/routes-registered.test.js index 354a1a03..46b93f4b 100644 --- a/test/routes-registered.test.js +++ b/test/routes-registered.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('tap') +const { test } = require('node:test') const FindMyWay = require('../') function initializeRoutes (router, handler, quantity) { @@ -19,7 +19,7 @@ test('verify routes registered', t => { const defaultHandler = (req, res, params) => res.end(JSON.stringify({ hello: 'world' })) findMyWay = initializeRoutes(findMyWay, defaultHandler, quantity) - t.equal(findMyWay.routes.length, quantity) + t.assert.equal(findMyWay.routes.length, quantity) findMyWay.routes.forEach((route, idx) => { t.match(route, { method: 'GET', @@ -40,7 +40,7 @@ test('verify routes registered and deregister', t => { const defaultHandler = (req, res, params) => res.end(JSON.stringify({ hello: 'world' })) findMyWay = initializeRoutes(findMyWay, defaultHandler, quantity) - t.equal(findMyWay.routes.length, quantity) + t.assert.equal(findMyWay.routes.length, quantity) findMyWay.off('GET', '/test-route-0') - t.equal(findMyWay.routes.length, quantity - 1) + t.assert.equal(findMyWay.routes.length, quantity - 1) }) diff --git a/test/server.test.js b/test/server.test.js index 2dbcd05d..63285154 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const http = require('http') const FindMyWay = require('../') @@ -9,9 +8,9 @@ test('basic router with http server', t => { t.plan(6) const findMyWay = FindMyWay() findMyWay.on('GET', '/test', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end(JSON.stringify({ hello: 'world' })) }) @@ -28,8 +27,8 @@ test('basic router with http server', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(JSON.parse(body), { hello: 'world' }) + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -38,9 +37,9 @@ test('router with params with http server', t => { t.plan(6) const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:id', (req, res, params) => { - t.ok(req) - t.ok(res) - t.equal(params.id, 'hello') + t.assert.ok(req) + t.assert.ok(res) + t.assert.equal(params.id, 'hello') res.end(JSON.stringify({ hello: 'world' })) }) @@ -57,8 +56,8 @@ test('router with params with http server', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(JSON.parse(body), { hello: 'world' }) + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(JSON.parse(body), { hello: 'world' }) }) }) }) @@ -81,7 +80,7 @@ test('default route', t => { server.unref() http.get('http://localhost:' + server.address().port, async (res) => { - t.equal(res.statusCode, 404) + t.assert.equal(res.statusCode, 404) }) }) }) @@ -99,7 +98,7 @@ test('automatic default route', t => { server.unref() http.get('http://localhost:' + server.address().port, async (res) => { - t.equal(res.statusCode, 404) + t.assert.equal(res.statusCode, 404) }) }) }) @@ -111,16 +110,16 @@ test('maps two routes when trailing slash should be trimmed', t => { }) findMyWay.on('GET', '/test/', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('test') }) findMyWay.on('GET', '/othertest', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('othertest') }) @@ -139,8 +138,8 @@ test('maps two routes when trailing slash should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '/test', async (res) => { @@ -148,8 +147,8 @@ test('maps two routes when trailing slash should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '/othertest', async (res) => { @@ -157,8 +156,8 @@ test('maps two routes when trailing slash should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'othertest') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'othertest') }) http.get(baseURL + '/othertest/', async (res) => { @@ -166,8 +165,8 @@ test('maps two routes when trailing slash should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'othertest') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'othertest') }) }) }) @@ -179,9 +178,9 @@ test('does not trim trailing slash when ignoreTrailingSlash is false', t => { }) findMyWay.on('GET', '/test/', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('test') }) @@ -200,12 +199,12 @@ test('does not trim trailing slash when ignoreTrailingSlash is false', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '/test', async (res) => { - t.equal(res.statusCode, 404) + t.assert.equal(res.statusCode, 404) }) }) }) @@ -217,9 +216,9 @@ test('does not map // when ignoreTrailingSlash is true', t => { }) findMyWay.on('GET', '/', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('test') }) @@ -238,12 +237,12 @@ test('does not map // when ignoreTrailingSlash is true', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '//', async (res) => { - t.equal(res.statusCode, 404) + t.assert.equal(res.statusCode, 404) }) }) }) @@ -255,16 +254,16 @@ test('maps two routes when duplicate slashes should be trimmed', t => { }) findMyWay.on('GET', '//test', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('test') }) findMyWay.on('GET', '/othertest', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('othertest') }) @@ -283,8 +282,8 @@ test('maps two routes when duplicate slashes should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '/test', async (res) => { @@ -292,8 +291,8 @@ test('maps two routes when duplicate slashes should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '/othertest', async (res) => { @@ -301,8 +300,8 @@ test('maps two routes when duplicate slashes should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'othertest') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'othertest') }) http.get(baseURL + '//othertest', async (res) => { @@ -310,8 +309,8 @@ test('maps two routes when duplicate slashes should be trimmed', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'othertest') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'othertest') }) }) }) @@ -323,9 +322,9 @@ test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', t = }) findMyWay.on('GET', '//test', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('test') }) @@ -344,12 +343,12 @@ test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', t = for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '/test', async (res) => { - t.equal(res.statusCode, 404) + t.assert.equal(res.statusCode, 404) }) }) }) @@ -361,9 +360,9 @@ test('does map // when ignoreDuplicateSlashes is true', t => { }) findMyWay.on('GET', '/', (req, res, params) => { - t.ok(req) - t.ok(res) - t.ok(params) + t.assert.ok(req) + t.assert.ok(res) + t.assert.ok(params) res.end('test') }) @@ -382,8 +381,8 @@ test('does map // when ignoreDuplicateSlashes is true', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) http.get(baseURL + '//', async (res) => { @@ -391,8 +390,8 @@ test('does map // when ignoreDuplicateSlashes is true', t => { for await (const chunk of res) { body += chunk } - t.equal(res.statusCode, 200) - t.same(body, 'test') + t.assert.equal(res.statusCode, 200) + t.assert.deepEqual(body, 'test') }) }) }) @@ -420,7 +419,7 @@ test('versioned routes', t => { headers: { 'Accept-Version': '1.x' } }, async (res) => { - t.equal(res.statusCode, 200) + t.assert.equal(res.statusCode, 200) } ) @@ -430,7 +429,7 @@ test('versioned routes', t => { headers: { 'Accept-Version': '2.x' } }, async (res) => { - t.equal(res.statusCode, 404) + t.assert.equal(res.statusCode, 404) } ) }) diff --git a/test/shorthands.test.js b/test/shorthands.test.js index 8bb513b0..f8e2d965 100644 --- a/test/shorthands.test.js +++ b/test/shorthands.test.js @@ -1,8 +1,7 @@ 'use strict' const httpMethods = require('../lib/http-methods') -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') t.test('should support shorthand', t => { @@ -17,7 +16,7 @@ t.test('should support shorthand', t => { const findMyWay = FindMyWay() findMyWay[methodName]('/test', () => { - t.ok('inside the handler') + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: m, url: '/test', headers: {} }, null) @@ -30,7 +29,7 @@ test('should support `.all` shorthand', t => { const findMyWay = FindMyWay() findMyWay.all('/test', () => { - t.ok('inside the handler') + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) diff --git a/test/store.test.js b/test/store.test.js index 7f205892..7f1aff38 100644 --- a/test/store.test.js +++ b/test/store.test.js @@ -1,7 +1,6 @@ 'use strict' -const t = require('tap') -const test = t.test +const {test} = require('node:test') const FindMyWay = require('../') test('handler should have the store object', t => { @@ -9,7 +8,7 @@ test('handler should have the store object', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test', (req, res, params, store) => { - t.equal(store.hello, 'world') + t.assert.equal(store.hello, 'world') }, { hello: 'world' }) findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) @@ -22,7 +21,7 @@ test('find a store object', t => { findMyWay.on('GET', '/test', fn, { hello: 'world' }) - t.same(findMyWay.find('GET', '/test'), { + t.assert.deepEqual(findMyWay.find('GET', '/test'), { handler: fn, params: {}, store: { hello: 'world' }, @@ -37,12 +36,12 @@ test('update the store', t => { findMyWay.on('GET', '/test', (req, res, params, store) => { if (!bool) { - t.equal(store.hello, 'world') + t.assert.equal(store.hello, 'world') store.hello = 'hello' bool = true findMyWay.lookup({ method: 'GET', url: '/test', headers: {} }, null) } else { - t.equal(store.hello, 'hello') + t.assert.equal(store.hello, 'hello') } }, { hello: 'world' }) From 7002d169b02fb4fb1ee5125c0454076f4e9a3892 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:29:51 +0100 Subject: [PATCH 02/26] fix: lint --- test/case-insensitive.test.js | 2 +- test/constraint.custom-versioning.test.js | 2 +- test/constraint.custom.async.test.js | 2 +- test/constraint.custom.test.js | 2 +- test/constraint.default-versioning.test.js | 2 +- test/constraint.host.test.js | 2 +- test/constraints.test.js | 2 +- test/custom-querystring-parser.test.js | 2 +- test/errors.test.js | 2 +- test/fastify-issue-3129.test.js | 2 +- test/fastify-issue-3957.test.js | 2 +- test/find-route.test.js | 2 +- test/find.test.js | 2 +- test/has-route.test.js | 2 +- test/http2/constraint.host.test.js | 2 +- test/issue-101.test.js | 2 +- test/issue-104.test.js | 2 +- test/issue-110.test.js | 2 +- test/issue-132.test.js | 2 +- test/issue-149.test.js | 2 +- test/issue-151.test.js | 2 +- test/issue-154.test.js | 2 +- test/issue-161.test.js | 2 +- test/issue-17.test.js | 2 +- test/issue-175.test.js | 2 +- test/issue-182.test.js | 2 +- test/issue-20.test.js | 2 +- test/issue-206.test.js | 2 +- test/issue-221.test.js | 2 +- test/issue-234.test.js | 2 +- test/issue-238.test.js | 2 +- test/issue-241.test.js | 2 +- test/issue-247.test.js | 2 +- test/issue-254.test.js | 2 +- test/issue-28.test.js | 2 +- test/issue-280.test.js | 2 +- test/issue-285.test.js | 2 +- test/issue-330.test.js | 2 +- test/issue-44.test.js | 2 +- test/issue-46.test.js | 2 +- test/issue-49.test.js | 2 +- test/issue-59.test.js | 2 +- test/issue-67.test.js | 2 +- test/issue-93.test.js | 2 +- test/lookup-async.test.js | 2 +- test/lookup.test.js | 2 +- test/matching-order.test.js | 2 +- test/max-param-length.test.js | 2 +- test/methods.test.js | 2 +- test/on-bad-url.test.js | 2 +- test/optional-params.test.js | 2 +- test/params-collisions.test.js | 2 +- test/path-params-match.test.js | 2 +- test/pretty-print-tree.test.js | 2 +- test/pretty-print.test.js | 2 +- test/querystring.test.js | 2 +- test/regex.test.js | 2 +- test/server.test.js | 2 +- test/shorthands.test.js | 2 +- test/store.test.js | 2 +- 60 files changed, 60 insertions(+), 60 deletions(-) diff --git a/test/case-insensitive.test.js b/test/case-insensitive.test.js index a1e5d6cb..c4bdd0ac 100644 --- a/test/case-insensitive.test.js +++ b/test/case-insensitive.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('case insensitive static routes of level 1', t => { diff --git a/test/constraint.custom-versioning.test.js b/test/constraint.custom-versioning.test.js index e2e2c578..bff1c3f6 100644 --- a/test/constraint.custom-versioning.test.js +++ b/test/constraint.custom-versioning.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const noop = () => { } diff --git a/test/constraint.custom.async.test.js b/test/constraint.custom.async.test.js index 36c783c1..4cfe2b35 100644 --- a/test/constraint.custom.async.test.js +++ b/test/constraint.custom.async.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const rfdc = require('rfdc')({ proto: true }) diff --git a/test/constraint.custom.test.js b/test/constraint.custom.test.js index aae01cf1..91aa5548 100644 --- a/test/constraint.custom.test.js +++ b/test/constraint.custom.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const alpha = () => { } const beta = () => { } diff --git a/test/constraint.default-versioning.test.js b/test/constraint.default-versioning.test.js index 1bc34664..e152e81c 100644 --- a/test/constraint.default-versioning.test.js +++ b/test/constraint.default-versioning.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const noop = () => { } diff --git a/test/constraint.host.test.js b/test/constraint.host.test.js index b6c426a5..5c347032 100644 --- a/test/constraint.host.test.js +++ b/test/constraint.host.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const alpha = () => { } const beta = () => { } diff --git a/test/constraints.test.js b/test/constraints.test.js index 52774fba..67bf8d81 100644 --- a/test/constraints.test.js +++ b/test/constraints.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const alpha = () => { } const beta = () => { } diff --git a/test/custom-querystring-parser.test.js b/test/custom-querystring-parser.test.js index f74b766c..e2bd620a 100644 --- a/test/custom-querystring-parser.test.js +++ b/test/custom-querystring-parser.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const querystring = require('fast-querystring') const FindMyWay = require('../') diff --git a/test/errors.test.js b/test/errors.test.js index 07e2a67c..480fde54 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Method should be a string', t => { diff --git a/test/fastify-issue-3129.test.js b/test/fastify-issue-3129.test.js index 1a3cdaa2..66f46ed2 100644 --- a/test/fastify-issue-3129.test.js +++ b/test/fastify-issue-3129.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('contain param and wildcard together', t => { diff --git a/test/fastify-issue-3957.test.js b/test/fastify-issue-3957.test.js index ca26787c..90b13ea9 100644 --- a/test/fastify-issue-3957.test.js +++ b/test/fastify-issue-3957.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('wildcard should not limit by maxParamLength', t => { diff --git a/test/find-route.test.js b/test/find-route.test.js index e522fbd9..6fe32bfb 100644 --- a/test/find-route.test.js +++ b/test/find-route.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const rfdc = require('rfdc')({ proto: true }) const FindMyWay = require('..') diff --git a/test/find.test.js b/test/find.test.js index 812b8f5a..8dade0b6 100644 --- a/test/find.test.js +++ b/test/find.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('find calls can pass no constraints', t => { diff --git a/test/has-route.test.js b/test/has-route.test.js index df91288d..035300bf 100644 --- a/test/has-route.test.js +++ b/test/has-route.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const rfdc = require('rfdc')({ proto: true }) const FindMyWay = require('..') diff --git a/test/http2/constraint.host.test.js b/test/http2/constraint.host.test.js index 788ae8de..4cf11131 100644 --- a/test/http2/constraint.host.test.js +++ b/test/http2/constraint.host.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../..') test('A route supports host constraints under http2 protocol', t => { diff --git a/test/issue-101.test.js b/test/issue-101.test.js index 8c1b46af..dc465708 100644 --- a/test/issue-101.test.js +++ b/test/issue-101.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Falling back for node\'s parametric brother', t => { diff --git a/test/issue-104.test.js b/test/issue-104.test.js index c4bf9f57..46037db1 100644 --- a/test/issue-104.test.js +++ b/test/issue-104.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Nested static parametric route, url with parameter common prefix > 1', t => { diff --git a/test/issue-110.test.js b/test/issue-110.test.js index b7481379..5dccbe31 100644 --- a/test/issue-110.test.js +++ b/test/issue-110.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Nested static parametric route, url with parameter common prefix > 1', t => { diff --git a/test/issue-132.test.js b/test/issue-132.test.js index c6bda442..0e7e66cd 100644 --- a/test/issue-132.test.js +++ b/test/issue-132.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Wildcard mixed with dynamic and common prefix / 1', t => { diff --git a/test/issue-149.test.js b/test/issue-149.test.js index 3feaf2dc..559949e6 100644 --- a/test/issue-149.test.js +++ b/test/issue-149.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Falling back for node\'s parametric brother', t => { diff --git a/test/issue-151.test.js b/test/issue-151.test.js index 2a508b5c..56770717 100644 --- a/test/issue-151.test.js +++ b/test/issue-151.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Wildcard route should not be blocked by Parametric with different method / 1', t => { diff --git a/test/issue-154.test.js b/test/issue-154.test.js index a586cec6..a4d36c20 100644 --- a/test/issue-154.test.js +++ b/test/issue-154.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const noop = () => {} diff --git a/test/issue-161.test.js b/test/issue-161.test.js index 0b6d662d..a7f4b44f 100644 --- a/test/issue-161.test.js +++ b/test/issue-161.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Falling back for node\'s parametric brother without ignoreTrailingSlash', t => { diff --git a/test/issue-17.test.js b/test/issue-17.test.js index 20a7ccbf..ed25b04f 100644 --- a/test/issue-17.test.js +++ b/test/issue-17.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Parametric route, request.url contains dash', t => { diff --git a/test/issue-175.test.js b/test/issue-175.test.js index 98d9048c..6b98bae6 100644 --- a/test/issue-175.test.js +++ b/test/issue-175.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('double colon is replaced with single colon, no parameters', t => { diff --git a/test/issue-182.test.js b/test/issue-182.test.js index af4c5703..38be9d07 100644 --- a/test/issue-182.test.js +++ b/test/issue-182.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('Set method property when splitting node', t => { diff --git a/test/issue-20.test.js b/test/issue-20.test.js index ab9eb032..70b3d7b7 100644 --- a/test/issue-20.test.js +++ b/test/issue-20.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Standard case', t => { diff --git a/test/issue-206.test.js b/test/issue-206.test.js index 6946bfad..7e9964a4 100644 --- a/test/issue-206.test.js +++ b/test/issue-206.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('Decode the URL before the routing', t => { diff --git a/test/issue-221.test.js b/test/issue-221.test.js index c992afce..13d324f6 100644 --- a/test/issue-221.test.js +++ b/test/issue-221.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('Should return correct param after switching from static route', t => { diff --git a/test/issue-234.test.js b/test/issue-234.test.js index fae2bf70..1406b511 100644 --- a/test/issue-234.test.js +++ b/test/issue-234.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('Match static url without encoding option', t => { diff --git a/test/issue-238.test.js b/test/issue-238.test.js index 58e53978..d1ea3730 100644 --- a/test/issue-238.test.js +++ b/test/issue-238.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Multi-parametric tricky path', t => { diff --git a/test/issue-241.test.js b/test/issue-241.test.js index 0b781594..39b007a0 100644 --- a/test/issue-241.test.js +++ b/test/issue-241.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('Double colon and parametric children', t => { diff --git a/test/issue-247.test.js b/test/issue-247.test.js index 6ed89efd..e5a99f03 100644 --- a/test/issue-247.test.js +++ b/test/issue-247.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('If there are constraints param, router.off method support filter', t => { diff --git a/test/issue-254.test.js b/test/issue-254.test.js index 090217db..9e6b4626 100644 --- a/test/issue-254.test.js +++ b/test/issue-254.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('Constraints should not be overrided when multiple router is created', t => { diff --git a/test/issue-28.test.js b/test/issue-28.test.js index 49982c34..80a2f482 100644 --- a/test/issue-28.test.js +++ b/test/issue-28.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('wildcard (more complex test)', t => { diff --git a/test/issue-280.test.js b/test/issue-280.test.js index 23fdba3e..b05fda82 100644 --- a/test/issue-280.test.js +++ b/test/issue-280.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Wildcard route match when regexp route fails', (t) => { diff --git a/test/issue-285.test.js b/test/issue-285.test.js index 3c756b4b..2fa564fd 100644 --- a/test/issue-285.test.js +++ b/test/issue-285.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Parametric regex match with similar routes', (t) => { diff --git a/test/issue-330.test.js b/test/issue-330.test.js index 5dc8cbf1..56ddf205 100644 --- a/test/issue-330.test.js +++ b/test/issue-330.test.js @@ -1,4 +1,4 @@ -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') const proxyquire = require('proxyquire') const HandlerStorage = require('../lib/handler-storage') diff --git a/test/issue-44.test.js b/test/issue-44.test.js index 6d13e530..e8ff5643 100644 --- a/test/issue-44.test.js +++ b/test/issue-44.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Parametric and static with shared prefix / 1', t => { diff --git a/test/issue-46.test.js b/test/issue-46.test.js index 9b4f7fb3..ef5cf231 100644 --- a/test/issue-46.test.js +++ b/test/issue-46.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('If the prefixLen is higher than the pathLen we should not save the wildcard child', t => { diff --git a/test/issue-49.test.js b/test/issue-49.test.js index 4719c360..cf5430d7 100644 --- a/test/issue-49.test.js +++ b/test/issue-49.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') const noop = () => {} diff --git a/test/issue-59.test.js b/test/issue-59.test.js index 66b68047..a9858581 100644 --- a/test/issue-59.test.js +++ b/test/issue-59.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') const noop = () => {} diff --git a/test/issue-67.test.js b/test/issue-67.test.js index 9e38bdc0..ac9cf59a 100644 --- a/test/issue-67.test.js +++ b/test/issue-67.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') const noop = () => {} diff --git a/test/issue-93.test.js b/test/issue-93.test.js index 3255ef41..6e57d81d 100644 --- a/test/issue-93.test.js +++ b/test/issue-93.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') const noop = () => {} diff --git a/test/lookup-async.test.js b/test/lookup-async.test.js index 20a805c0..e1ba2c5e 100644 --- a/test/lookup-async.test.js +++ b/test/lookup-async.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('should return result in the done callback', t => { diff --git a/test/lookup.test.js b/test/lookup.test.js index d6ad0888..f7bfa020 100644 --- a/test/lookup.test.js +++ b/test/lookup.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('lookup calls route handler with no context', t => { diff --git a/test/matching-order.test.js b/test/matching-order.test.js index 87fbe367..1f7cb952 100644 --- a/test/matching-order.test.js +++ b/test/matching-order.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('Matching order', t => { diff --git a/test/max-param-length.test.js b/test/max-param-length.test.js index 46c30079..9e397d1e 100644 --- a/test/max-param-length.test.js +++ b/test/max-param-length.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('maxParamLength default value is 500', t => { diff --git a/test/methods.test.js b/test/methods.test.js index 64794345..dfcedf25 100644 --- a/test/methods.test.js +++ b/test/methods.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('the router is an object with methods', t => { diff --git a/test/on-bad-url.test.js b/test/on-bad-url.test.js index 920d137c..32e55cd4 100644 --- a/test/on-bad-url.test.js +++ b/test/on-bad-url.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('If onBadUrl is defined, then a bad url should be handled differently (find)', t => { diff --git a/test/optional-params.test.js b/test/optional-params.test.js index 0390d878..d1c481b4 100644 --- a/test/optional-params.test.js +++ b/test/optional-params.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('Test route with optional parameter', (t) => { diff --git a/test/params-collisions.test.js b/test/params-collisions.test.js index b1c163f9..c9ff622e 100644 --- a/test/params-collisions.test.js +++ b/test/params-collisions.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('..') test('should setup parametric and regexp node', t => { diff --git a/test/path-params-match.test.js b/test/path-params-match.test.js index 6f635897..3978017d 100644 --- a/test/path-params-match.test.js +++ b/test/path-params-match.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('path params match', (t) => { diff --git a/test/pretty-print-tree.test.js b/test/pretty-print-tree.test.js index 70ffdaac..39f49fd7 100644 --- a/test/pretty-print-tree.test.js +++ b/test/pretty-print-tree.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('pretty print - empty tree', t => { diff --git a/test/pretty-print.test.js b/test/pretty-print.test.js index 8e4c8a15..d02e8d43 100644 --- a/test/pretty-print.test.js +++ b/test/pretty-print.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('pretty print - empty tree', t => { diff --git a/test/querystring.test.js b/test/querystring.test.js index 01f0884c..5b89521d 100644 --- a/test/querystring.test.js +++ b/test/querystring.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('should sanitize the url - query', t => { diff --git a/test/regex.test.js b/test/regex.test.js index 104f0902..b5a18c6a 100644 --- a/test/regex.test.js +++ b/test/regex.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('route with matching regex', t => { diff --git a/test/server.test.js b/test/server.test.js index 63285154..9d3881e6 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const http = require('http') const FindMyWay = require('../') diff --git a/test/shorthands.test.js b/test/shorthands.test.js index f8e2d965..63170c8c 100644 --- a/test/shorthands.test.js +++ b/test/shorthands.test.js @@ -1,7 +1,7 @@ 'use strict' const httpMethods = require('../lib/http-methods') -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') t.test('should support shorthand', t => { diff --git a/test/store.test.js b/test/store.test.js index 7f1aff38..51ca8c54 100644 --- a/test/store.test.js +++ b/test/store.test.js @@ -1,6 +1,6 @@ 'use strict' -const {test} = require('node:test') +const { test } = require('node:test') const FindMyWay = require('../') test('handler should have the store object', t => { From bd62d5096ce28fd4317b8100e2ecf80d49f11cac Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:31:20 +0100 Subject: [PATCH 03/26] fix: lint --- test/full-url.test.js | 24 ++++++++++++------------ test/null-object.test.js | 2 +- test/shorthands.test.js | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/full-url.test.js b/test/full-url.test.js index 5674fbda..ba8b8c5b 100644 --- a/test/full-url.test.js +++ b/test/full-url.test.js @@ -3,21 +3,21 @@ const { test } = require('node:test') const FindMyWay = require('../') -const findMyWay = FindMyWay({ - defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') - } -}) +test('full-url', t => { + const findMyWay = FindMyWay({ + defaultRoute: (req, res) => { + t.assert.fail('Should not be defaultRoute') + } + }) -findMyWay.on('GET', '/a', (req, res) => { - res.end('{"message":"hello world"}') -}) + findMyWay.on('GET', '/a', (req, res) => { + res.end('{"message":"hello world"}') + }) -findMyWay.on('GET', '/a/:id', (req, res) => { - res.end('{"message":"hello world"}') -}) + findMyWay.on('GET', '/a/:id', (req, res) => { + res.end('{"message":"hello world"}') + }) -test('full-url', t => { t.assert.deepEqual(findMyWay.find('GET', 'http://localhost/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) t.assert.deepEqual(findMyWay.find('GET', 'http://localhost:8080/a', { host: 'localhost' }), findMyWay.find('GET', '/a', { host: 'localhost' })) t.assert.deepEqual(findMyWay.find('GET', 'http://123.123.123.123/a', {}), findMyWay.find('GET', '/a', {})) diff --git a/test/null-object.test.js b/test/null-object.test.js index 41bb5efc..6f225b16 100644 --- a/test/null-object.test.js +++ b/test/null-object.test.js @@ -30,7 +30,7 @@ test('has no methods from generic Object class', t => { const nullObject = new NullObject() for (const propertyName of propertyNames) { - t.assert.ok(!propertyName in nullObject, propertyName) + t.assert.ok(!(propertyName in nullObject), propertyName) } t.assert.equal(getAllPropertyNames(nullObject).length, 0) }) diff --git a/test/shorthands.test.js b/test/shorthands.test.js index 63170c8c..c1b3ef1e 100644 --- a/test/shorthands.test.js +++ b/test/shorthands.test.js @@ -4,7 +4,7 @@ const httpMethods = require('../lib/http-methods') const { test } = require('node:test') const FindMyWay = require('../') -t.test('should support shorthand', t => { +test('should support shorthand', t => { t.plan(httpMethods.length) for (const i in httpMethods) { From cefe5f4de0e9242e72961c8b430cf9035d89a75b Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:32:34 +0100 Subject: [PATCH 04/26] chore: assert fail --- test/case-insensitive.test.js | 24 ++-- test/constraint.default-versioning.test.js | 16 +-- test/errors.test.js | 80 ++++++------- test/fastify-issue-3129.test.js | 2 +- test/fastify-issue-3957.test.js | 2 +- test/issue-101.test.js | 2 +- test/issue-104.test.js | 12 +- test/issue-110.test.js | 2 +- test/issue-132.test.js | 4 +- test/issue-149.test.js | 2 +- test/issue-151.test.js | 12 +- test/issue-161.test.js | 8 +- test/issue-17.test.js | 40 +++---- test/issue-175.test.js | 12 +- test/issue-20.test.js | 10 +- test/issue-206.test.js | 2 +- test/issue-238.test.js | 10 +- test/issue-28.test.js | 132 ++++++++++----------- test/issue-44.test.js | 34 +++--- test/issue-46.test.js | 8 +- test/methods.test.js | 20 ++-- test/on-bad-url.test.js | 14 +-- test/optional-params.test.js | 20 ++-- test/regex.test.js | 30 ++--- 24 files changed, 249 insertions(+), 249 deletions(-) diff --git a/test/case-insensitive.test.js b/test/case-insensitive.test.js index c4bdd0ac..db73dc39 100644 --- a/test/case-insensitive.test.js +++ b/test/case-insensitive.test.js @@ -9,7 +9,7 @@ test('case insensitive static routes of level 1', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -26,7 +26,7 @@ test('case insensitive static routes of level 2', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -43,7 +43,7 @@ test('case insensitive static routes of level 3', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -60,7 +60,7 @@ test('parametric case insensitive', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -77,7 +77,7 @@ test('parametric case insensitive with a static part', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -94,7 +94,7 @@ test('parametric case insensitive with capital letter', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -111,7 +111,7 @@ test('case insensitive with capital letter in static path with param', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -132,7 +132,7 @@ test('case insensitive with multiple paths containing capital letter in static p const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -154,7 +154,7 @@ test('case insensitive with multiple mixed-case params within same slash couple' const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -172,7 +172,7 @@ test('case insensitive with multiple mixed-case params', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -190,7 +190,7 @@ test('case insensitive with wildcard', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -207,7 +207,7 @@ test('parametric case insensitive with multiple routes', t => { const findMyWay = FindMyWay({ caseSensitive: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/constraint.default-versioning.test.js b/test/constraint.default-versioning.test.js index e152e81c..08adf490 100644 --- a/test/constraint.default-versioning.test.js +++ b/test/constraint.default-versioning.test.js @@ -167,7 +167,7 @@ test('It should always choose the highest version of a route', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/', { constraints: { version: '2.3.0' } }, (req, res) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.on('GET', '/', { constraints: { version: '2.4.0' } }, (req, res) => { @@ -179,15 +179,15 @@ test('It should always choose the highest version of a route', t => { }) findMyWay.on('GET', '/', { constraints: { version: '3.2.0' } }, (req, res) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.on('GET', '/', { constraints: { version: '3.2.2' } }, (req, res) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.on('GET', '/', { constraints: { version: '4.4.0' } }, (req, res) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.on('GET', '/', { constraints: { version: '4.3.2' } }, (req, res) => { @@ -234,7 +234,7 @@ test('It should throw if you declare multiple times the same route', t => { try { findMyWay.on('GET', '/', { constraints: { version: '1.2.3' } }, noop) - t.fail('It should throw') + t.assert.fail('It should throw') } catch (err) { t.assert.equal(err.message, 'Method \'GET\' already declared for route \'/\' with constraints \'{"version":"1.2.3"}\'') } @@ -245,7 +245,7 @@ test('Versioning won\'t work if there are no versioned routes', t => { const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') } }) @@ -275,10 +275,10 @@ test('Unversioned routes aren\'t triggered when unknown versions are requested', }) findMyWay.on('GET', '/', (req, res) => { - t.fail('unversioned route shouldnt be hit!') + t.assert.fail('unversioned route shouldnt be hit!') }) findMyWay.on('GET', '/', { constraints: { version: '1.0.0' } }, (req, res) => { - t.fail('versioned route shouldnt be hit for wrong version!') + t.assert.fail('versioned route shouldnt be hit for wrong version!') }) findMyWay.lookup({ diff --git a/test/errors.test.js b/test/errors.test.js index 480fde54..08b752fa 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -9,7 +9,7 @@ test('Method should be a string', t => { try { findMyWay.on(0, '/test', () => {}) - t.fail('method shoukd be a string') + t.assert.fail('method shoukd be a string') } catch (e) { t.assert.equal(e.message, 'Method should be a string') } @@ -21,7 +21,7 @@ test('Method should be a string [ignoreTrailingSlash=true]', t => { try { findMyWay.on(0, '/test', () => {}) - t.fail('method shoukd be a string') + t.assert.fail('method shoukd be a string') } catch (e) { t.assert.equal(e.message, 'Method should be a string') } @@ -33,7 +33,7 @@ test('Method should be a string [ignoreDuplicateSlashes=true]', t => { try { findMyWay.on(0, '/test', () => {}) - t.fail('method shoukd be a string') + t.assert.fail('method shoukd be a string') } catch (e) { t.assert.equal(e.message, 'Method should be a string') } @@ -45,7 +45,7 @@ test('Method should be a string (array)', t => { try { findMyWay.on(['GET', 0], '/test', () => {}) - t.fail('method shoukd be a string') + t.assert.fail('method shoukd be a string') } catch (e) { t.assert.equal(e.message, 'Method should be a string') } @@ -57,7 +57,7 @@ test('Method should be a string (array) [ignoreTrailingSlash=true]', t => { try { findMyWay.on(['GET', 0], '/test', () => {}) - t.fail('method shoukd be a string') + t.assert.fail('method shoukd be a string') } catch (e) { t.assert.equal(e.message, 'Method should be a string') } @@ -69,7 +69,7 @@ test('Method should be a string (array) [ignoreDuplicateSlashes=true]', t => { try { findMyWay.on(['GET', 0], '/test', () => {}) - t.fail('method shoukd be a string') + t.assert.fail('method shoukd be a string') } catch (e) { t.assert.equal(e.message, 'Method should be a string') } @@ -81,7 +81,7 @@ test('Path should be a string', t => { try { findMyWay.on('GET', 0, () => {}) - t.fail('path should be a string') + t.assert.fail('path should be a string') } catch (e) { t.assert.equal(e.message, 'Path should be a string') } @@ -93,7 +93,7 @@ test('Path should be a string [ignoreTrailingSlash=true]', t => { try { findMyWay.on('GET', 0, () => {}) - t.fail('path should be a string') + t.assert.fail('path should be a string') } catch (e) { t.assert.equal(e.message, 'Path should be a string') } @@ -105,7 +105,7 @@ test('Path should be a string [ignoreDuplicateSlashes=true]', t => { try { findMyWay.on('GET', 0, () => {}) - t.fail('path should be a string') + t.assert.fail('path should be a string') } catch (e) { t.assert.equal(e.message, 'Path should be a string') } @@ -117,7 +117,7 @@ test('The path could not be empty', t => { try { findMyWay.on('GET', '', () => {}) - t.fail('The path could not be empty') + t.assert.fail('The path could not be empty') } catch (e) { t.assert.equal(e.message, 'The path could not be empty') } @@ -129,7 +129,7 @@ test('The path could not be empty [ignoreTrailingSlash=true]', t => { try { findMyWay.on('GET', '', () => {}) - t.fail('The path could not be empty') + t.assert.fail('The path could not be empty') } catch (e) { t.assert.equal(e.message, 'The path could not be empty') } @@ -141,7 +141,7 @@ test('The path could not be empty [ignoreDuplicateSlashes=true]', t => { try { findMyWay.on('GET', '', () => {}) - t.fail('The path could not be empty') + t.assert.fail('The path could not be empty') } catch (e) { t.assert.equal(e.message, 'The path could not be empty') } @@ -153,7 +153,7 @@ test('The first character of a path should be `/` or `*`', t => { try { findMyWay.on('GET', 'a', () => {}) - t.fail('The first character of a path should be `/` or `*`') + t.assert.fail('The first character of a path should be `/` or `*`') } catch (e) { t.assert.equal(e.message, 'The first character of a path should be `/` or `*`') } @@ -165,7 +165,7 @@ test('The first character of a path should be `/` or `*` [ignoreTrailingSlash=tr try { findMyWay.on('GET', 'a', () => {}) - t.fail('The first character of a path should be `/` or `*`') + t.assert.fail('The first character of a path should be `/` or `*`') } catch (e) { t.assert.equal(e.message, 'The first character of a path should be `/` or `*`') } @@ -177,7 +177,7 @@ test('The first character of a path should be `/` or `*` [ignoreDuplicateSlashes try { findMyWay.on('GET', 'a', () => {}) - t.fail('The first character of a path should be `/` or `*`') + t.assert.fail('The first character of a path should be `/` or `*`') } catch (e) { t.assert.equal(e.message, 'The first character of a path should be `/` or `*`') } @@ -189,7 +189,7 @@ test('Handler should be a function', t => { try { findMyWay.on('GET', '/test', 0) - t.fail('handler should be a function') + t.assert.fail('handler should be a function') } catch (e) { t.assert.equal(e.message, 'Handler should be a function') } @@ -201,7 +201,7 @@ test('Method is not an http method.', t => { try { findMyWay.on('GETT', '/test', () => {}) - t.fail('method is not a valid http method') + t.assert.fail('method is not a valid http method') } catch (e) { t.assert.equal(e.message, 'Method \'GETT\' is not an http method.') } @@ -213,7 +213,7 @@ test('Method is not an http method. (array)', t => { try { findMyWay.on(['POST', 'GETT'], '/test', () => {}) - t.fail('method is not a valid http method') + t.assert.fail('method is not a valid http method') } catch (e) { t.assert.equal(e.message, 'Method \'GETT\' is not an http method.') } @@ -225,7 +225,7 @@ test('The default route must be a function', t => { FindMyWay({ defaultRoute: '/404' }) - t.fail('default route must be a function') + t.assert.fail('default route must be a function') } catch (e) { t.assert.equal(e.message, 'The default route must be a function') } @@ -238,7 +238,7 @@ test('Method already declared', t => { findMyWay.on('GET', '/test', () => {}) try { findMyWay.on('GET', '/test', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } @@ -251,7 +251,7 @@ test('Method already declared if * is used', t => { findMyWay.on('GET', '/*', () => {}) try { findMyWay.on('GET', '*', () => {}) - t.fail('should throw error') + t.assert.fail('should throw error') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') } @@ -264,7 +264,7 @@ test('Method already declared if /* is used', t => { findMyWay.on('GET', '*', () => {}) try { findMyWay.on('GET', '/*', () => {}) - t.fail('should throw error') + t.assert.fail('should throw error') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') } @@ -281,14 +281,14 @@ test('Method already declared [ignoreTrailingSlash=true]', t => { try { findMyWay.on('GET', '/test', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } @@ -302,14 +302,14 @@ test('Method already declared [ignoreTrailingSlash=true]', t => { try { findMyWay.on('GET', '/test', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } @@ -327,14 +327,14 @@ test('Method already declared [ignoreDuplicateSlashes=true]', t => { try { findMyWay.on('GET', '/test', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '//test', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } @@ -348,14 +348,14 @@ test('Method already declared [ignoreDuplicateSlashes=true]', t => { try { findMyWay.on('GET', '/test', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } try { findMyWay.on('GET', '//test', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{}\'') } @@ -372,7 +372,7 @@ test('Method already declared nested route', t => { try { findMyWay.on('GET', '/test/hello', () => {}) - t.fail('method already delcared in nested route') + t.assert.fail('method already delcared in nested route') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } @@ -391,14 +391,14 @@ test('Method already declared nested route [ignoreTrailingSlash=true]', t => { try { findMyWay.on('GET', '/test/hello', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/hello/', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } @@ -411,7 +411,7 @@ test('Method already declared nested route [ignoreTrailingSlash=true]', t => { findMyWay.on('GET', '/test', { constraints: { host: 'fastify.io' } }, () => {}) try { findMyWay.on('GET', '/test', { constraints: { host: 'fastify.io' } }, () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test\' with constraints \'{"host":"fastify.io"}\'') } @@ -427,14 +427,14 @@ test('Method already declared nested route [ignoreTrailingSlash=true]', t => { try { findMyWay.on('GET', '/test/hello', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test/hello/', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } @@ -454,14 +454,14 @@ test('Method already declared nested route [ignoreDuplicateSlashes=true]', t => try { findMyWay.on('GET', '/test/hello', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test//hello', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } @@ -477,14 +477,14 @@ test('Method already declared nested route [ignoreDuplicateSlashes=true]', t => try { findMyWay.on('GET', '/test/hello', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } try { findMyWay.on('GET', '/test//hello', () => {}) - t.fail('method already declared') + t.assert.fail('method already declared') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/test/hello\' with constraints \'{}\'') } diff --git a/test/fastify-issue-3129.test.js b/test/fastify-issue-3129.test.js index 66f46ed2..b221b73e 100644 --- a/test/fastify-issue-3129.test.js +++ b/test/fastify-issue-3129.test.js @@ -8,7 +8,7 @@ test('contain param and wildcard together', t => { const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) diff --git a/test/fastify-issue-3957.test.js b/test/fastify-issue-3957.test.js index 90b13ea9..5bc7892d 100644 --- a/test/fastify-issue-3957.test.js +++ b/test/fastify-issue-3957.test.js @@ -8,7 +8,7 @@ test('wildcard should not limit by maxParamLength', t => { const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) diff --git a/test/issue-101.test.js b/test/issue-101.test.js index dc465708..51df3c0f 100644 --- a/test/issue-101.test.js +++ b/test/issue-101.test.js @@ -7,7 +7,7 @@ test('Falling back for node\'s parametric brother', t => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-104.test.js b/test/issue-104.test.js index 46037db1..78430e1e 100644 --- a/test/issue-104.test.js +++ b/test/issue-104.test.js @@ -7,7 +7,7 @@ test('Nested static parametric route, url with parameter common prefix > 1', t = t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -34,7 +34,7 @@ test('Parametric route, url with parameter common prefix > 1', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -61,7 +61,7 @@ test('Parametric route, url with multi parameter common prefix > 1', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -88,7 +88,7 @@ test('Mixed routes, url with parameter common prefix > 1', t => { t.plan(11) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -149,7 +149,7 @@ test('Parent parametric brother should not rewrite child node parametric brother t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -172,7 +172,7 @@ test('Mixed parametric routes, with last defined route being static', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-110.test.js b/test/issue-110.test.js index 5dccbe31..937585d7 100644 --- a/test/issue-110.test.js +++ b/test/issue-110.test.js @@ -7,7 +7,7 @@ test('Nested static parametric route, url with parameter common prefix > 1', t = t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-132.test.js b/test/issue-132.test.js index 0e7e66cd..74459f71 100644 --- a/test/issue-132.test.js +++ b/test/issue-132.test.js @@ -7,7 +7,7 @@ test('Wildcard mixed with dynamic and common prefix / 1', t => { t.plan(5) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -42,7 +42,7 @@ test('Wildcard mixed with dynamic and common prefix / 2', t => { t.plan(6) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-149.test.js b/test/issue-149.test.js index 559949e6..52ff04c9 100644 --- a/test/issue-149.test.js +++ b/test/issue-149.test.js @@ -7,7 +7,7 @@ test('Falling back for node\'s parametric brother', t => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-151.test.js b/test/issue-151.test.js index 56770717..71f0c052 100644 --- a/test/issue-151.test.js +++ b/test/issue-151.test.js @@ -7,12 +7,12 @@ test('Wildcard route should not be blocked by Parametric with different method / t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { - t.fail('Should not be here') + t.assert.fail('Should not be here') }) findMyWay.on('OPTIONS', '/obj/*', (req, res, params) => { @@ -20,7 +20,7 @@ test('Wildcard route should not be blocked by Parametric with different method / }) findMyWay.on('GET', '/obj/:id', (req, res, params) => { - t.fail('Should not be GET') + t.assert.fail('Should not be GET') }) findMyWay.lookup({ method: 'OPTIONS', url: '/obj/params', headers: {} }, null) @@ -30,12 +30,12 @@ test('Wildcard route should not be blocked by Parametric with different method / t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) findMyWay.on('OPTIONS', '/*', { version: '1.2.3' }, (req, res, params) => { - t.fail('Should not be here') + t.assert.fail('Should not be here') }) findMyWay.on('OPTIONS', '/obj/*', { version: '1.2.3' }, (req, res, params) => { @@ -43,7 +43,7 @@ test('Wildcard route should not be blocked by Parametric with different method / }) findMyWay.on('GET', '/obj/:id', { version: '1.2.3' }, (req, res, params) => { - t.fail('Should not be GET') + t.assert.fail('Should not be GET') }) findMyWay.lookup({ diff --git a/test/issue-161.test.js b/test/issue-161.test.js index a7f4b44f..1fae7739 100644 --- a/test/issue-161.test.js +++ b/test/issue-161.test.js @@ -8,7 +8,7 @@ test('Falling back for node\'s parametric brother without ignoreTrailingSlash', const findMyWay = FindMyWay({ ignoreTrailingSlash: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -27,7 +27,7 @@ test('Falling back for node\'s parametric brother with ignoreTrailingSlash', t = const findMyWay = FindMyWay({ ignoreTrailingSlash: true, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -46,7 +46,7 @@ test('Falling back for node\'s parametric brother without ignoreTrailingSlash', const findMyWay = FindMyWay({ ignoreTrailingSlash: false, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -69,7 +69,7 @@ test('Falling back for node\'s parametric brother with ignoreTrailingSlash', t = const findMyWay = FindMyWay({ ignoreTrailingSlash: true, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-17.test.js b/test/issue-17.test.js index ed25b04f..f9f8119e 100644 --- a/test/issue-17.test.js +++ b/test/issue-17.test.js @@ -7,7 +7,7 @@ test('Parametric route, request.url contains dash', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -21,7 +21,7 @@ test('Parametric route, request.url contains dash', t => { test('Parametric route with fixed suffix', t => { t.plan(6) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) findMyWay.on('GET', '/a/:param-static', () => {}) @@ -46,7 +46,7 @@ test('Regex param exceeds max parameter length', t => { }) findMyWay.on('GET', '/a/:param(^\\w{3})', (req, res, params) => { - t.fail('regex match') + t.assert.fail('regex match') }) findMyWay.lookup({ method: 'GET', url: '/a/fool', headers: {} }, null) @@ -61,7 +61,7 @@ test('Parametric route with regexp and fixed suffix / 1', t => { }) findMyWay.on('GET', '/a/:param(^\\w{3})bar', (req, res, params) => { - t.fail('regex match') + t.assert.fail('regex match') }) findMyWay.lookup({ method: 'GET', url: '/a/$mebar', headers: {} }, null) @@ -74,7 +74,7 @@ test('Parametric route with regexp and fixed suffix / 2', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -89,7 +89,7 @@ test('Parametric route with regexp and fixed suffix / 3', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -104,7 +104,7 @@ test('Multi parametric route / 1', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -126,7 +126,7 @@ test('Multi parametric route / 2', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -148,7 +148,7 @@ test('Multi parametric route / 3', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -175,11 +175,11 @@ test('Multi parametric route / 4', t => { }) findMyWay.on('GET', '/a/:p1-:p2', (req, res, params) => { - t.fail('Should not match this route') + t.assert.fail('Should not match this route') }) findMyWay.on('GET', '/b/:p1.:p2', (req, res, params) => { - t.fail('Should not match this route') + t.assert.fail('Should not match this route') }) findMyWay.lookup({ method: 'GET', url: '/a/foo', headers: {} }, null) @@ -190,7 +190,7 @@ test('Multi parametric route with regexp / 1', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -206,7 +206,7 @@ test('Multi parametric route with colon separator', t => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -227,7 +227,7 @@ test('Multi parametric route with regexp / 2', t => { t.plan(8) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -262,7 +262,7 @@ test('Multi parametric route with fixed suffix', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -284,7 +284,7 @@ test('Multi parametric route with regexp and fixed suffix', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -306,7 +306,7 @@ test('Multi parametric route with wildcard', t => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -328,7 +328,7 @@ test('Nested multi parametric route', t => { t.plan(6) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -352,7 +352,7 @@ test('Nested multi parametric route with regexp / 1', t => { t.plan(6) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -376,7 +376,7 @@ test('Nested multi parametric route with regexp / 2', t => { t.plan(6) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-175.test.js b/test/issue-175.test.js index 6b98bae6..c45236e6 100644 --- a/test/issue-175.test.js +++ b/test/issue-175.test.js @@ -6,7 +6,7 @@ const FindMyWay = require('..') test('double colon is replaced with single colon, no parameters', t => { t.plan(1) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('should not be default route') + defaultRoute: () => t.assert.fail('should not be default route') }) function handler (req, res, params) { @@ -32,11 +32,11 @@ test('exactly one match for static route with colon', t => { test('double colon is replaced with single colon, no parameters, same parent node name', t => { t.plan(1) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('should not be default route') + defaultRoute: () => t.assert.fail('should not be default route') }) findMyWay.on('GET', '/name', () => { - t.fail('should not be parent route') + t.assert.fail('should not be parent route') }) findMyWay.on('GET', '/name::customVerb', (req, res, params) => { @@ -53,11 +53,11 @@ test('double colon is replaced with single colon, default route, same parent nod }) findMyWay.on('GET', '/name', () => { - t.fail('should not be parent route') + t.assert.fail('should not be parent route') }) findMyWay.on('GET', '/name::customVerb', () => { - t.fail('should not be child route') + t.assert.fail('should not be child route') }) findMyWay.lookup({ method: 'GET', url: '/name:wrongCustomVerb', headers: {} }, null) @@ -66,7 +66,7 @@ test('double colon is replaced with single colon, default route, same parent nod test('double colon is replaced with single colon, with parameters', t => { t.plan(1) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('should not be default route') + defaultRoute: () => t.assert.fail('should not be default route') }) findMyWay.on('GET', '/name1::customVerb1/:param1/name2::customVerb2:param2', (req, res, params) => { diff --git a/test/issue-20.test.js b/test/issue-20.test.js index 70b3d7b7..d1ab5ea4 100644 --- a/test/issue-20.test.js +++ b/test/issue-20.test.js @@ -7,7 +7,7 @@ test('Standard case', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be here') + t.assert.fail('Should not be here') } }) @@ -27,7 +27,7 @@ test('Should be 404 / 1', t => { }) findMyWay.on('GET', '/a/:param', (req, res, params) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.lookup({ method: 'GET', url: '/a', headers: {} }, null) @@ -42,7 +42,7 @@ test('Should be 404 / 2', t => { }) findMyWay.on('GET', '/a/:param', (req, res, params) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.lookup({ method: 'GET', url: '/a-non-existing-route', headers: {} }, null) @@ -57,7 +57,7 @@ test('Should be 404 / 3', t => { }) findMyWay.on('GET', '/a/:param', (req, res, params) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.lookup({ method: 'GET', url: '/a//', headers: {} }, null) @@ -67,7 +67,7 @@ test('Should get an empty parameter', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') } }) diff --git a/test/issue-206.test.js b/test/issue-206.test.js index 7e9964a4..39e5f0ad 100644 --- a/test/issue-206.test.js +++ b/test/issue-206.test.js @@ -100,7 +100,7 @@ test('Multi parametric route with encoded colon separator', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/issue-238.test.js b/test/issue-238.test.js index d1ea3730..44423235 100644 --- a/test/issue-238.test.js +++ b/test/issue-238.test.js @@ -6,7 +6,7 @@ const FindMyWay = require('../') test('Multi-parametric tricky path', t => { t.plan(6) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) findMyWay.on('GET', '/:param1-static-:param2', () => {}) @@ -40,7 +40,7 @@ test('Multi-parametric tricky path', t => { test('Multi-parametric nodes with different static ending 1', t => { t.plan(4) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) const paramHandler = () => {} @@ -59,7 +59,7 @@ test('Multi-parametric nodes with different static ending 1', t => { test('Multi-parametric nodes with different static ending 2', t => { t.plan(4) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) const jpgHandler = () => {} @@ -78,7 +78,7 @@ test('Multi-parametric nodes with different static ending 2', t => { test('Multi-parametric nodes with different static ending 3', t => { t.plan(4) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) const jpgHandler = () => {} @@ -97,7 +97,7 @@ test('Multi-parametric nodes with different static ending 3', t => { test('Multi-parametric nodes with different static ending 4', t => { t.plan(6) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) const handler = () => {} diff --git a/test/issue-28.test.js b/test/issue-28.test.js index 80a2f482..60441f0a 100644 --- a/test/issue-28.test.js +++ b/test/issue-28.test.js @@ -7,7 +7,7 @@ test('wildcard (more complex test)', t => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) @@ -23,7 +23,7 @@ test('wildcard (more complex test)', t => { t.assert.ok('correct parameter') break default: - t.fail('wrong parameter: ' + params['*']) + t.assert.fail('wrong parameter: ' + params['*']) } }) @@ -47,7 +47,7 @@ test('Wildcard inside a node with a static route but different method', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) @@ -77,7 +77,7 @@ test('Wildcard inside a node with a static route but different method (more comp if (req.url === '/test/helloo' && req.method === 'GET') { t.assert.ok('Everything fine') } else { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } } }) @@ -120,16 +120,16 @@ test('Wildcard edge cases', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '/test1/foo', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/test2/foo', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { @@ -146,7 +146,7 @@ test('Wildcard edge cases same method', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) @@ -155,7 +155,7 @@ test('Wildcard edge cases same method', t => { }) findMyWay.on('OPTIONS', '/test2/foo', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('OPTIONS', '/*', (req, res, params) => { @@ -177,7 +177,7 @@ test('Wildcard and parametric edge cases', t => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) @@ -186,7 +186,7 @@ test('Wildcard and parametric edge cases', t => { }) findMyWay.on('OPTIONS', '/test2/foo', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/:test/foo', (req, res, params) => { @@ -217,20 +217,20 @@ test('Mixed wildcard and static with same method', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '/foo1/bar1/baz', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/bar2/baz', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo2/bar2/baz', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '*', (req, res, params) => { @@ -247,12 +247,12 @@ test('Nested wildcards case - 1', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { @@ -260,7 +260,7 @@ test('Nested wildcards case - 1', t => { }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -273,12 +273,12 @@ test('Nested wildcards case - 2', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { @@ -286,7 +286,7 @@ test('Nested wildcards case - 2', t => { }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -299,12 +299,12 @@ test('Nested wildcards with parametric and static - 1', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { @@ -312,15 +312,15 @@ test('Nested wildcards with parametric and static - 1', t => { }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo4/param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -333,20 +333,20 @@ test('Nested wildcards with parametric and static - 2', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { @@ -354,7 +354,7 @@ test('Nested wildcards with parametric and static - 2', t => { }) findMyWay.on('GET', '/foo4/param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -367,24 +367,24 @@ test('Nested wildcards with parametric and static - 3', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo4/param', (req, res, params) => { @@ -401,24 +401,24 @@ test('Nested wildcards with parametric and static - 4', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/param', (req, res, params) => { @@ -435,12 +435,12 @@ test('Nested wildcards with parametric and static - 5', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { @@ -448,15 +448,15 @@ test('Nested wildcards with parametric and static - 5', t => { }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/param/hello/test/long/route', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -469,7 +469,7 @@ test('Nested wildcards with parametric and static - 6', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) @@ -478,19 +478,19 @@ test('Nested wildcards with parametric and static - 6', t => { }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo4/param/hello/test/long/route', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -503,20 +503,20 @@ test('Nested wildcards with parametric and static - 7', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { @@ -524,11 +524,11 @@ test('Nested wildcards with parametric and static - 7', t => { }) findMyWay.on('GET', '/foo3/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo4/example/hello/test/long/route', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -541,24 +541,24 @@ test('Nested wildcards with parametric and static - 8', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo2/*', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/:param', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo3/*', (req, res, params) => { @@ -566,7 +566,7 @@ test('Nested wildcards with parametric and static - 8', t => { }) findMyWay.on('GET', '/foo4/param/hello/test/long/route', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( @@ -579,7 +579,7 @@ test('Wildcard node with constraints', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) @@ -588,11 +588,11 @@ test('Wildcard node with constraints', t => { }) findMyWay.on('GET', '/foo1/*', { constraints: { host: 'something-else.io' } }, (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.on('GET', '/foo1/foo2', (req, res, params) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) }) findMyWay.lookup( diff --git a/test/issue-44.test.js b/test/issue-44.test.js index e8ff5643..80e4f0aa 100644 --- a/test/issue-44.test.js +++ b/test/issue-44.test.js @@ -7,12 +7,12 @@ test('Parametric and static with shared prefix / 1', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) findMyWay.on('GET', '/woo', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.on('GET', '/:param', (req, res, params) => { @@ -26,7 +26,7 @@ test('Parametric and static with shared prefix / 2', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -35,7 +35,7 @@ test('Parametric and static with shared prefix / 2', t => { }) findMyWay.on('GET', '/:param', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.lookup({ method: 'GET', url: '/woo', headers: {} }, null) @@ -50,11 +50,11 @@ test('Parametric and static with shared prefix (nested)', t => { }) findMyWay.on('GET', '/woo', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.on('GET', '/:param', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.lookup({ method: 'GET', url: '/winter/coming', headers: {} }, null) @@ -64,12 +64,12 @@ test('Parametric and static with shared prefix and different suffix', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') } }) findMyWay.on('GET', '/example/shared/nested/test', (req, res, params) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.on('GET', '/example/:param/nested/other', (req, res, params) => { @@ -83,12 +83,12 @@ test('Parametric and static with shared prefix (with wildcard)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) findMyWay.on('GET', '/woo', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.on('GET', '/:param', (req, res, params) => { @@ -96,7 +96,7 @@ test('Parametric and static with shared prefix (with wildcard)', t => { }) findMyWay.on('GET', '/*', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.lookup({ method: 'GET', url: '/winter', headers: {} }, null) @@ -106,16 +106,16 @@ test('Parametric and static with shared prefix (nested with wildcard)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) findMyWay.on('GET', '/woo', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.on('GET', '/:param', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.on('GET', '/*', (req, res, params) => { @@ -129,12 +129,12 @@ test('Parametric and static with shared prefix (nested with split)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') } }) findMyWay.on('GET', '/woo', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.on('GET', '/:param', (req, res, params) => { @@ -142,7 +142,7 @@ test('Parametric and static with shared prefix (nested with split)', t => { }) findMyWay.on('GET', '/wo', (req, res, params) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.lookup({ method: 'GET', url: '/winter', headers: {} }, null) diff --git a/test/issue-46.test.js b/test/issue-46.test.js index ef5cf231..ba99726b 100644 --- a/test/issue-46.test.js +++ b/test/issue-46.test.js @@ -7,7 +7,7 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -22,7 +22,7 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -40,7 +40,7 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -59,7 +59,7 @@ test('If the prefixLen is higher than the pathLen we should not save the wildcar t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/methods.test.js b/test/methods.test.js index dfcedf25..c09088cc 100644 --- a/test/methods.test.js +++ b/test/methods.test.js @@ -112,7 +112,7 @@ test('off with nested wildcards with parametric and static', t => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('we should not be here, the url is: ' + req.url) + t.assert.fail('we should not be here, the url is: ' + req.url) } }) @@ -562,7 +562,7 @@ test('static routes should be inserted before parametric / 1', t => { }) findMyWay.on('GET', '/test/:id', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -573,7 +573,7 @@ test('static routes should be inserted before parametric / 2', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:id', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.on('GET', '/test/hello', () => { @@ -588,7 +588,7 @@ test('static routes should be inserted before parametric / 3', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/:id', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.on('GET', '/test', () => { @@ -596,7 +596,7 @@ test('static routes should be inserted before parametric / 3', t => { }) findMyWay.on('GET', '/test/:id', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.on('GET', '/test/hello', () => { @@ -616,7 +616,7 @@ test('static routes should be inserted before parametric / 4', t => { }) findMyWay.on('GET', '/test', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.on('GET', '/test/:id', () => { @@ -624,7 +624,7 @@ test('static routes should be inserted before parametric / 4', t => { }) findMyWay.on('GET', '/test/hello', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.lookup({ method: 'GET', url: '/test/id', headers: {} }, null) @@ -641,7 +641,7 @@ test('Static parametric with shared part of the path', t => { }) findMyWay.on('GET', '/example/shared/nested/test', (req, res, params) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.on('GET', '/example/:param/nested/oops', (req, res, params) => { @@ -699,7 +699,7 @@ test('Unsupported method (static)', t => { }) findMyWay.on('GET', '/', (req, res, params) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.lookup({ method: 'TROLL', url: '/', headers: {} }, null) @@ -714,7 +714,7 @@ test('Unsupported method (wildcard)', t => { }) findMyWay.on('GET', '*', (req, res, params) => { - t.fail('We should not be here') + t.assert.fail('We should not be here') }) findMyWay.lookup({ method: 'TROLL', url: '/hello/world', headers: {} }, null) diff --git a/test/on-bad-url.test.js b/test/on-bad-url.test.js index 32e55cd4..44306267 100644 --- a/test/on-bad-url.test.js +++ b/test/on-bad-url.test.js @@ -7,7 +7,7 @@ test('If onBadUrl is defined, then a bad url should be handled differently (find t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') }, onBadUrl: (path, req, res) => { t.assert.equal(path, '/%world', { todo: 'this is not executed' }) @@ -15,7 +15,7 @@ test('If onBadUrl is defined, then a bad url should be handled differently (find }) findMyWay.on('GET', '/hello/:id', (req, res) => { - t.fail('Should not be here') + t.assert.fail('Should not be here') }) const handle = findMyWay.find('GET', '/hello/%world') @@ -26,7 +26,7 @@ test('If onBadUrl is defined, then a bad url should be handled differently (look t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') }, onBadUrl: (path, req, res) => { t.assert.equal(path, '/hello/%world') @@ -34,7 +34,7 @@ test('If onBadUrl is defined, then a bad url should be handled differently (look }) findMyWay.on('GET', '/hello/:id', (req, res) => { - t.fail('Should not be here') + t.assert.fail('Should not be here') }) findMyWay.lookup({ method: 'GET', url: '/hello/%world', headers: {} }, null) @@ -44,12 +44,12 @@ test('If onBadUrl is not defined, then we should call the defaultRoute (find)', t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) findMyWay.on('GET', '/hello/:id', (req, res) => { - t.fail('Should not be here') + t.assert.fail('Should not be here') }) const handle = findMyWay.find('GET', '/hello/%world') @@ -65,7 +65,7 @@ test('If onBadUrl is not defined, then we should call the defaultRoute (lookup)' }) findMyWay.on('GET', '/hello/:id', (req, res) => { - t.fail('Should not be here') + t.assert.fail('Should not be here') }) findMyWay.lookup({ method: 'GET', url: '/hello/%world', headers: {} }, null) diff --git a/test/optional-params.test.js b/test/optional-params.test.js index d1c481b4..55eb38a4 100644 --- a/test/optional-params.test.js +++ b/test/optional-params.test.js @@ -7,7 +7,7 @@ test('Test route with optional parameter', (t) => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -27,7 +27,7 @@ test('Test for duplicate route with optional param', (t) => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -35,7 +35,7 @@ test('Test for duplicate route with optional param', (t) => { try { findMyWay.on('GET', '/foo', (req, res, params) => {}) - t.fail('method is already declared for route with optional param') + t.assert.fail('method is already declared for route with optional param') } catch (e) { t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/foo\' with constraints \'{}\'') } @@ -45,13 +45,13 @@ test('Test for param with ? not at the end', (t) => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) try { findMyWay.on('GET', '/foo/:bar?/baz', (req, res, params) => {}) - t.fail('Optional Param in the middle of the path is not allowed') + t.assert.fail('Optional Param in the middle of the path is not allowed') } catch (e) { t.assert.equal(e.message, 'Optional Parameter needs to be the last parameter of the path') } @@ -61,7 +61,7 @@ test('Multi parametric route with optional param', (t) => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -81,7 +81,7 @@ test('Optional Parameter with ignoreTrailingSlash = true', (t) => { const findMyWay = FindMyWay({ ignoreTrailingSlash: true, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -129,7 +129,7 @@ test('Optional Parameter with ignoreDuplicateSlashes = true', (t) => { const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true, defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -180,7 +180,7 @@ test('deregister a route with optional param', (t) => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -199,7 +199,7 @@ test('optional parameter on root', (t) => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) diff --git a/test/regex.test.js b/test/regex.test.js index b5a18c6a..7bb8382e 100644 --- a/test/regex.test.js +++ b/test/regex.test.js @@ -7,7 +7,7 @@ test('route with matching regex', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) @@ -27,7 +27,7 @@ test('route without matching regex', t => { }) findMyWay.on('GET', '/test/:id(^\\d+$)', () => { - t.fail('regex match') + t.assert.fail('regex match') }) findMyWay.lookup({ method: 'GET', url: '/test/test', headers: {} }, null) @@ -37,7 +37,7 @@ test('route with an extension regex 2', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req) => { - t.fail(`route not matched: ${req.url}`) + t.assert.fail(`route not matched: ${req.url}`) } }) findMyWay.on('GET', '/test/S/:file(^\\S+).png', () => { @@ -54,7 +54,7 @@ test('nested route with matching regex', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) @@ -69,7 +69,7 @@ test('mixed nested route with matching regex', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) @@ -85,7 +85,7 @@ test('mixed nested route with double matching regex', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) @@ -106,7 +106,7 @@ test('mixed nested route without double matching regex', t => { }) findMyWay.on('GET', '/test/:id(^\\d+$)/hello/:world(^\\d+$)', (req, res, params) => { - t.fail('route mathed') + t.assert.fail('route mathed') }) findMyWay.lookup({ method: 'GET', url: '/test/12/hello/test', headers: {} }, null) @@ -116,7 +116,7 @@ test('route with an extension regex', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) @@ -136,7 +136,7 @@ test('route with an extension regex - no match', t => { }) findMyWay.on('GET', '/test/:file(^\\d+).png', () => { - t.fail('regex match') + t.assert.fail('regex match') }) findMyWay.lookup({ method: 'GET', url: '/test/aa.png', headers: {} }, null) @@ -151,7 +151,7 @@ test('safe decodeURIComponent', t => { }) findMyWay.on('GET', '/test/:id(^\\d+$)', () => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) t.assert.deepEqual( @@ -193,14 +193,14 @@ test('Should check if a regex is safe to use', t => { t.assert.ok('ok') findMyWay.off('GET', `/test/:id(${regex.toString()})`) } catch (err) { - t.fail(err) + t.assert.fail(err) } }) bad.forEach(regex => { try { findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop) - t.fail('should throw') + t.assert.fail('should throw') } catch (err) { t.assert.ok(err) } @@ -240,7 +240,7 @@ test('Disable safe regex check', t => { t.assert.ok('ok') findMyWay.off('GET', `/test/:id(${regex.toString()})`) } catch (err) { - t.fail(err) + t.assert.fail(err) } }) @@ -250,7 +250,7 @@ test('Disable safe regex check', t => { t.assert.ok('ok') findMyWay.off('GET', `/test/:id(${regex.toString()})`) } catch (err) { - t.fail(err) + t.assert.fail(err) } }) }) @@ -261,7 +261,7 @@ test('prevent back-tracking', (t) => { const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) From 08f8fffd0be7f94eb9e3b9adf6376258cf574f8f Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:34:45 +0100 Subject: [PATCH 05/26] fix: assert --- test/optional-params.test.js | 2 +- test/regex.test.js | 2 +- test/routes-registered.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/optional-params.test.js b/test/optional-params.test.js index 55eb38a4..3dcf43ca 100644 --- a/test/optional-params.test.js +++ b/test/optional-params.test.js @@ -104,7 +104,7 @@ test('Optional Parameter with ignoreTrailingSlash = false', (t) => { const findMyWay = FindMyWay({ ignoreTrailingSlash: false, defaultRoute: (req, res) => { - t.match(req.url, '/test/hello/foo/') + t.assert.match(req.url, '/test/hello/foo/') } }) diff --git a/test/regex.test.js b/test/regex.test.js index 7bb8382e..fd1b976a 100644 --- a/test/regex.test.js +++ b/test/regex.test.js @@ -257,7 +257,7 @@ test('Disable safe regex check', t => { test('prevent back-tracking', (t) => { t.plan(0) - t.setTimeout(20) + setTimeout(() => t.assert.fail('timeout'), 20) const findMyWay = FindMyWay({ defaultRoute: () => { diff --git a/test/routes-registered.test.js b/test/routes-registered.test.js index 46b93f4b..693597ca 100644 --- a/test/routes-registered.test.js +++ b/test/routes-registered.test.js @@ -21,7 +21,7 @@ test('verify routes registered', t => { findMyWay = initializeRoutes(findMyWay, defaultHandler, quantity) t.assert.equal(findMyWay.routes.length, quantity) findMyWay.routes.forEach((route, idx) => { - t.match(route, { + t.assert.match(route, { method: 'GET', path: '/test-route-' + idx, opts: {}, From 62cc593978ea9cce1f048f9c376adf42d0dd6ce8 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:37:50 +0100 Subject: [PATCH 06/26] fix: throws --- test/constraint.host.test.js | 2 +- test/issue-154.test.js | 6 +++--- test/issue-28.test.js | 12 ++++++------ test/issue-330.test.js | 22 +++++++++++----------- test/issue-63.test.js | 2 +- test/methods.test.js | 22 +++++++++++----------- test/optional-params.test.js | 2 +- test/params-collisions.test.js | 4 ++-- test/routes-registered.test.js | 12 +++++------- 9 files changed, 41 insertions(+), 43 deletions(-) diff --git a/test/constraint.host.test.js b/test/constraint.host.test.js index 5c347032..8e9a4eed 100644 --- a/test/constraint.host.test.js +++ b/test/constraint.host.test.js @@ -97,7 +97,7 @@ test('A route throws when constraint limit exceeded', (t) => { findMyWay.on('GET', '/', { constraints: { host } }, alpha) } - t.throws( + t.assert.throws( () => findMyWay.on('GET', '/', { constraints: { host: 'h31' } }, beta), 'find-my-way supports a maximum of 31 route handlers per node when there are constraints, limit reached' ) diff --git a/test/issue-154.test.js b/test/issue-154.test.js index a4d36c20..60ec264b 100644 --- a/test/issue-154.test.js +++ b/test/issue-154.test.js @@ -9,13 +9,13 @@ test('Should throw when not sending a string', t => { const findMyWay = FindMyWay() - t.throws(() => { + t.assert.throws(() => { findMyWay.on('GET', '/t1', { constraints: { version: 42 } }, noop) }) - t.throws(() => { + t.assert.throws(() => { findMyWay.on('GET', '/t2', { constraints: { version: null } }, noop) }) - t.throws(() => { + t.assert.throws(() => { findMyWay.on('GET', '/t2', { constraints: { version: true } }, noop) }) }) diff --git a/test/issue-28.test.js b/test/issue-28.test.js index 60441f0a..98848be8 100644 --- a/test/issue-28.test.js +++ b/test/issue-28.test.js @@ -608,11 +608,11 @@ test('Wildcard must be the last character in the route', (t) => { const findMyWay = FindMyWay() - t.throws(() => findMyWay.on('GET', '*1', () => {}), expectedError) - t.throws(() => findMyWay.on('GET', '*/', () => {}), expectedError) - t.throws(() => findMyWay.on('GET', '*?', () => {}), expectedError) + t.assert.throws(() => findMyWay.on('GET', '*1', () => {}), expectedError) + t.assert.throws(() => findMyWay.on('GET', '*/', () => {}), expectedError) + t.assert.throws(() => findMyWay.on('GET', '*?', () => {}), expectedError) - t.throws(() => findMyWay.on('GET', '/foo*123', () => {}), expectedError) - t.throws(() => findMyWay.on('GET', '/foo*?', () => {}), expectedError) - t.throws(() => findMyWay.on('GET', '/foo*/', () => {}), expectedError) + t.assert.throws(() => findMyWay.on('GET', '/foo*123', () => {}), expectedError) + t.assert.throws(() => findMyWay.on('GET', '/foo*?', () => {}), expectedError) + t.assert.throws(() => findMyWay.on('GET', '/foo*/', () => {}), expectedError) }) diff --git a/test/issue-330.test.js b/test/issue-330.test.js index 56ddf205..1db9abe1 100644 --- a/test/issue-330.test.js +++ b/test/issue-330.test.js @@ -16,7 +16,7 @@ test('FULL_PATH_REGEXP and OPTIONAL_PARAM_REGEXP should be considered safe', (t) test('should throw an error for unsafe FULL_PATH_REGEXP', (t) => { t.plan(1) - t.throws(() => proxyquire('..', { + t.assert.throws(() => proxyquire('..', { 'safe-regex2': () => false }), new Error('the FULL_PATH_REGEXP is not safe, update this module')) }) @@ -25,7 +25,7 @@ test('Should throw an error for unsafe OPTIONAL_PARAM_REGEXP', (t) => { t.plan(1) let callCount = 0 - t.throws(() => proxyquire('..', { + t.assert.throws(() => proxyquire('..', { 'safe-regex2': () => { return ++callCount < 2 } @@ -70,9 +70,9 @@ test('wildcard must be the last character in the route', (t) => { const findMyWay = FindMyWay() findMyWay.on('GET', '*', () => {}) - t.throws(() => findMyWay.findRoute('GET', '*1'), expectedError) - t.throws(() => findMyWay.findRoute('GET', '*/'), expectedError) - t.throws(() => findMyWay.findRoute('GET', '*?'), expectedError) + t.assert.throws(() => findMyWay.findRoute('GET', '*1'), expectedError) + t.assert.throws(() => findMyWay.findRoute('GET', '*/'), expectedError) + t.assert.throws(() => findMyWay.findRoute('GET', '*?'), expectedError) }) test('does not find the route if maxParamLength is exceeded', t => { @@ -97,7 +97,7 @@ test('Should check if a regex is safe to use', (t) => { findMyWay.on('GET', '/test/:id(\\d+)', () => {}) const unSafeRegex = /(x+x+)+y/ - t.throws(() => findMyWay.findRoute('GET', `/test/:id(${unSafeRegex.toString()})`), { + t.assert.throws(() => findMyWay.findRoute('GET', `/test/:id(${unSafeRegex.toString()})`), { message: "The regex '(/(x+x+)+y/)' is not safe!" }) }) @@ -117,8 +117,8 @@ test('throws error if no strategy registered for constraint key', (t) => { const constrainer = new Constrainer() const error = new Error('No strategy registered for constraint key invalid-constraint') - t.throws(() => constrainer.newStoreForConstraint('invalid-constraint'), error) - t.throws(() => constrainer.validateConstraints({ 'invalid-constraint': 'foo' }), error) + t.assert.throws(() => constrainer.newStoreForConstraint('invalid-constraint'), error) + t.assert.throws(() => constrainer.validateConstraints({ 'invalid-constraint': 'foo' }), error) }) test('throws error if pass an undefined constraint value', (t) => { @@ -126,7 +126,7 @@ test('throws error if pass an undefined constraint value', (t) => { const constrainer = new Constrainer() const error = new Error('Can\'t pass an undefined constraint value, must pass null or no key at all') - t.throws(() => constrainer.validateConstraints({ key: undefined }), error) + t.assert.throws(() => constrainer.validateConstraints({ key: undefined }), error) }) test('Constrainer.noteUsage', (t) => { @@ -169,7 +169,7 @@ test('SemVerStore version should be a string', (t) => { const Storage = acceptVersionStrategy.storage - t.throws(() => new Storage().set(1), new TypeError('Version should be a string')) + t.assert.throws(() => new Storage().set(1), new TypeError('Version should be a string')) }) test('SemVerStore.maxMajor should increase automatically', (t) => { @@ -208,7 +208,7 @@ test('Major version must be a numeric value', t => { const findMyWay = FindMyWay() - t.throws(() => findMyWay.on('GET', '/test', { constraints: { version: 'x' } }, () => {}), + t.assert.throws(() => findMyWay.on('GET', '/test', { constraints: { version: 'x' } }, () => {}), new TypeError('Major version must be a numeric value')) }) diff --git a/test/issue-63.test.js b/test/issue-63.test.js index 2becc1e5..55bee948 100644 --- a/test/issue-63.test.js +++ b/test/issue-63.test.js @@ -10,7 +10,7 @@ test('issue-63', (t) => { const fmw = factory() - t.throws(function () { + t.assert.throws(function () { fmw.on('GET', '/foo/:id(a', noop) }) diff --git a/test/methods.test.js b/test/methods.test.js index c09088cc..9dd55805 100644 --- a/test/methods.test.js +++ b/test/methods.test.js @@ -18,7 +18,7 @@ test('on throws for invalid method', t => { t.plan(1) const findMyWay = FindMyWay() - t.throws(() => { + t.assert.throws(() => { findMyWay.on('INVALID', '/a/b') }) }) @@ -28,17 +28,17 @@ test('on throws for invalid path', t => { const findMyWay = FindMyWay() // Non string - t.throws(() => { + t.assert.throws(() => { findMyWay.on('GET', 1) }) // Empty - t.throws(() => { + t.assert.throws(() => { findMyWay.on('GET', '') }) // Doesn't start with / or * - t.throws(() => { + t.assert.throws(() => { findMyWay.on('GET', 'invalid') }) }) @@ -83,7 +83,7 @@ test('off throws for invalid method', t => { t.plan(1) const findMyWay = FindMyWay() - t.throws(() => { + t.assert.throws(() => { findMyWay.off('INVALID', '/a/b') }) }) @@ -93,17 +93,17 @@ test('off throws for invalid path', t => { const findMyWay = FindMyWay() // Non string - t.throws(() => { + t.assert.throws(() => { findMyWay.off('GET', 1) }) // Empty - t.throws(() => { + t.assert.throws(() => { findMyWay.off('GET', '') }) // Doesn't start with / or * - t.throws(() => { + t.assert.throws(() => { findMyWay.off('GET', 'invalid') }) }) @@ -806,9 +806,9 @@ test('off validates that constraints is an object or undefined', t => { const findMyWay = FindMyWay() - t.throws(() => findMyWay.off('GET', '/', 2)) - t.throws(() => findMyWay.off('GET', '/', 'should throw')) - t.throws(() => findMyWay.off('GET', '/', [])) + t.assert.throws(() => findMyWay.off('GET', '/', 2)) + t.assert.throws(() => findMyWay.off('GET', '/', 'should throw')) + t.assert.throws(() => findMyWay.off('GET', '/', [])) t.doesNotThrow(() => findMyWay.off('GET', '/', undefined)) t.doesNotThrow(() => findMyWay.off('GET', '/', {})) t.doesNotThrow(() => findMyWay.off('GET', '/')) diff --git a/test/optional-params.test.js b/test/optional-params.test.js index 3dcf43ca..844181d5 100644 --- a/test/optional-params.test.js +++ b/test/optional-params.test.js @@ -104,7 +104,7 @@ test('Optional Parameter with ignoreTrailingSlash = false', (t) => { const findMyWay = FindMyWay({ ignoreTrailingSlash: false, defaultRoute: (req, res) => { - t.assert.match(req.url, '/test/hello/foo/') + t.assert.equal(req.url, '/test/hello/foo/') } }) diff --git a/test/params-collisions.test.js b/test/params-collisions.test.js index c9ff622e..03fac6bc 100644 --- a/test/params-collisions.test.js +++ b/test/params-collisions.test.js @@ -39,7 +39,7 @@ test('should throw when set upping two parametric nodes', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/foo/:bar', () => {}) - t.throws(() => findMyWay.on('GET', '/foo/:baz', () => {})) + t.assert.throws(() => findMyWay.on('GET', '/foo/:baz', () => {})) }) test('should throw when set upping two regexp nodes', t => { @@ -48,7 +48,7 @@ test('should throw when set upping two regexp nodes', t => { const findMyWay = FindMyWay() findMyWay.on('GET', '/foo/:bar(123)', () => {}) - t.throws(() => findMyWay.on('GET', '/foo/:bar(456)', () => {})) + t.assert.throws(() => findMyWay.on('GET', '/foo/:bar(456)', () => {})) }) test('should set up two parametric nodes with static ending', t => { diff --git a/test/routes-registered.test.js b/test/routes-registered.test.js index 693597ca..e3fedef1 100644 --- a/test/routes-registered.test.js +++ b/test/routes-registered.test.js @@ -21,13 +21,11 @@ test('verify routes registered', t => { findMyWay = initializeRoutes(findMyWay, defaultHandler, quantity) t.assert.equal(findMyWay.routes.length, quantity) findMyWay.routes.forEach((route, idx) => { - t.assert.match(route, { - method: 'GET', - path: '/test-route-' + idx, - opts: {}, - handler: defaultHandler, - store: undefined - }) + t.assert.equal(route.method, 'GET') + t.assert.equal(route.path, '/test-route-' + idx) + t.assert.deepStrictEqual(route.opts, {}) + t.assert.equal(route.handler, defaultHandler) + t.assert.equal(route.store, undefined) }) }) From 7b83662ccc03a155e93ffdf17fdf60c1b487df91 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:38:47 +0100 Subject: [PATCH 07/26] chore: strictSame --- test/find-route.test.js | 8 ++++---- test/has-route.test.js | 8 ++++---- test/issue-330.test.js | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/find-route.test.js b/test/find-route.test.js index 6fe32bfb..06a48349 100644 --- a/test/find-route.test.js +++ b/test/find-route.test.js @@ -5,16 +5,16 @@ const rfdc = require('rfdc')({ proto: true }) const FindMyWay = require('..') function equalRouters (t, router1, router2) { - t.strictSame(router1._opts, router2._opts) + t.assert.deepStrictEqual(router1._opts, router2._opts) t.assert.deepEqual(router1.routes, router2.routes) t.assert.deepEqual(router1.trees, router2.trees) - t.strictSame(router1.constrainer.strategies, router2.constrainer.strategies) - t.strictSame( + t.assert.deepStrictEqual(router1.constrainer.strategies, router2.constrainer.strategies) + t.assert.deepStrictEqual( router1.constrainer.strategiesInUse, router2.constrainer.strategiesInUse ) - t.strictSame( + t.assert.deepStrictEqual( router1.constrainer.asyncStrategiesInUse, router2.constrainer.asyncStrategiesInUse ) diff --git a/test/has-route.test.js b/test/has-route.test.js index 035300bf..b7b9fe77 100644 --- a/test/has-route.test.js +++ b/test/has-route.test.js @@ -5,19 +5,19 @@ const rfdc = require('rfdc')({ proto: true }) const FindMyWay = require('..') function equalRouters (t, router1, router2) { - t.strictSame(router1._opts, router2._opts) + t.assert.deepStrictEqual(router1._opts, router2._opts) t.assert.deepEqual(router1.routes, router2.routes) t.assert.deepEqual(router1.trees, router2.trees) - t.strictSame( + t.assert.deepStrictEqual( router1.constrainer.strategies, router2.constrainer.strategies ) - t.strictSame( + t.assert.deepStrictEqual( router1.constrainer.strategiesInUse, router2.constrainer.strategiesInUse ) - t.strictSame( + t.assert.deepStrictEqual( router1.constrainer.asyncStrategiesInUse, router2.constrainer.asyncStrategiesInUse ) diff --git a/test/issue-330.test.js b/test/issue-330.test.js index 1db9abe1..59a71231 100644 --- a/test/issue-330.test.js +++ b/test/issue-330.test.js @@ -39,11 +39,11 @@ test('double colon does not define parametric node', (t) => { findMyWay.on('GET', '/::id', () => {}) const route1 = findMyWay.findRoute('GET', '/::id') - t.strictSame(route1.params, []) + t.assert.deepStrictEqual(route1.params, []) findMyWay.on('GET', '/:foo(\\d+)::bar', () => {}) const route2 = findMyWay.findRoute('GET', '/:foo(\\d+)::bar') - t.strictSame(route2.params, ['foo']) + t.assert.deepStrictEqual(route2.params, ['foo']) }) test('case insensitive static routes', (t) => { @@ -220,7 +220,7 @@ test('httpMethodStrategy storage handles set and get operations correctly', (t) t.assert.equal(storage.get('foo'), null) storage.set('foo', { bar: 'baz' }) - t.strictSame(storage.get('foo'), { bar: 'baz' }) + t.assert.deepStrictEqual(storage.get('foo'), { bar: 'baz' }) }) test('if buildPrettyMeta argument is undefined, will return an object', (t) => { From a141e967081950a421b05d3276ff46269f5c2d85 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:40:22 +0100 Subject: [PATCH 08/26] fix: doesNotThrow --- test/issue-330.test.js | 4 ++-- test/methods.test.js | 6 +++--- test/on-bad-url.test.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/issue-330.test.js b/test/issue-330.test.js index 59a71231..13b4f605 100644 --- a/test/issue-330.test.js +++ b/test/issue-330.test.js @@ -10,7 +10,7 @@ const httpMethodStrategy = require('../lib/strategies/http-method') test('FULL_PATH_REGEXP and OPTIONAL_PARAM_REGEXP should be considered safe', (t) => { t.plan(1) - t.doesNotThrow(() => require('..')) + t.assert.doesNotThrow(() => require('..')) }) test('should throw an error for unsafe FULL_PATH_REGEXP', (t) => { @@ -109,7 +109,7 @@ test('Disable safe regex check', (t) => { const unSafeRegex = /(x+x+)+y/ findMyWay.on('GET', `/test2/:id(${unSafeRegex.toString()})`, () => {}) - t.doesNotThrow(() => findMyWay.findRoute('GET', `/test2/:id(${unSafeRegex.toString()})`)) + t.assert.doesNotThrow(() => findMyWay.findRoute('GET', `/test2/:id(${unSafeRegex.toString()})`)) }) test('throws error if no strategy registered for constraint key', (t) => { diff --git a/test/methods.test.js b/test/methods.test.js index 9dd55805..3ee01a9f 100644 --- a/test/methods.test.js +++ b/test/methods.test.js @@ -809,9 +809,9 @@ test('off validates that constraints is an object or undefined', t => { t.assert.throws(() => findMyWay.off('GET', '/', 2)) t.assert.throws(() => findMyWay.off('GET', '/', 'should throw')) t.assert.throws(() => findMyWay.off('GET', '/', [])) - t.doesNotThrow(() => findMyWay.off('GET', '/', undefined)) - t.doesNotThrow(() => findMyWay.off('GET', '/', {})) - t.doesNotThrow(() => findMyWay.off('GET', '/')) + t.assert.doesNotThrow(() => findMyWay.off('GET', '/', undefined)) + t.assert.doesNotThrow(() => findMyWay.off('GET', '/', {})) + t.assert.doesNotThrow(() => findMyWay.off('GET', '/')) }) test('off removes only unconstrainted route if an empty object is given as constraints', t => { diff --git a/test/on-bad-url.test.js b/test/on-bad-url.test.js index 44306267..3bc211e4 100644 --- a/test/on-bad-url.test.js +++ b/test/on-bad-url.test.js @@ -19,7 +19,7 @@ test('If onBadUrl is defined, then a bad url should be handled differently (find }) const handle = findMyWay.find('GET', '/hello/%world') - t.not(handle, null) + t.assert.notDeepStrictEqual(handle, null) }) test('If onBadUrl is defined, then a bad url should be handled differently (lookup)', t => { From 36ce0458e0db7cd26517a695af015ceebae379d3 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:41:35 +0100 Subject: [PATCH 09/26] chore: timeout --- test/regex.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/regex.test.js b/test/regex.test.js index fd1b976a..f73b97bd 100644 --- a/test/regex.test.js +++ b/test/regex.test.js @@ -255,9 +255,8 @@ test('Disable safe regex check', t => { }) }) -test('prevent back-tracking', (t) => { +test('prevent back-tracking', { timeout: 20 }, (t) => { t.plan(0) - setTimeout(() => t.assert.fail('timeout'), 20) const findMyWay = FindMyWay({ defaultRoute: () => { From e6893da1d34a6dd0aa0bba2343bae917bb061737 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:43:28 +0100 Subject: [PATCH 10/26] fix: assert --- test/routes-registered.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/routes-registered.test.js b/test/routes-registered.test.js index e3fedef1..dd5eef2e 100644 --- a/test/routes-registered.test.js +++ b/test/routes-registered.test.js @@ -11,9 +11,10 @@ function initializeRoutes (router, handler, quantity) { } test('verify routes registered', t => { + const assertPerTest = 5 const quantity = 5 // 1 (check length) + quantity of routes * quantity of tests per route - t.plan(1 + (quantity * 1)) + t.plan(1 + (quantity * assertPerTest)) let findMyWay = FindMyWay() const defaultHandler = (req, res, params) => res.end(JSON.stringify({ hello: 'world' })) From 7f63d9a7293b4ec284924b6a42037ccac965cfdf Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:50:38 +0100 Subject: [PATCH 11/26] chore: null --- test/issue-59.test.js | 2 +- test/server.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/issue-59.test.js b/test/issue-59.test.js index a9858581..7a3a6d4e 100644 --- a/test/issue-59.test.js +++ b/test/issue-59.test.js @@ -117,7 +117,7 @@ test('with parameter / 6', t => { t.assert.equal(findMyWay.find('GET', '/bulk'), null) t.assert.equal(findMyWay.find('GET', '/static/foo/bulk'), null) - t.not(findMyWay.find('GET', '/static/foo/static/bulk'), null) + t.assert.notEqual(findMyWay.find('GET', '/static/foo/static/bulk'), null) }) test('wildcard / 1', t => { diff --git a/test/server.test.js b/test/server.test.js index 9d3881e6..6183d6e1 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -371,7 +371,7 @@ test('does map // when ignoreDuplicateSlashes is true', t => { }) server.listen(0, err => { - t.error(err) + t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -410,7 +410,7 @@ test('versioned routes', t => { }) server.listen(0, err => { - t.error(err) + t.assert.equal(err, undefined) server.unref() http.get( From 058c7be89c1c55d206a6ff0be4273d44bc6f7539 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 18:51:59 +0100 Subject: [PATCH 12/26] chore: not match --- test/issue-182.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/issue-182.test.js b/test/issue-182.test.js index 38be9d07..ac4c7cbd 100644 --- a/test/issue-182.test.js +++ b/test/issue-182.test.js @@ -14,5 +14,5 @@ test('Set method property when splitting node', t => { findMyWay.on('GET', '/health-a/health', handler) findMyWay.on('GET', '/health-b/health', handler) - t.notMatch(findMyWay.prettyPrint(), /undefined/) + t.assert.ok(!findMyWay.prettyPrint().includes('undefined')) }) From 2f3589a49e98fcb35259be46ab3a97b7ea55476b Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 19:27:00 +0100 Subject: [PATCH 13/26] chore: server --- test/server.test.js | 158 ++++++++++++++++++-------------------------- 1 file changed, 64 insertions(+), 94 deletions(-) diff --git a/test/server.test.js b/test/server.test.js index 6183d6e1..68cda924 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -4,7 +4,7 @@ const { test } = require('node:test') const http = require('http') const FindMyWay = require('../') -test('basic router with http server', t => { +test('basic router with http server', (t, done) => { t.plan(6) const findMyWay = FindMyWay() findMyWay.on('GET', '/test', (req, res, params) => { @@ -18,22 +18,19 @@ test('basic router with http server', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.equal(err, undefined) server.unref() - http.get('http://localhost:' + server.address().port + '/test', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(JSON.parse(body), { hello: 'world' }) - }) + const res = await fetch(`http://localhost:${server.address().port}/test`) + + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.json(), { hello: 'world' }) + done() }) }) -test('router with params with http server', t => { +test('router with params with http server', (t, done) => { t.plan(6) const findMyWay = FindMyWay() findMyWay.on('GET', '/test/:id', (req, res, params) => { @@ -47,22 +44,19 @@ test('router with params with http server', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.equal(err, undefined) server.unref() - http.get('http://localhost:' + server.address().port + '/test/hello', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(JSON.parse(body), { hello: 'world' }) - }) + const res = await fetch(`http://localhost:${server.address().port}/test/hello`) + + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.json(), { hello: 'world' }) + done() }) }) -test('default route', t => { +test('default route', (t, done) => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { @@ -75,17 +69,17 @@ test('default route', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.equal(err, undefined) server.unref() - http.get('http://localhost:' + server.address().port, async (res) => { - t.assert.equal(res.statusCode, 404) - }) + const res = await fetch(`http://localhost:${server.address().port}`) + t.assert.equal(res.status, 404) + done() }) }) -test('automatic default route', t => { +test('automatic default route', (t, done) => { t.plan(2) const findMyWay = FindMyWay() @@ -93,17 +87,17 @@ test('automatic default route', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.equal(err, undefined) server.unref() - http.get('http://localhost:' + server.address().port, async (res) => { - t.assert.equal(res.statusCode, 404) - }) + const res = await fetch(`http://localhost:${server.address().port}`) + t.assert.equal(res.status, 404) + done() }) }) -test('maps two routes when trailing slash should be trimmed', t => { +test('maps two routes when trailing slash should be trimmed', (t, done) => { t.plan(21) const findMyWay = FindMyWay({ ignoreTrailingSlash: true @@ -127,47 +121,29 @@ test('maps two routes when trailing slash should be trimmed', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port - http.get(baseURL + '/test/', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + let res = await fetch(`${baseURL}/test/`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '/test', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + res = await fetch(`${baseURL}/test`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '/othertest', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'othertest') - }) + res = await fetch(`${baseURL}/othertest`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'othertest') - http.get(baseURL + '/othertest/', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'othertest') - }) + res = await fetch(`${baseURL}/othertest/`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'othertest') + + done() }) }) @@ -189,7 +165,7 @@ test('does not trim trailing slash when ignoreTrailingSlash is false', t => { }) server.listen(0, err => { - t.error(err) + t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -227,7 +203,7 @@ test('does not map // when ignoreTrailingSlash is true', t => { }) server.listen(0, err => { - t.error(err) + t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -272,7 +248,7 @@ test('maps two routes when duplicate slashes should be trimmed', t => { }) server.listen(0, err => { - t.error(err) + t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -333,7 +309,7 @@ test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', t = }) server.listen(0, err => { - t.error(err) + t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -396,7 +372,7 @@ test('does map // when ignoreDuplicateSlashes is true', t => { }) }) -test('versioned routes', t => { +test('versioned routes', (t, done) => { t.plan(3) const findMyWay = FindMyWay() @@ -409,28 +385,22 @@ test('versioned routes', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { + server.listen(0, async err => { t.assert.equal(err, undefined) server.unref() - http.get( - 'http://localhost:' + server.address().port + '/test', - { - headers: { 'Accept-Version': '1.x' } - }, - async (res) => { - t.assert.equal(res.statusCode, 200) - } - ) - - http.get( - 'http://localhost:' + server.address().port + '/test', - { - headers: { 'Accept-Version': '2.x' } - }, - async (res) => { - t.assert.equal(res.statusCode, 404) - } - ) + let res = await fetch(`http://localhost:${server.address().port}/test`, { + headers: { 'Accept-Version': '1.2.3' } + }) + + t.assert.equal(res.status, 200) + + res = await fetch(`http://localhost:${server.address().port}/test`, { + headers: { 'Accept-Version': '2.x' } + }) + + t.assert.equal(res.status, 404) + + done() }) }) From 8a941fab6104aa6058621d12ac08415f2c08e79a Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 19:28:04 +0100 Subject: [PATCH 14/26] feat: trim --- test/server.test.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/test/server.test.js b/test/server.test.js index 68cda924..afe3b234 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -147,7 +147,7 @@ test('maps two routes when trailing slash should be trimmed', (t, done) => { }) }) -test('does not trim trailing slash when ignoreTrailingSlash is false', t => { +test('does not trim trailing slash when ignoreTrailingSlash is false', (t, done) => { t.plan(7) const findMyWay = FindMyWay({ ignoreTrailingSlash: false @@ -164,24 +164,20 @@ test('does not trim trailing slash when ignoreTrailingSlash is false', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { + server.listen(0, async err => { t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port - http.get(baseURL + '/test/', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + let res = await fetch(`${baseURL}/test/`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '/test', async (res) => { - t.assert.equal(res.statusCode, 404) - }) + res = await fetch(`${baseURL}/test`) + t.assert.equal(res.status, 404) + + done() }) }) From f847bfa124d9b99c86e32366d98e25872e40b828 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 19:28:55 +0100 Subject: [PATCH 15/26] chore: server --- test/server.test.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/test/server.test.js b/test/server.test.js index afe3b234..69f7b919 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -181,7 +181,7 @@ test('does not trim trailing slash when ignoreTrailingSlash is false', (t, done) }) }) -test('does not map // when ignoreTrailingSlash is true', t => { +test('does not map // when ignoreTrailingSlash is true', (t, done) => { t.plan(7) const findMyWay = FindMyWay({ ignoreTrailingSlash: false @@ -198,24 +198,20 @@ test('does not map // when ignoreTrailingSlash is true', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { + server.listen(0, async err => { t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port - http.get(baseURL + '/', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + let res = await fetch(`${baseURL}/`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '//', async (res) => { - t.assert.equal(res.statusCode, 404) - }) + res = await fetch(`${baseURL}//`) + t.assert.equal(res.status, 404) + + done() }) }) From a52c74d1091e5127dfa120e1e3fb6801e9e5036b Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 19:30:47 +0100 Subject: [PATCH 16/26] chore: server --- test/server.test.js | 50 +++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/test/server.test.js b/test/server.test.js index 69f7b919..a3f7e486 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -215,7 +215,7 @@ test('does not map // when ignoreTrailingSlash is true', (t, done) => { }) }) -test('maps two routes when duplicate slashes should be trimmed', t => { +test('maps two routes when duplicate slashes should be trimmed', (t, done) => { t.plan(21) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true @@ -239,47 +239,29 @@ test('maps two routes when duplicate slashes should be trimmed', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { + server.listen(0, async err => { t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port - http.get(baseURL + '//test', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + let res = await fetch(`${baseURL}//test`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '/test', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + res = await fetch(`${baseURL}/test`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '/othertest', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'othertest') - }) + res = await fetch(`${baseURL}/othertest`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'othertest') - http.get(baseURL + '//othertest', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'othertest') - }) + res = await fetch(`${baseURL}//othertest`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'othertest') + + done() }) }) From a6b454fd84366230660e8b13a152d9e13087dc46 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 19:32:07 +0100 Subject: [PATCH 17/26] chore: server --- test/server.test.js | 50 +++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/test/server.test.js b/test/server.test.js index a3f7e486..434b17f2 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -265,7 +265,7 @@ test('maps two routes when duplicate slashes should be trimmed', (t, done) => { }) }) -test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', t => { +test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', (t, done) => { t.plan(7) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: false @@ -282,28 +282,24 @@ test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', t = findMyWay.lookup(req, res) }) - server.listen(0, err => { + server.listen(0, async err => { t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port - http.get(baseURL + '//test', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + let res = await fetch(`${baseURL}//test`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '/test', async (res) => { - t.assert.equal(res.statusCode, 404) - }) + res = await fetch(`${baseURL}/test`) + t.assert.equal(res.status, 404) + + done() }) }) -test('does map // when ignoreDuplicateSlashes is true', t => { +test('does map // when ignoreDuplicateSlashes is true', (t, done) => { t.plan(11) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true @@ -320,29 +316,21 @@ test('does map // when ignoreDuplicateSlashes is true', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { + server.listen(0, async err => { t.assert.equal(err, undefined) server.unref() const baseURL = 'http://localhost:' + server.address().port - http.get(baseURL + '/', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + let res = await fetch(`${baseURL}/`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') - http.get(baseURL + '//', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.assert.equal(res.statusCode, 200) - t.assert.deepEqual(body, 'test') - }) + res = await fetch(`${baseURL}//`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') + + done() }) }) From e8e7d1cdca2fc817127f7a967b1589886a4fe2dd Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 20:32:02 +0100 Subject: [PATCH 18/26] chore: shorthands --- test/shorthands.test.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/shorthands.test.js b/test/shorthands.test.js index c1b3ef1e..f2998a20 100644 --- a/test/shorthands.test.js +++ b/test/shorthands.test.js @@ -1,17 +1,15 @@ 'use strict' const httpMethods = require('../lib/http-methods') -const { test } = require('node:test') +const { describe, test } = require('node:test') const FindMyWay = require('../') -test('should support shorthand', t => { - t.plan(httpMethods.length) - +describe('should support shorthand', t => { for (const i in httpMethods) { const m = httpMethods[i] const methodName = m.toLowerCase() - t.test('`.' + methodName + '`', t => { + test('`.' + methodName + '`', t => { t.plan(1) const findMyWay = FindMyWay() From 719a9386dfecec592cdc9bbbc01fa652ee804ac0 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 20:33:35 +0100 Subject: [PATCH 19/26] fix: methods --- test/methods.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/methods.test.js b/test/methods.test.js index 3ee01a9f..58f5af16 100644 --- a/test/methods.test.js +++ b/test/methods.test.js @@ -668,7 +668,7 @@ test('parametric route with different method', t => { findMyWay.lookup({ method: 'POST', url: '/test/world', headers: {} }, null) }) -test('params does not keep the object reference', t => { +test('params does not keep the object reference', (t, done) => { t.plan(2) const findMyWay = FindMyWay() let first = true @@ -681,6 +681,7 @@ test('params does not keep the object reference', t => { } else { setTimeout(() => { t.assert.equal(params.id, 'world') + done() }, 10) } first = false From fab35f9b34941a3a34cec933f6bd085ae3555877 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 20:41:23 +0100 Subject: [PATCH 20/26] chore: constraint --- test/constraint.custom-versioning.test.js | 4 ++-- test/constraint.host.test.js | 2 +- test/find-route.test.js | 2 +- test/has-route.test.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/constraint.custom-versioning.test.js b/test/constraint.custom-versioning.test.js index bff1c3f6..2e839ebf 100644 --- a/test/constraint.custom-versioning.test.js +++ b/test/constraint.custom-versioning.test.js @@ -113,7 +113,7 @@ test('Overriding custom strategies throws as error (add strategy outside constru findMyWay.addConstraintStrategy(customVersioning) t.assert.throws(() => findMyWay.addConstraintStrategy(customVersioning), - 'There already exists a custom constraint with the name version.' + new Error('There already exists a custom constraint with the name version.') ) }) @@ -125,6 +125,6 @@ test('Overriding default strategies after defining a route with constraint', t = findMyWay.on('GET', '/', { constraints: { host: 'fastify.io', version: '1.0.0' } }, () => {}) t.assert.throws(() => findMyWay.addConstraintStrategy(customVersioning), - 'There already exists a route with version constraint.' + new Error('There already exists a route with version constraint.') ) }) diff --git a/test/constraint.host.test.js b/test/constraint.host.test.js index 8e9a4eed..a53796f1 100644 --- a/test/constraint.host.test.js +++ b/test/constraint.host.test.js @@ -99,6 +99,6 @@ test('A route throws when constraint limit exceeded', (t) => { t.assert.throws( () => findMyWay.on('GET', '/', { constraints: { host: 'h31' } }, beta), - 'find-my-way supports a maximum of 31 route handlers per node when there are constraints, limit reached' + new Error('find-my-way supports a maximum of 31 route handlers per node when there are constraints, limit reached') ) }) diff --git a/test/find-route.test.js b/test/find-route.test.js index 06a48349..bb099183 100644 --- a/test/find-route.test.js +++ b/test/find-route.test.js @@ -7,7 +7,7 @@ const FindMyWay = require('..') function equalRouters (t, router1, router2) { t.assert.deepStrictEqual(router1._opts, router2._opts) t.assert.deepEqual(router1.routes, router2.routes) - t.assert.deepEqual(router1.trees, router2.trees) + t.assert.deepEqual(JSON.stringify(router1.trees), JSON.stringify(router2.trees)) t.assert.deepStrictEqual(router1.constrainer.strategies, router2.constrainer.strategies) t.assert.deepStrictEqual( diff --git a/test/has-route.test.js b/test/has-route.test.js index b7b9fe77..db3a97c6 100644 --- a/test/has-route.test.js +++ b/test/has-route.test.js @@ -7,7 +7,7 @@ const FindMyWay = require('..') function equalRouters (t, router1, router2) { t.assert.deepStrictEqual(router1._opts, router2._opts) t.assert.deepEqual(router1.routes, router2.routes) - t.assert.deepEqual(router1.trees, router2.trees) + t.assert.deepEqual(JSON.stringify(router1.trees), JSON.stringify(router2.trees)) t.assert.deepStrictEqual( router1.constrainer.strategies, From 012fda0c33bd429ef2ff1d0990674c4bde41632e Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 20:43:49 +0100 Subject: [PATCH 21/26] chore: errors --- test/errors.test.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/test/errors.test.js b/test/errors.test.js index 08b752fa..12efced0 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -1,6 +1,6 @@ 'use strict' -const { test } = require('node:test') +const { test, describe } = require('node:test') const FindMyWay = require('../') test('Method should be a string', t => { @@ -270,10 +270,8 @@ test('Method already declared if /* is used', t => { } }) -test('Method already declared [ignoreTrailingSlash=true]', t => { - t.plan(2) - - t.test('without trailing slash', t => { +describe('Method already declared [ignoreTrailingSlash=true]', t => { + test('without trailing slash', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) @@ -294,7 +292,7 @@ test('Method already declared [ignoreTrailingSlash=true]', t => { } }) - t.test('with trailing slash', t => { + test('with trailing slash', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) @@ -316,10 +314,8 @@ test('Method already declared [ignoreTrailingSlash=true]', t => { }) }) -test('Method already declared [ignoreDuplicateSlashes=true]', t => { - t.plan(2) - - t.test('without duplicate slashes', t => { +describe('Method already declared [ignoreDuplicateSlashes=true]', t => { + test('without duplicate slashes', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true }) @@ -340,7 +336,7 @@ test('Method already declared [ignoreDuplicateSlashes=true]', t => { } }) - t.test('with duplicate slashes', t => { + test('with duplicate slashes', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true }) @@ -378,10 +374,8 @@ test('Method already declared nested route', t => { } }) -test('Method already declared nested route [ignoreTrailingSlash=true]', t => { - t.plan(2) - - t.test('without trailing slash', t => { +describe('Method already declared nested route [ignoreTrailingSlash=true]', t => { + test('without trailing slash', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) @@ -417,7 +411,7 @@ test('Method already declared nested route [ignoreTrailingSlash=true]', t => { } }) - t.test('with trailing slash', t => { + test('with trailing slash', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) @@ -467,7 +461,7 @@ test('Method already declared nested route [ignoreDuplicateSlashes=true]', t => } }) - t.test('with duplicate slashes', t => { + test('with duplicate slashes', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true }) From 90d3f144264f4aa31b108963d63dddd82851e13b Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 20:45:04 +0100 Subject: [PATCH 22/26] chore: tests --- test/errors.test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/errors.test.js b/test/errors.test.js index 12efced0..9a003fe3 100644 --- a/test/errors.test.js +++ b/test/errors.test.js @@ -435,10 +435,8 @@ describe('Method already declared nested route [ignoreTrailingSlash=true]', t => }) }) -test('Method already declared nested route [ignoreDuplicateSlashes=true]', t => { - t.plan(2) - - t.test('without duplicate slashes', t => { +describe('Method already declared nested route [ignoreDuplicateSlashes=true]', t => { + test('without duplicate slashes', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true }) From 8669589b5851d740fcab81d7afd0070b089d1dee Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 20:51:26 +0100 Subject: [PATCH 23/26] fix: test command --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9b1d4e44..0524e282 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,9 @@ "bench:cmp:ci": "node ./benchmark/compare-branches.js --ci", "test:lint": "standard", "test:typescript": "tsd", - "test": "standard && node --test test/*.test.js && npm run test:typescript", - "test:report": "node --test test/*.test.js --test-reporter tap --test-reporter-destination out.tap", - "test:reporter": "node --test --test-reporter junit --test-reporter-destination test/junit-testresults.xml" + "test": "standard && node --test test/*.test.js test/**/*.test.js && npm run test:typescript", + "test:report": "node --test test/*.test.js test/**/*.test.js --test-reporter tap --test-reporter-destination out.tap", + "test:reporter": "node --test test/*.test.js test/**/*.test.js --test-reporter junit --test-reporter-destination test/junit-testresults.xml" }, "repository": { "type": "git", From fe6c783bf371afa0d096ad5b82f4f00640ae5279 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 20:55:55 +0100 Subject: [PATCH 24/26] chore: removed useless commands --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index 0524e282..562bfb13 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,7 @@ "bench:cmp:ci": "node ./benchmark/compare-branches.js --ci", "test:lint": "standard", "test:typescript": "tsd", - "test": "standard && node --test test/*.test.js test/**/*.test.js && npm run test:typescript", - "test:report": "node --test test/*.test.js test/**/*.test.js --test-reporter tap --test-reporter-destination out.tap", - "test:reporter": "node --test test/*.test.js test/**/*.test.js --test-reporter junit --test-reporter-destination test/junit-testresults.xml" + "test": "standard && node --test test/*.test.js test/**/*.test.js && npm run test:typescript" }, "repository": { "type": "git", From 4b34c9d96a1c17b19eed75aa06206ee2f4690ec2 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 21:04:26 +0100 Subject: [PATCH 25/26] chore: use borp --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 562bfb13..69e08764 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "bench:cmp:ci": "node ./benchmark/compare-branches.js --ci", "test:lint": "standard", "test:typescript": "tsd", - "test": "standard && node --test test/*.test.js test/**/*.test.js && npm run test:typescript" + "test": "standard && borp && npm run test:typescript" }, "repository": { "type": "git", @@ -35,6 +35,7 @@ "devDependencies": { "@types/node": "^20.0.0", "benchmark": "^2.1.4", + "borp": "^0.18.0", "chalk": "^4.1.2", "inquirer": "^8.2.4", "pre-commit": "^1.2.2", From 9f8eca18479cbebb2ae4cc0578db36b9a4477a80 Mon Sep 17 00:00:00 2001 From: Matteo Pietro Dazzi Date: Sun, 3 Nov 2024 21:16:12 +0100 Subject: [PATCH 26/26] chore: ifError --- test/server.test.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/server.test.js b/test/server.test.js index 434b17f2..55087ac7 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -19,7 +19,7 @@ test('basic router with http server', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const res = await fetch(`http://localhost:${server.address().port}/test`) @@ -45,7 +45,7 @@ test('router with params with http server', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const res = await fetch(`http://localhost:${server.address().port}/test/hello`) @@ -70,7 +70,7 @@ test('default route', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const res = await fetch(`http://localhost:${server.address().port}`) @@ -88,7 +88,7 @@ test('automatic default route', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const res = await fetch(`http://localhost:${server.address().port}`) @@ -122,7 +122,7 @@ test('maps two routes when trailing slash should be trimmed', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -165,7 +165,7 @@ test('does not trim trailing slash when ignoreTrailingSlash is false', (t, done) }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -199,7 +199,7 @@ test('does not map // when ignoreTrailingSlash is true', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -240,7 +240,7 @@ test('maps two routes when duplicate slashes should be trimmed', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -283,7 +283,7 @@ test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', (t, }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -317,7 +317,7 @@ test('does map // when ignoreDuplicateSlashes is true', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() const baseURL = 'http://localhost:' + server.address().port @@ -348,7 +348,7 @@ test('versioned routes', (t, done) => { }) server.listen(0, async err => { - t.assert.equal(err, undefined) + t.assert.ifError(err) server.unref() let res = await fetch(`http://localhost:${server.address().port}/test`, {