Skip to content

Commit

Permalink
test: migrated plugin-loaded-so-far.test.js from tap to node:test (#296)
Browse files Browse the repository at this point in the history
* test: migrated plugin-loaded-so-far.test.js from tap to node:test

* Use assert.doesNotReject

---------

Co-authored-by: hanquliu <hanquliu@futunn.com>
  • Loading branch information
liuhanqu and hanquliu authored Jan 23, 2025
1 parent 21100b4 commit 6acb99f
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions test/plugin-loaded-so-far.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const fastq = require('fastq')
const boot = require('..')
const { Plugin } = require('../lib/plugin')

test('loadedSoFar resolves a Promise, if plugin.loaded is set to true', async (t) => {
t.plan(1)
const app = boot({})

const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
Expand All @@ -15,28 +14,27 @@ test('loadedSoFar resolves a Promise, if plugin.loaded is set to true', async (t

plugin.loaded = true

await t.resolves(plugin.loadedSoFar())
await t.assert.doesNotReject(() => plugin.loadedSoFar())
})

test('loadedSoFar resolves a Promise, if plugin was loaded by avvio', async (t) => {
t.plan(2)
t.plan(1)
const app = boot({})

const plugin = new Plugin(fastq(app, app._loadPluginNextTick, 1), function (instance, opts, done) {
done()
}, false, 0)

app._loadPlugin(plugin, function (err) {
t.equal(err, undefined)
t.assert.ifError(err)
})

await app.ready()

await t.resolves(plugin.loadedSoFar())
await plugin.loadedSoFar()
})

test('loadedSoFar resolves a Promise, if .after() has no error', async t => {
t.plan(1)
const app = boot()

app.after = function (callback) {
Expand All @@ -49,7 +47,7 @@ test('loadedSoFar resolves a Promise, if .after() has no error', async t => {

app._loadPlugin(plugin, function () {})

await t.resolves(plugin.loadedSoFar())
await plugin.loadedSoFar()
})

test('loadedSoFar rejects a Promise, if .after() has an error', async t => {
Expand All @@ -66,12 +64,10 @@ test('loadedSoFar rejects a Promise, if .after() has an error', async t => {

app._loadPlugin(plugin, function () {})

await t.rejects(plugin.loadedSoFar(), new Error('ArbitraryError'))
await t.assert.rejects(plugin.loadedSoFar(), new Error('ArbitraryError'))
})

test('loadedSoFar resolves a Promise, if Plugin is attached to avvio after it the Plugin was instantiated', async t => {
t.plan(1)

const plugin = new Plugin(fastq(null, null, 1), function (instance, opts, done) {
done()
}, false, 0)
Expand All @@ -80,5 +76,6 @@ test('loadedSoFar resolves a Promise, if Plugin is attached to avvio after it th

plugin.server = boot()
plugin.emit('start')
await t.resolves(promise)

await t.assert.doesNotReject(promise)
})

0 comments on commit 6acb99f

Please sign in to comment.