Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate test suite from tap to node:test #190

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .taprc

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 --100 cross-env VALUE_FROM_ENV=pippo node --test"
},
"repository": {
"type": "git",
Expand All @@ -37,7 +37,7 @@
"fastify": "^5.0.0-alpha.4",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
"tap": "^20.0.1",
"c8": "^10.1.2",
"tsd": "^0.31.0"
},
"pre-commit": [
Expand All @@ -50,4 +50,4 @@
"publishConfig": {
"access": "public"
}
}
}
simoneb marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 13 additions & 14 deletions test/fastify-env.test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
'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)
t.assert.equal(err, null)
t.assert.deepEqual(fastify.config, confExpected)
return
}

t.strictSame(err.message, errorMessage)
t.assert.equal(err.message, errorMessage)
})
}

Expand Down Expand Up @@ -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'],
Expand All @@ -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',
Expand All @@ -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)
narendra-reddy-nf marked this conversation as resolved.
Show resolved Hide resolved

const schema = {
type: 'object',
Expand Down Expand Up @@ -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')
})