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

Test: #5555 - move to node test runner #191

Merged
merged 9 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .borp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
files:
- 'test/**/*.test.js'
2 changes: 0 additions & 2 deletions .taprc

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint:fix": "eslint --fix",
"test": "npm run test:unit && npm run test:typescript",
"test:typescript": "tsd",
"test:unit": "tap"
"test:unit": "borp -C --check-coverage --reporter=@jsumners/line-reporter"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -59,11 +59,12 @@
],
"devDependencies": {
"@fastify/pre-commit": "^2.1.0",
"@jsumners/line-reporter": "^1.0.1",
"@types/node": "^22.0.0",
"borp": "^0.19.0",
"eslint": "^9.17.0",
"fastify": "^5.0.0",
"neostandard": "^0.12.0",
"tap": "^18.7.1",
"tsd": "^0.31.0"
},
"dependencies": {
Expand Down
155 changes: 86 additions & 69 deletions test/assert.test.js
Original file line number Diff line number Diff line change
@@ -1,263 +1,280 @@
'use strict'

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

const Fastify = require('fastify')
const Sensible = require('../index')

test('Should support basic assert', t => {
test('Should support basic assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert(true)
t.pass('Works correctly')
fastify.assert.ok(true)
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support ok assert', t => {
test('Should support ok assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.ok(true)
t.pass('Works correctly')
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support equal assert', t => {
test('Should support equal assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.equal(1, '1')
t.pass('Works correctly')
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support not equal assert', t => {
test('Should support not equal assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.notEqual(1, '2')
t.pass('Works correctly')
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support strict equal assert', t => {
test('Should support strict equal assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.strictEqual(1, 1)
t.pass('Works correctly')
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support not strict equal assert', t => {
test('Should support not strict equal assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.notStrictEqual(1, 2)
t.pass('Works correctly')
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support deep equal assert', t => {
test('Should support deep equal assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.deepEqual({ hello: 'world' }, { hello: 'world' })
t.pass('Works correctly')
fastify.assert.deepEqual({ a: 1 }, { a: 1 })
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support not deep equal assert', t => {
test('Should support not deep equal assert', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.notDeepEqual({ hello: 'world' }, { hello: 'dlrow' })
t.pass('Works correctly')
t.assert.ok('Works correctly')
} catch (err) {
t.fail(err)
t.assert.fail(err)
}
done()
})
})

test('Should support basic assert (throw)', t => {
test('Should support basic assert (throw)', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert(false)
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
done()
})
})

test('Should support equal assert (throw)', t => {
test('Should support equal assert (throw)', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.equal(1, '2')
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
done()
})
})

test('Should support not equal assert (throw)', t => {
test('Should support not equal assert (throw)', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.notEqual(1, '1')
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
done()
})
})

test('Should support strict equal assert (throw)', t => {
test('Should support strict equal assert (throw)', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.equal(1, 2)
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
done()
})
})

test('Should support not strict equal assert (throw)', t => {
test('Should support not strict equal assert (throw)', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.notStrictEqual(1, 1)
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
done()
})
})

test('Should support deep equal assert (throw)', t => {
test('Should support deep equal assert (throw)', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.deepEqual({ hello: 'world' }, { hello: 'dlrow' })
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
done()
})
})

test('Should support not deep equal assert (throw)', t => {
test('Should support not deep equal assert (throw)', (t, done) => {
t.plan(2)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert.notDeepEqual({ hello: 'world' }, { hello: 'world' })
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.ok(err)
t.assert.ok(err)
}
done()
})
})

test('Should generate the correct http error', t => {
test('Should generate the correct http error', (t, done) => {
t.plan(4)
const fastify = Fastify()
fastify.register(Sensible)

fastify.ready(err => {
t.error(err)
t.assert.ifError(err)
try {
fastify.assert(false, 400, 'Wrong!')
t.fail('Should throw')
t.assert.fail('Should throw')
} catch (err) {
t.equal(err.message, 'Wrong!')
t.equal(err.name, 'BadRequestError')
t.equal(err.statusCode, 400)
t.assert.strictEqual(err.message, 'Wrong!')
t.assert.strictEqual(err.name, 'BadRequestError')
t.assert.strictEqual(err.statusCode, 400)
}
done()
})
})
Loading
Loading