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 2 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 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": "^7.12.0",
"tsd": "^0.31.0"
},
"pre-commit": [
Expand All @@ -50,4 +50,4 @@
"publishConfig": {
"access": "public"
}
}
}
37 changes: 18 additions & 19 deletions test/fastify-env.test.js
Original file line number Diff line number Diff line change
@@ -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 => {

Check failure on line 13 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 4 spaces but found 6
if (isOk) {

Check failure on line 14 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 6 spaces but found 8
t.assert.equal(err, null)

Check failure on line 15 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 8 spaces but found 10
t.assert.deepEqual(fastify.config, confExpected)

Check failure on line 16 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 8 spaces but found 10
return

Check failure on line 17 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 8 spaces but found 10
}

Check failure on line 18 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 6 spaces but found 8
t.assert.equal(err.message, errorMessage)

Check failure on line 19 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 6 spaces but found 8
})

Check failure on line 20 in test/fastify-env.test.js

View workflow job for this annotation

GitHub Actions / test / Lint Code

Expected indentation of 4 spaces but found 6
}

const tests = [
Expand Down Expand Up @@ -261,7 +260,7 @@
})

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 @@
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 @@
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',
Expand Down Expand Up @@ -342,6 +341,6 @@
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')
})
Loading