diff --git a/package.json b/package.json index e28d4e61..69e08764 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 && 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 && borp && npm run test:typescript" }, "repository": { "type": "git", @@ -37,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", @@ -44,8 +43,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..db73dc39 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 => { @@ -10,12 +9,12 @@ 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') } }) 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) @@ -27,12 +26,12 @@ 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') } }) 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) @@ -44,12 +43,12 @@ 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') } }) 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) @@ -61,12 +60,12 @@ 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') } }) 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) @@ -78,12 +77,12 @@ 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') } }) 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) @@ -95,12 +94,12 @@ 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') } }) 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) @@ -112,12 +111,12 @@ 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') } }) 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) @@ -133,16 +132,16 @@ 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') } }) 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) @@ -155,13 +154,13 @@ 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') } }) 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) @@ -173,13 +172,13 @@ 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') } }) 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) @@ -191,12 +190,12 @@ 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') } }) 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) @@ -208,21 +207,21 @@ 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') } }) 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..2e839ebf 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,8 +112,8 @@ test('Overriding custom strategies throws as error (add strategy outside constru findMyWay.addConstraintStrategy(customVersioning) - t.throws(() => findMyWay.addConstraintStrategy(customVersioning), - 'There already exists a custom constraint with the name version.' + t.assert.throws(() => findMyWay.addConstraintStrategy(customVersioning), + new Error('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), - 'There already exists a route with version constraint.' + t.assert.throws(() => findMyWay.addConstraintStrategy(customVersioning), + new Error('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..4cfe2b35 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..91aa5548 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..08adf490 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({ @@ -168,31 +167,31 @@ 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) => { - 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) => { - 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) => { - 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 => { @@ -235,9 +234,9 @@ 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.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"}\'') } }) @@ -246,12 +245,12 @@ 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') } }) findMyWay.on('GET', '/', (req, res) => { - t.pass('Yeah!') + t.assert.ok('Yeah!') }) findMyWay.lookup({ @@ -271,15 +270,15 @@ 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') } }) 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/constraint.host.test.js b/test/constraint.host.test.js index 5033ed45..a53796f1 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) => { @@ -98,8 +97,8 @@ 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' + new Error('find-my-way supports a maximum of 31 route handlers per node when there are constraints, limit reached') ) }) diff --git a/test/constraints.test.js b/test/constraints.test.js index 13124fcb..67bf8d81 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..e2bd620a 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..9a003fe3 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, describe } = require('node:test') const FindMyWay = require('../') test('Method should be a string', t => { @@ -10,9 +9,9 @@ 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.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -22,9 +21,9 @@ 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.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -34,9 +33,9 @@ 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.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -46,9 +45,9 @@ 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.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -58,9 +57,9 @@ 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.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -70,9 +69,9 @@ 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.equal(e.message, 'Method should be a string') + t.assert.equal(e.message, 'Method should be a string') } }) @@ -82,9 +81,9 @@ 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.equal(e.message, 'Path should be a string') + t.assert.equal(e.message, 'Path should be a string') } }) @@ -94,9 +93,9 @@ 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.equal(e.message, 'Path should be a string') + t.assert.equal(e.message, 'Path should be a string') } }) @@ -106,9 +105,9 @@ 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.equal(e.message, 'Path should be a string') + t.assert.equal(e.message, 'Path should be a string') } }) @@ -118,9 +117,9 @@ 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.equal(e.message, 'The path could not be empty') + t.assert.equal(e.message, 'The path could not be empty') } }) @@ -130,9 +129,9 @@ 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.equal(e.message, 'The path could not be empty') + t.assert.equal(e.message, 'The path could not be empty') } }) @@ -142,9 +141,9 @@ 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.equal(e.message, 'The path could not be empty') + t.assert.equal(e.message, 'The path could not be empty') } }) @@ -154,9 +153,9 @@ 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.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 `*`') } }) @@ -166,9 +165,9 @@ 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.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 `*`') } }) @@ -178,9 +177,9 @@ 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.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 `*`') } }) @@ -190,9 +189,9 @@ 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.equal(e.message, 'Handler should be a function') + t.assert.equal(e.message, 'Handler should be a function') } }) @@ -202,9 +201,9 @@ 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.equal(e.message, 'Method \'GETT\' is not an http method.') + t.assert.equal(e.message, 'Method \'GETT\' is not an http method.') } }) @@ -214,9 +213,9 @@ 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.equal(e.message, 'Method \'GETT\' is not an http method.') + t.assert.equal(e.message, 'Method \'GETT\' is not an http method.') } }) @@ -226,9 +225,9 @@ 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.equal(e.message, 'The default route must be a function') + t.assert.equal(e.message, 'The default route must be a function') } }) @@ -239,9 +238,9 @@ 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.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 \'{}\'') } }) @@ -252,9 +251,9 @@ 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.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') } }) @@ -265,16 +264,14 @@ 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.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') + t.assert.equal(e.message, 'Method \'GET\' already declared for route \'/*\' with constraints \'{}\'') } }) -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 }) @@ -282,20 +279,20 @@ 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.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') + t.assert.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 \'{}\'') } }) - t.test('with trailing slash', t => { + test('with trailing slash', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) @@ -303,24 +300,22 @@ 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.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') + t.assert.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 \'{}\'') } }) }) -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 }) @@ -328,20 +323,20 @@ 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.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') + t.assert.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 \'{}\'') } }) - t.test('with duplicate slashes', t => { + test('with duplicate slashes', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true }) @@ -349,16 +344,16 @@ 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.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') + t.assert.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 \'{}\'') } }) }) @@ -373,16 +368,14 @@ 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.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 \'{}\'') } }) -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 }) @@ -392,16 +385,16 @@ 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.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') + t.assert.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 \'{}\'') } }) @@ -412,13 +405,13 @@ 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.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"}\'') } }) - t.test('with trailing slash', t => { + test('with trailing slash', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreTrailingSlash: true }) @@ -428,24 +421,22 @@ 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.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') + t.assert.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 \'{}\'') } }) }) -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 }) @@ -455,20 +446,20 @@ 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.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') + t.assert.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 \'{}\'') } }) - t.test('with duplicate slashes', t => { + test('with duplicate slashes', t => { t.plan(2) const findMyWay = FindMyWay({ ignoreDuplicateSlashes: true }) @@ -478,16 +469,16 @@ 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.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') + t.assert.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..b221b73e 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 => { @@ -9,18 +8,18 @@ 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) } }) 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..5bc7892d 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 => { @@ -9,12 +8,12 @@ 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) } }) 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..bb099183 100644 --- a/test/find-route.test.js +++ b/test/find-route.test.js @@ -1,21 +1,20 @@ '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.deepStrictEqual(router1._opts, router2._opts) + t.assert.deepEqual(router1.routes, router2.routes) + t.assert.deepEqual(JSON.stringify(router1.trees), JSON.stringify(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 ) @@ -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..8dade0b6 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..ba8b8c5b 100644 --- a/test/full-url.test.js +++ b/test/full-url.test.js @@ -1,28 +1,30 @@ 'use strict' -const t = require('tap') +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"}') + }) -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' })) + 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..db3a97c6 100644 --- a/test/has-route.test.js +++ b/test/has-route.test.js @@ -1,24 +1,23 @@ '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.deepStrictEqual(router1._opts, router2._opts) + t.assert.deepEqual(router1.routes, router2.routes) + t.assert.deepEqual(JSON.stringify(router1.trees), JSON.stringify(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 ) @@ -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..4cf11131 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..51df3c0f 100644 --- a/test/issue-101.test.js +++ b/test/issue-101.test.js @@ -1,31 +1,30 @@ '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 => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) 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..78430e1e 100644 --- a/test/issue-104.test.js +++ b/test/issue-104.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('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') } }) @@ -28,14 +27,14 @@ 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 => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -55,14 +54,14 @@ 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 => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -82,14 +81,14 @@ 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 => { t.plan(11) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -133,24 +132,24 @@ 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 => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -166,14 +165,14 @@ 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 => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -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..937585d7 100644 --- a/test/issue-110.test.js +++ b/test/issue-110.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('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') } }) @@ -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..74459f71 100644 --- a/test/issue-132.test.js +++ b/test/issue-132.test.js @@ -1,31 +1,30 @@ '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 => { t.plan(5) 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.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) @@ -43,28 +42,28 @@ 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') } }) 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..52ff04c9 100644 --- a/test/issue-149.test.js +++ b/test/issue-149.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('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') } }) @@ -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..71f0c052 100644 --- a/test/issue-151.test.js +++ b/test/issue-151.test.js @@ -1,27 +1,26 @@ '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 => { 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) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) 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) @@ -31,20 +30,20 @@ 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) => { - t.equal(req.method, 'OPTIONS') + t.assert.equal(req.method, 'OPTIONS') }) 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-154.test.js b/test/issue-154.test.js index 62bc1bbf..60ec264b 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 = () => {} @@ -10,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-161.test.js b/test/issue-161.test.js index adcf090a..1fae7739 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 => { @@ -9,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') } }) @@ -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 => { @@ -28,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') } }) @@ -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 => { @@ -47,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') } }) @@ -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 => { @@ -70,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') } }) @@ -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..f9f8119e 100644 --- a/test/issue-17.test.js +++ b/test/issue-17.test.js @@ -1,19 +1,18 @@ '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 => { 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', '/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) @@ -22,32 +21,32 @@ 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', () => {}) 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') } }) 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) @@ -57,12 +56,12 @@ 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') } }) 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) @@ -75,12 +74,12 @@ 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') } }) 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) @@ -90,12 +89,12 @@ 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') } }) 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) @@ -105,18 +104,18 @@ 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') } }) 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) @@ -127,18 +126,18 @@ 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') } }) 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) @@ -149,18 +148,18 @@ 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') } }) 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,16 +170,16 @@ test('Multi parametric route / 4', t => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) 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) @@ -191,13 +190,13 @@ 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') } }) 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) @@ -207,17 +206,17 @@ 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') } }) 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) @@ -228,28 +227,28 @@ 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') } }) 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) @@ -263,18 +262,18 @@ 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') } }) 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) @@ -285,18 +284,18 @@ 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') } }) 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) @@ -307,18 +306,18 @@ 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') } }) 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) @@ -329,20 +328,20 @@ 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') } }) 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) @@ -353,20 +352,20 @@ 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') } }) 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) @@ -377,20 +376,20 @@ 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') } }) 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..c45236e6 100644 --- a/test/issue-175.test.js +++ b/test/issue-175.test.js @@ -1,17 +1,16 @@ '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 => { 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) { - t.same(params, {}) + t.assert.deepEqual(params, {}) } findMyWay.on('GET', '/name::customVerb', handler) @@ -26,22 +25,22 @@ 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 => { 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) => { - t.same(params, {}) + t.assert.deepEqual(params, {}) }) findMyWay.lookup({ method: 'GET', url: '/name:customVerb', headers: {} }, null) @@ -50,15 +49,15 @@ 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', () => { - 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) @@ -67,11 +66,11 @@ 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) => { - 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..ac4c7cbd 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,11 +8,11 @@ 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) findMyWay.on('GET', '/health-b/health', handler) - t.notMatch(findMyWay.prettyPrint(), /undefined/) + t.assert.ok(!findMyWay.prettyPrint().includes('undefined')) }) 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..d1ab5ea4 100644 --- a/test/issue-20.test.js +++ b/test/issue-20.test.js @@ -1,19 +1,18 @@ 'use strict' -const t = require('tap') -const test = t.test +const { test } = require('node:test') const FindMyWay = require('../') 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') } }) 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,12 +22,12 @@ test('Should be 404 / 1', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) 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) @@ -38,12 +37,12 @@ test('Should be 404 / 2', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) 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) @@ -53,12 +52,12 @@ test('Should be 404 / 3', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything good') + t.assert.ok('Everything good') } }) 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) @@ -68,12 +67,12 @@ 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') } }) 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..39e5f0ad 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) @@ -101,12 +100,12 @@ 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') } }) 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..13d324f6 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..1406b511 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..44423235 100644 --- a/test/issue-238.test.js +++ b/test/issue-238.test.js @@ -1,38 +1,37 @@ 'use strict' -const t = require('tap') -const test = t.test +const { test } = require('node:test') 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', () => {}) - 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' } ) @@ -41,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 = () => {} @@ -50,17 +49,17 @@ 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 => { t.plan(4) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) const jpgHandler = () => {} @@ -69,17 +68,17 @@ 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 => { t.plan(4) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) const jpgHandler = () => {} @@ -88,17 +87,17 @@ 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 => { t.plan(6) const findMyWay = FindMyWay({ - defaultRoute: () => t.fail('Should not be defaultRoute') + defaultRoute: () => t.assert.fail('Should not be defaultRoute') }) const handler = () => {} @@ -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..39b007a0 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..e5a99f03 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..9e6b4626 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..98848be8 100644 --- a/test/issue-28.test.js +++ b/test/issue-28.test.js @@ -1,30 +1,29 @@ 'use strict' -const t = require('tap') -const test = t.test +const { test } = require('node:test') const FindMyWay = require('../') 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) } }) 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['*']) + t.assert.fail('wrong parameter: ' + params['*']) } }) @@ -48,16 +47,16 @@ 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) } }) 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,19 +75,19 @@ 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) + t.assert.fail('we should not be here, the url is: ' + req.url) } } }) 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( @@ -121,20 +120,20 @@ 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) => { - t.equal(params['*'], 'test1/foo') + t.assert.equal(params['*'], 'test1/foo') }) findMyWay.lookup( @@ -147,20 +146,20 @@ 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) } }) 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) => { - 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) => { - t.equal(params['*'], 'test/foo') + t.assert.equal(params['*'], 'test/foo') }) findMyWay.lookup( @@ -178,24 +177,24 @@ 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) } }) 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) => { - 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) => { - 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( @@ -218,24 +217,24 @@ 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) => { - t.equal(params['*'], '/foo1/bar1/kuux') + t.assert.equal(params['*'], '/foo1/bar1/kuux') }) findMyWay.lookup( @@ -248,20 +247,20 @@ 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) => { - t.equal(params['*'], 'bar1/kuux') + t.assert.equal(params['*'], 'bar1/kuux') }) 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( @@ -274,20 +273,20 @@ 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) => { - t.equal(params['*'], 'bar1/kuux') + t.assert.equal(params['*'], 'bar1/kuux') }) 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( @@ -300,28 +299,28 @@ 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) => { - t.equal(params['*'], 'bar1/kuux') + t.assert.equal(params['*'], 'bar1/kuux') }) 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( @@ -334,28 +333,28 @@ 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) => { - t.equal(params.param, 'bar1') + t.assert.equal(params.param, 'bar1') }) 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( @@ -368,28 +367,28 @@ 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) => { - t.equal(req.url, '/foo4/param') + t.assert.equal(req.url, '/foo4/param') }) findMyWay.lookup( @@ -402,28 +401,28 @@ 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) => { - t.equal(req.url, '/foo1/param') + t.assert.equal(req.url, '/foo1/param') }) findMyWay.lookup( @@ -436,28 +435,28 @@ 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) => { - t.equal(params['*'], 'param/hello/test/long/routee') + t.assert.equal(params['*'], 'param/hello/test/long/routee') }) 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( @@ -470,28 +469,28 @@ 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) } }) 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) => { - 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( @@ -504,32 +503,32 @@ 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) => { - t.equal(params.param, 'hello') + t.assert.equal(params.param, 'hello') }) 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( @@ -542,32 +541,32 @@ 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) => { - t.equal(params['*'], 'hello/world') + t.assert.equal(params['*'], 'hello/world') }) 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( @@ -580,20 +579,20 @@ 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) } }) 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) => { - 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( @@ -609,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-280.test.js b/test/issue-280.test.js index b1b2ec1d..b05fda82 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..2fa564fd 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..13b4f605 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') @@ -11,13 +10,13 @@ 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) => { 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')) }) @@ -26,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 } @@ -40,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) => { @@ -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) => { @@ -71,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 => { @@ -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) => { @@ -98,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!" }) }) @@ -110,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) => { @@ -118,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) => { @@ -127,20 +126,20 @@ 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) => { 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) => { @@ -170,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) => { @@ -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 => { @@ -209,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')) }) @@ -218,15 +217,15 @@ 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' }) + t.assert.deepStrictEqual(storage.get('foo'), { bar: 'baz' }) }) 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..80e4f0aa 100644 --- a/test/issue-44.test.js +++ b/test/issue-44.test.js @@ -1,23 +1,22 @@ '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 => { 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.equal(params.param, 'winter') + t.assert.equal(params.param, 'winter') }) findMyWay.lookup({ method: 'GET', url: '/winter', headers: {} }, null) @@ -27,16 +26,16 @@ 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') } }) 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) => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) findMyWay.lookup({ method: 'GET', url: '/woo', headers: {} }, null) @@ -46,16 +45,16 @@ 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') } }) 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) @@ -65,16 +64,16 @@ 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) => { - t.ok('We should be here') + t.assert.ok('We should be here') }) findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/other', headers: {} }, null) @@ -84,20 +83,20 @@ 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) => { - t.equal(params.param, 'winter') + t.assert.equal(params.param, 'winter') }) 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) @@ -107,20 +106,20 @@ 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) => { - t.equal(params['*'], 'winter/coming') + t.assert.equal(params['*'], 'winter/coming') }) findMyWay.lookup({ method: 'GET', url: '/winter/coming', headers: {} }, null) @@ -130,20 +129,20 @@ 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) => { - t.equal(params.param, 'winter') + t.assert.equal(params.param, 'winter') }) 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 963c8407..ba99726b 100644 --- a/test/issue-46.test.js +++ b/test/issue-46.test.js @@ -1,29 +1,28 @@ '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 => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) 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 => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -32,16 +31,16 @@ 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 => { t.plan(3) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -51,16 +50,16 @@ 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 => { t.plan(4) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) @@ -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..cf5430d7 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..7a3a6d4e 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,9 +115,9 @@ 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.not(findMyWay.find('GET', '/static/foo/static/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/bulk'), null) + t.assert.equal(findMyWay.find('GET', '/static/foo/bulk'), null) + t.assert.notEqual(findMyWay.find('GET', '/static/foo/static/bulk'), null) }) test('wildcard / 1', t => { @@ -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..55bee948 100644 --- a/test/issue-63.test.js +++ b/test/issue-63.test.js @@ -1,23 +1,23 @@ '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() - t.throws(function () { + t.assert.throws(function () { fmw.on('GET', '/foo/:id(a', noop) }) 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..ac9cf59a 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..6e57d81d 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..e1ba2c5e 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..f7bfa020 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..1f7cb952 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..9e397d1e 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..58f5af16 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,17 +8,17 @@ 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 => { t.plan(1) const findMyWay = FindMyWay() - t.throws(() => { + t.assert.throws(() => { findMyWay.on('INVALID', '/a/b') }) }) @@ -29,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') }) }) @@ -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 ) @@ -84,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') }) }) @@ -94,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') }) }) @@ -113,12 +112,12 @@ 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) } }) 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,11 +558,11 @@ 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', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -574,11 +573,11 @@ 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', () => { - t.pass('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.lookup({ method: 'GET', url: '/test/hello', headers: {} }, null) @@ -589,19 +588,19 @@ 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', () => { - t.ok('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.on('GET', '/test/:id', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) 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,19 +612,19 @@ 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', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.on('GET', '/test/:id', () => { - t.ok('inside correct handler') + t.assert.ok('inside correct handler') }) findMyWay.on('GET', '/test/hello', () => { - t.fail('wrong handler') + t.assert.fail('wrong handler') }) findMyWay.lookup({ method: 'GET', url: '/test/id', headers: {} }, null) @@ -637,16 +636,16 @@ 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') } }) 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) => { - t.equal(params.param, 'other') + t.assert.equal(params.param, 'other') }) findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/oopss', headers: {} }, null) @@ -658,18 +657,18 @@ 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) 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 @@ -677,11 +676,12 @@ 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') + done() }, 10) } first = false @@ -695,12 +695,12 @@ test('Unsupported method (static)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything ok') + t.assert.ok('Everything ok') } }) 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) @@ -710,12 +710,12 @@ test('Unsupported method (wildcard)', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.pass('Everything ok') + t.assert.ok('Everything ok') } }) 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) @@ -727,7 +727,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 +736,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 +751,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 +771,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 +784,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 +799,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 => { @@ -807,12 +807,12 @@ 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.doesNotThrow(() => findMyWay.off('GET', '/', undefined)) - t.doesNotThrow(() => findMyWay.off('GET', '/', {})) - t.doesNotThrow(() => 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.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 => { @@ -825,6 +825,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..6f225b16 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..3bc211e4 100644 --- a/test/on-bad-url.test.js +++ b/test/on-bad-url.test.js @@ -1,41 +1,40 @@ '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 => { 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.equal(path, '/%world', { todo: 'this is not executed' }) + t.assert.equal(path, '/%world', { todo: 'this is not executed' }) } }) 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') - t.not(handle, null) + t.assert.notDeepStrictEqual(handle, null) }) test('If onBadUrl is defined, then a bad url should be handled differently (lookup)', t => { 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.equal(path, '/hello/%world') + t.assert.equal(path, '/hello/%world') } }) 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) @@ -45,28 +44,28 @@ 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') - 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') } }) 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 16650654..844181d5 100644 --- a/test/optional-params.test.js +++ b/test/optional-params.test.js @@ -1,22 +1,21 @@ '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) => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) 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) } }) @@ -28,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') } }) @@ -36,9 +35,9 @@ 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.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 \'{}\'') } }) @@ -46,15 +45,15 @@ 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.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') } }) @@ -62,14 +61,14 @@ 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') } }) 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') } }) @@ -82,15 +81,15 @@ 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') } }) 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) } }) @@ -105,17 +104,17 @@ test('Optional Parameter with ignoreTrailingSlash = false', (t) => { const findMyWay = FindMyWay({ ignoreTrailingSlash: false, defaultRoute: (req, res) => { - t.match(req.url, '/test/hello/foo/') + t.assert.equal(req.url, '/test/hello/foo/') } }) 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' }) } }) @@ -130,15 +129,15 @@ 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') } }) 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' }) } }) @@ -181,34 +180,34 @@ 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') } }) 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) => { t.plan(2) const findMyWay = FindMyWay({ defaultRoute: (req, res) => { - t.fail('Should not be defaultRoute') + t.assert.fail('Should not be defaultRoute') } }) 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..03fac6bc 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 => { @@ -40,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 => { @@ -49,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 => { @@ -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..3978017d 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..39f49fd7 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..d02e8d43 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..5b89521d 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..f73b97bd 100644 --- a/test/regex.test.js +++ b/test/regex.test.js @@ -1,19 +1,18 @@ 'use strict' -const t = require('tap') -const test = t.test +const { test } = require('node:test') const FindMyWay = require('../') test('route with matching regex', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) 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,12 +22,12 @@ test('route without matching regex', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) findMyWay.on('GET', '/test/:id(^\\d+$)', () => { - t.fail('regex match') + t.assert.fail('regex match') }) findMyWay.lookup({ method: 'GET', url: '/test/test', headers: {} }, null) @@ -38,14 +37,14 @@ 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', () => { - 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) @@ -55,12 +54,12 @@ 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') } }) 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) @@ -70,13 +69,13 @@ 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') } }) 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) @@ -86,13 +85,13 @@ 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') } }) 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,12 +101,12 @@ 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') } }) 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) @@ -117,12 +116,12 @@ 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') } }) 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,12 +131,12 @@ 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') } }) 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) @@ -147,15 +146,15 @@ test('safe decodeURIComponent', t => { t.plan(1) const findMyWay = FindMyWay({ defaultRoute: () => { - t.ok('route not matched') + t.assert.ok('route not matched') } }) findMyWay.on('GET', '/test/:id(^\\d+$)', () => { - t.fail('we should not be here') + t.assert.fail('we should not be here') }) - t.same( + t.assert.deepEqual( findMyWay.find('GET', '/test/hel%"Flo', {}), null ) @@ -191,19 +190,19 @@ 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) + 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.ok(err) + t.assert.ok(err) } }) }) @@ -238,31 +237,30 @@ 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) + t.assert.fail(err) } }) 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) + t.assert.fail(err) } }) }) -test('prevent back-tracking', (t) => { +test('prevent back-tracking', { timeout: 20 }, (t) => { t.plan(0) - t.setTimeout(20) const findMyWay = FindMyWay({ defaultRoute: () => { - t.fail('route not matched') + t.assert.fail('route not matched') } }) diff --git a/test/routes-registered.test.js b/test/routes-registered.test.js index 354a1a03..dd5eef2e 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) { @@ -11,23 +11,22 @@ 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' })) 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', - 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) }) }) @@ -40,7 +39,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..55087ac7 100644 --- a/test/server.test.js +++ b/test/server.test.js @@ -1,17 +1,16 @@ 'use strict' -const t = require('tap') -const test = t.test +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) => { - 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' })) }) @@ -19,28 +18,25 @@ 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.ifError(err) server.unref() - http.get('http://localhost:' + server.address().port + '/test', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.equal(res.statusCode, 200) - t.same(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) => { - 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' })) }) @@ -48,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.ifError(err) server.unref() - http.get('http://localhost:' + server.address().port + '/test/hello', async (res) => { - let body = '' - for await (const chunk of res) { - body += chunk - } - t.equal(res.statusCode, 200) - t.same(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) => { @@ -76,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.ifError(err) server.unref() - http.get('http://localhost:' + server.address().port, async (res) => { - t.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() @@ -94,33 +87,33 @@ test('automatic default route', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.ifError(err) server.unref() - http.get('http://localhost:' + server.address().port, async (res) => { - t.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 }) 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') }) @@ -128,60 +121,42 @@ 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.ifError(err) 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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 200) - t.same(body, 'othertest') - }) + res = await fetch(`${baseURL}/othertest/`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'othertest') + + 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 }) 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') }) @@ -189,37 +164,33 @@ test('does not trim trailing slash when ignoreTrailingSlash is false', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.ifError(err) 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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 404) - }) + res = await fetch(`${baseURL}/test`) + t.assert.equal(res.status, 404) + + 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 }) 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') }) @@ -227,44 +198,40 @@ test('does not map // when ignoreTrailingSlash is true', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.ifError(err) 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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 404) - }) + res = await fetch(`${baseURL}//`) + t.assert.equal(res.status, 404) + + 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 }) 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') }) @@ -272,60 +239,42 @@ test('maps two routes when duplicate slashes should be trimmed', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.ifError(err) 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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 200) - t.same(body, 'othertest') - }) + res = await fetch(`${baseURL}//othertest`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'othertest') + + 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 }) 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') }) @@ -333,37 +282,33 @@ test('does not trim duplicate slashes when ignoreDuplicateSlashes is false', t = findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.ifError(err) 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.equal(res.statusCode, 200) - t.same(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.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 }) 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') }) @@ -371,33 +316,25 @@ test('does map // when ignoreDuplicateSlashes is true', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.ifError(err) 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.equal(res.statusCode, 200) - t.same(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.equal(res.statusCode, 200) - t.same(body, 'test') - }) + res = await fetch(`${baseURL}//`) + t.assert.equal(res.status, 200) + t.assert.deepEqual(await res.text(), 'test') + + done() }) }) -test('versioned routes', t => { +test('versioned routes', (t, done) => { t.plan(3) const findMyWay = FindMyWay() @@ -410,28 +347,22 @@ test('versioned routes', t => { findMyWay.lookup(req, res) }) - server.listen(0, err => { - t.error(err) + server.listen(0, async err => { + t.assert.ifError(err) server.unref() - http.get( - 'http://localhost:' + server.address().port + '/test', - { - headers: { 'Accept-Version': '1.x' } - }, - async (res) => { - t.equal(res.statusCode, 200) - } - ) - - http.get( - 'http://localhost:' + server.address().port + '/test', - { - headers: { 'Accept-Version': '2.x' } - }, - async (res) => { - t.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() }) }) diff --git a/test/shorthands.test.js b/test/shorthands.test.js index 8bb513b0..f2998a20 100644 --- a/test/shorthands.test.js +++ b/test/shorthands.test.js @@ -1,23 +1,20 @@ 'use strict' const httpMethods = require('../lib/http-methods') -const t = require('tap') -const test = t.test +const { describe, test } = require('node:test') const FindMyWay = require('../') -t.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() findMyWay[methodName]('/test', () => { - t.ok('inside the handler') + t.assert.ok('inside the handler') }) findMyWay.lookup({ method: m, url: '/test', headers: {} }, null) @@ -30,7 +27,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..51ca8c54 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' })