From 1ecfa5aa1f6be53ddaac60d62d2eff432f235d1d Mon Sep 17 00:00:00 2001 From: narendra Date: Mon, 9 Sep 2024 12:18:30 +0530 Subject: [PATCH 1/5] migrated tap to node:test with c8 coverage --- package.json | 8 ++++---- test/fastify-env.test.js | 37 ++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 00db134..d0607ae 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,12 @@ "type": "commonjs", "types": "types/index.d.ts", "scripts": { - "coverage": "cross-env VALUE_FROM_ENV=pippo tap --coverage-report=html", + "coverage": "cross-env VALUE_FROM_ENV=pippo c8 --reporter=html node --test", "lint": "standard | snazzy", "lint:fix": "standard --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", - "test:unit": "cross-env VALUE_FROM_ENV=pippo tap" + "test:unit": "c8 cross-env VALUE_FROM_ENV=pippo node --test" }, "repository": { "type": "git", @@ -37,7 +37,7 @@ "fastify": "^5.0.0-alpha.4", "snazzy": "^9.0.0", "standard": "^17.1.0", - "tap": "^20.0.1", + "c8": "^7.12.0", "tsd": "^0.31.0" }, "pre-commit": [ @@ -50,4 +50,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/test/fastify-env.test.js b/test/fastify-env.test.js index fe53e88..922c6de 100644 --- a/test/fastify-env.test.js +++ b/test/fastify-env.test.js @@ -1,24 +1,23 @@ 'use strict' -const t = require('tap') +const t = require('node:test') const path = require('node:path') const Fastify = require('fastify') const fastifyEnv = require('../index') function makeTest (t, options, isOk, confExpected, errorMessage) { - t.plan(isOk ? 2 : 1) + // t.plan(isOk ? 2 : 1) const fastify = Fastify() fastify.register(fastifyEnv, options) - .ready(err => { - if (isOk) { - t.notOk(err) - t.strictSame(fastify.config, confExpected) - return - } - - t.strictSame(err.message, errorMessage) - }) + .ready(err => { + if (isOk) { + t.assert.equal(err, null) + t.assert.deepEqual(fastify.config, confExpected) + return + } + t.assert.equal(err.message, errorMessage) + }) } const tests = [ @@ -261,7 +260,7 @@ tests.forEach(function (testConf) { }) t.test('should use custom config key name', t => { - t.plan(1) + // t.plan(1) const schema = { type: 'object', required: ['PORT'], @@ -279,12 +278,12 @@ t.test('should use custom config key name', t => { confKey: 'customConfigKeyName' }) .ready(() => { - t.strictSame(fastify.customConfigKeyName, { PORT: 6666 }) + t.assert.deepEqual(fastify.customConfigKeyName, { PORT: 6666 }) }) }) t.test('should use function `getEnvs` to retrieve the envs object', async t => { - t.plan(2) + // t.plan(2) const schema = { type: 'object', @@ -310,11 +309,11 @@ t.test('should use function `getEnvs` to retrieve the envs object', async t => { url: '/' }) - t.strictSame(requestEnvs, { PORT: 6666 }) - t.strictSame(fastify.getEnvs(), { PORT: 6666 }) + t.assert.deepEqual(requestEnvs, { PORT: 6666 }) + t.assert.deepEqual(fastify.getEnvs(), { PORT: 6666 }) }) t.test('should skip the getEnvs decorators if there is already one with the same name', async t => { - t.plan(2) + // t.plan(2) const schema = { type: 'object', @@ -342,6 +341,6 @@ t.test('should skip the getEnvs decorators if there is already one with the same url: '/' }) - t.strictSame(requestEnvs, 'another_value') - t.strictSame(fastify.getEnvs(), 'another_value') + t.assert.equal(requestEnvs, 'another_value') + t.assert.equal(fastify.getEnvs(), 'another_value') }) From ecac51b97a0c14aec5ba6ec71d3cf3aefc578f0b Mon Sep 17 00:00:00 2001 From: narendra Date: Mon, 9 Sep 2024 12:22:25 +0530 Subject: [PATCH 2/5] removed .taprc --- .taprc | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .taprc diff --git a/.taprc b/.taprc deleted file mode 100644 index ceb5f77..0000000 --- a/.taprc +++ /dev/null @@ -1,2 +0,0 @@ -files: - - test/**.test.js From d7de7e3e9b68423ad28cf8ef1a3ebbdfd671770a Mon Sep 17 00:00:00 2001 From: narendra Date: Mon, 9 Sep 2024 13:32:44 +0530 Subject: [PATCH 3/5] fixed linting issues --- test/fastify-env.test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/fastify-env.test.js b/test/fastify-env.test.js index 922c6de..37008cc 100644 --- a/test/fastify-env.test.js +++ b/test/fastify-env.test.js @@ -10,14 +10,14 @@ function makeTest (t, options, isOk, confExpected, errorMessage) { const fastify = Fastify() fastify.register(fastifyEnv, options) - .ready(err => { - if (isOk) { - t.assert.equal(err, null) - t.assert.deepEqual(fastify.config, confExpected) - return - } - t.assert.equal(err.message, errorMessage) - }) + .ready(err => { + if (isOk) { + t.assert.equal(err, null) + t.assert.deepEqual(fastify.config, confExpected) + return + } + t.assert.equal(err.message, errorMessage) + }) } const tests = [ From 8edd0cc39ab2cba426e04cc7c30136a646aeeb95 Mon Sep 17 00:00:00 2001 From: narendra Date: Mon, 9 Sep 2024 13:33:07 +0530 Subject: [PATCH 4/5] updated c8 to v10 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d0607ae..cac18d7 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "lint:fix": "standard --fix", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", - "test:unit": "c8 cross-env VALUE_FROM_ENV=pippo node --test" + "test:unit": "c8 --100 cross-env VALUE_FROM_ENV=pippo node --test" }, "repository": { "type": "git", @@ -37,7 +37,7 @@ "fastify": "^5.0.0-alpha.4", "snazzy": "^9.0.0", "standard": "^17.1.0", - "c8": "^7.12.0", + "c8": "^10.1.2", "tsd": "^0.31.0" }, "pre-commit": [ From c025b69bf93561ad4204cc4ffb07bc38e89ec08b Mon Sep 17 00:00:00 2001 From: narendra Date: Tue, 10 Sep 2024 17:39:44 +0530 Subject: [PATCH 5/5] added t.plan and fixed failing tests --- package.json | 2 +- test/fastify-env.test.js | 53 +++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index cac18d7..218050a 100644 --- a/package.json +++ b/package.json @@ -50,4 +50,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/test/fastify-env.test.js b/test/fastify-env.test.js index 37008cc..ac63540 100644 --- a/test/fastify-env.test.js +++ b/test/fastify-env.test.js @@ -5,19 +5,23 @@ const path = require('node:path') const Fastify = require('fastify') const fastifyEnv = require('../index') -function makeTest (t, options, isOk, confExpected, errorMessage) { - // t.plan(isOk ? 2 : 1) +async function makeTest (t, options, isOk, confExpected, errorMessage) { + t.plan(isOk ? 2 : 1) const fastify = Fastify() - fastify.register(fastifyEnv, options) - .ready(err => { - if (isOk) { - t.assert.equal(err, null) - t.assert.deepEqual(fastify.config, confExpected) - return - } - t.assert.equal(err.message, errorMessage) - }) + try { + await fastify.register(fastifyEnv, options) + await fastify.ready() + + if (isOk) { + t.assert.ifError(null) + t.assert.deepStrictEqual(fastify.config, confExpected) + } + } catch (err) { + if (!isOk) { + t.assert.deepStrictEqual(err.message, errorMessage) + } + } } const tests = [ @@ -247,7 +251,7 @@ const tests = [ ] tests.forEach(function (testConf) { - t.test(testConf.name, t => { + t.test(testConf.name, async t => { const options = { schema: testConf.schema, data: testConf.data, @@ -255,12 +259,12 @@ tests.forEach(function (testConf) { dotenvConfig: testConf.dotenvConfig } - makeTest(t, options, testConf.isOk, testConf.confExpected, testConf.errorMessage) + await makeTest(t, options, testConf.isOk, testConf.confExpected, testConf.errorMessage) }) }) -t.test('should use custom config key name', t => { - // t.plan(1) +t.test('should use custom config key name', async (t) => { + t.plan(1) const schema = { type: 'object', required: ['PORT'], @@ -273,17 +277,16 @@ t.test('should use custom config key name', t => { } const fastify = Fastify() - fastify.register(fastifyEnv, { + await fastify.register(fastifyEnv, { schema, confKey: 'customConfigKeyName' }) - .ready(() => { - t.assert.deepEqual(fastify.customConfigKeyName, { PORT: 6666 }) - }) + await fastify.ready() + t.assert.deepStrictEqual(fastify.customConfigKeyName, { PORT: 6666 }) }) t.test('should use function `getEnvs` to retrieve the envs object', async t => { - // t.plan(2) + t.plan(2) const schema = { type: 'object', @@ -309,11 +312,11 @@ t.test('should use function `getEnvs` to retrieve the envs object', async t => { url: '/' }) - t.assert.deepEqual(requestEnvs, { PORT: 6666 }) - t.assert.deepEqual(fastify.getEnvs(), { PORT: 6666 }) + t.assert.deepStrictEqual(requestEnvs, { PORT: 6666 }) + t.assert.deepStrictEqual(fastify.getEnvs(), { PORT: 6666 }) }) t.test('should skip the getEnvs decorators if there is already one with the same name', async t => { - // t.plan(2) + t.plan(2) const schema = { type: 'object', @@ -341,6 +344,6 @@ t.test('should skip the getEnvs decorators if there is already one with the same url: '/' }) - t.assert.equal(requestEnvs, 'another_value') - t.assert.equal(fastify.getEnvs(), 'another_value') + t.assert.deepStrictEqual(requestEnvs, 'another_value') + t.assert.deepStrictEqual(fastify.getEnvs(), 'another_value') })