Skip to content

Commit

Permalink
test: migrated reentrant.test.js from tap to node:test (#294)
Browse files Browse the repository at this point in the history
Co-authored-by: hanquliu <[email protected]>
  • Loading branch information
liuhanqu and hanquliu authored Jan 3, 2025
1 parent 8bd7e10 commit 6a2c669
Showing 1 changed file with 49 additions and 47 deletions.
96 changes: 49 additions & 47 deletions test/reentrant.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const { test } = require('tap')
const { test } = require('node:test')
const boot = require('..')

test('one level', (t) => {
test('one level', (t, testDone) => {
t.plan(13)

const app = boot()
Expand All @@ -15,39 +15,40 @@ test('one level', (t) => {
app.use(third)

function first (s, opts, done) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.assert.strictEqual(firstLoaded, false, 'first is not loaded')
t.assert.strictEqual(secondLoaded, false, 'second is not loaded')
t.assert.strictEqual(thirdLoaded, false, 'third is not loaded')
firstLoaded = true
s.use(second)
done()
}

function second (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.strictEqual(secondLoaded, false, 'second is not loaded')
t.assert.strictEqual(thirdLoaded, false, 'third is not loaded')
secondLoaded = true
done()
}

function third (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.ok(secondLoaded, 'second is loaded')
t.assert.strictEqual(thirdLoaded, false, 'third is not loaded')
thirdLoaded = true
done()
}

app.on('start', () => {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.pass('booted')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.ok(secondLoaded, 'second is loaded')
t.assert.ok(thirdLoaded, 'third is loaded')
t.assert.ok('booted')
testDone()
})
})

test('multiple reentrant plugin loading', (t) => {
test('multiple reentrant plugin loading', (t, testDone) => {
t.plan(31)

const app = boot()
Expand All @@ -61,64 +62,65 @@ test('multiple reentrant plugin loading', (t) => {
app.use(fifth)

function first (s, opts, done) {
t.notOk(firstLoaded, 'first is not loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
t.assert.strictEqual(firstLoaded, false, 'first is not loaded')
t.assert.strictEqual(secondLoaded, false, 'second is not loaded')
t.assert.strictEqual(thirdLoaded, false, 'third is not loaded')
t.assert.strictEqual(fourthLoaded, false, 'fourth is not loaded')
t.assert.strictEqual(fifthLoaded, false, 'fifth is not loaded')
firstLoaded = true
s.use(second)
done()
}

function second (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.notOk(secondLoaded, 'second is not loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.strictEqual(secondLoaded, false, 'second is not loaded')
t.assert.strictEqual(thirdLoaded, false, 'third is not loaded')
t.assert.strictEqual(fourthLoaded, false, 'fourth is not loaded')
t.assert.strictEqual(fifthLoaded, false, 'fifth is not loaded')
secondLoaded = true
s.use(third)
s.use(fourth)
done()
}

function third (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.notOk(thirdLoaded, 'third is not loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.ok(secondLoaded, 'second is loaded')
t.assert.strictEqual(thirdLoaded, false, 'third is not loaded')
t.assert.strictEqual(fourthLoaded, false, 'fourth is not loaded')
t.assert.strictEqual(fifthLoaded, false, 'fifth is not loaded')
thirdLoaded = true
done()
}

function fourth (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.notOk(fourthLoaded, 'fourth is not loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.ok(secondLoaded, 'second is loaded')
t.assert.ok(thirdLoaded, 'third is loaded')
t.assert.strictEqual(fourthLoaded, false, 'fourth is not loaded')
t.assert.strictEqual(fifthLoaded, false, 'fifth is not loaded')
fourthLoaded = true
done()
}

function fifth (s, opts, done) {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
t.notOk(fifthLoaded, 'fifth is not loaded')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.ok(secondLoaded, 'second is loaded')
t.assert.ok(thirdLoaded, 'third is loaded')
t.assert.ok(fourthLoaded, 'fourth is loaded')
t.assert.strictEqual(fifthLoaded, false, 'fifth is not loaded')
fifthLoaded = true
done()
}

app.on('start', () => {
t.ok(firstLoaded, 'first is loaded')
t.ok(secondLoaded, 'second is loaded')
t.ok(thirdLoaded, 'third is loaded')
t.ok(fourthLoaded, 'fourth is loaded')
t.ok(fifthLoaded, 'fifth is loaded')
t.pass('booted')
t.assert.ok(firstLoaded, 'first is loaded')
t.assert.ok(secondLoaded, 'second is loaded')
t.assert.ok(thirdLoaded, 'third is loaded')
t.assert.ok(fourthLoaded, 'fourth is loaded')
t.assert.ok(fifthLoaded, 'fifth is loaded')
t.assert.ok('booted')
testDone()
})
})

0 comments on commit 6a2c669

Please sign in to comment.