Skip to content

test: migrated expose.test.js from tap to node:test #289

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
21 changes: 10 additions & 11 deletions test/expose.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const boot = require('..')
const { AVV_ERR_EXPOSE_ALREADY_DEFINED, AVV_ERR_ATTRIBUTE_ALREADY_DEFINED } = require('../lib/errors')
const { kAvvio } = require('../lib/symbols')
Expand All @@ -12,7 +12,7 @@ for (const key of ['use', 'after', 'ready', 'onClose', 'close']) {
const app = {}
app[key] = () => { }

t.throws(() => boot(app), new AVV_ERR_EXPOSE_ALREADY_DEFINED(key, key))
t.assert.throws(() => boot(app), new AVV_ERR_EXPOSE_ALREADY_DEFINED(key, key))
})

test('throws if ' + key + ' is already there', (t) => {
Expand All @@ -21,7 +21,7 @@ for (const key of ['use', 'after', 'ready', 'onClose', 'close']) {
const app = {}
app['cust' + key] = () => { }

t.throws(() => boot(app, { expose: { [key]: 'cust' + key } }), new AVV_ERR_EXPOSE_ALREADY_DEFINED('cust' + key, key))
t.assert.throws(() => boot(app, { expose: { [key]: 'cust' + key } }), new AVV_ERR_EXPOSE_ALREADY_DEFINED('cust' + key, key))
})

test('support expose for ' + key, (t) => {
Expand All @@ -34,8 +34,6 @@ for (const key of ['use', 'after', 'ready', 'onClose', 'close']) {
boot(app, {
expose
})

t.end()
})
}

Expand All @@ -45,10 +43,10 @@ test('set the kAvvio to true on the server', (t) => {
const server = {}
boot(server)

t.ok(server[kAvvio])
t.assert.ok(server[kAvvio])
})

test('.then()', t => {
test('.then()', (t, testDone) => {
t.plan(3)

t.test('.then() can not be overwritten', (t) => {
Expand All @@ -57,16 +55,15 @@ test('.then()', t => {
const server = {
then: () => {}
}
t.throws(() => boot(server), AVV_ERR_ATTRIBUTE_ALREADY_DEFINED('then'))
t.assert.throws(() => boot(server), AVV_ERR_ATTRIBUTE_ALREADY_DEFINED('then'))
})

t.test('.then() is a function', (t) => {
t.plan(1)

const server = {}
boot(server)

t.type(server.then, 'function')
t.assert.strictEqual(typeof server.then, 'function')
})

t.test('.then() can not be overwritten', (t) => {
Expand All @@ -75,6 +72,8 @@ test('.then()', t => {
const server = {}
boot(server)

t.throws(() => { server.then = 'invalid' }, TypeError('Cannot set property then of #<Object> which has only a getter'))
t.assert.throws(() => { server.then = 'invalid' }, TypeError('Cannot set property then of #<Object> which has only a getter'))
})

process.nextTick(testDone)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member

@gurgunday gurgunday Mar 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the question

})
Loading