Aktueller Stand
This commit is contained in:
190
backend/node_modules/fastify/test/throw.test.js
generated
vendored
190
backend/node_modules/fastify/test/throw.test.js
generated
vendored
@@ -1,20 +1,20 @@
|
||||
'use strict'
|
||||
|
||||
const { test } = require('tap')
|
||||
const { test } = require('node:test')
|
||||
const Fastify = require('..')
|
||||
|
||||
test('Fastify should throw on wrong options', t => {
|
||||
test('Fastify should throw on wrong options', (t) => {
|
||||
t.plan(2)
|
||||
try {
|
||||
Fastify('lol')
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.message, 'Options must be an object')
|
||||
t.pass()
|
||||
t.assert.strictEqual(e.message, 'Options must be an object')
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Fastify should throw on multiple assignment to the same route', t => {
|
||||
test('Fastify should throw on multiple assignment to the same route', (t) => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
|
||||
@@ -22,14 +22,14 @@ test('Fastify should throw on multiple assignment to the same route', t => {
|
||||
|
||||
try {
|
||||
fastify.get('/', () => {})
|
||||
t.fail('Should throw fastify duplicated route declaration')
|
||||
t.assert.fail('Should throw fastify duplicated route declaration')
|
||||
} catch (error) {
|
||||
t.equal(error.code, 'FST_ERR_DUPLICATED_ROUTE')
|
||||
t.assert.strictEqual(error.code, 'FST_ERR_DUPLICATED_ROUTE')
|
||||
}
|
||||
})
|
||||
|
||||
test('Fastify should throw for an invalid schema, printing the error route - headers', t => {
|
||||
t.plan(2)
|
||||
test('Fastify should throw for an invalid schema, printing the error route - headers', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const badSchema = {
|
||||
type: 'object',
|
||||
@@ -39,20 +39,18 @@ test('Fastify should throw for an invalid schema, printing the error route - hea
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const fastify = Fastify()
|
||||
fastify.get('/', { schema: { headers: badSchema } }, () => {})
|
||||
fastify.get('/not-loaded', { schema: { headers: badSchema } }, () => {})
|
||||
|
||||
fastify.ready(err => {
|
||||
t.equal(err.code, 'FST_ERR_SCH_VALIDATION_BUILD')
|
||||
t.match(err.message, /Failed building the validation schema for GET: \//)
|
||||
await t.assert.rejects(fastify.ready(), {
|
||||
code: 'FST_ERR_SCH_VALIDATION_BUILD',
|
||||
message: /Failed building the validation schema for GET: \//
|
||||
})
|
||||
})
|
||||
|
||||
test('Fastify should throw for an invalid schema, printing the error route - body', t => {
|
||||
t.plan(2)
|
||||
|
||||
test('Fastify should throw for an invalid schema, printing the error route - body', async (t) => {
|
||||
t.plan(1)
|
||||
const badSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@@ -68,25 +66,13 @@ test('Fastify should throw for an invalid schema, printing the error route - bod
|
||||
done()
|
||||
}, { prefix: 'hello' })
|
||||
|
||||
fastify.ready(err => {
|
||||
t.equal(err.code, 'FST_ERR_SCH_VALIDATION_BUILD')
|
||||
t.match(err.message, /Failed building the validation schema for POST: \/hello\/form/)
|
||||
await t.assert.rejects(fastify.ready(), {
|
||||
code: 'FST_ERR_SCH_VALIDATION_BUILD',
|
||||
message: /Failed building the validation schema for POST: \/hello\/form/
|
||||
})
|
||||
})
|
||||
|
||||
test('Fastify should throw for an invalid shorthand option type', t => {
|
||||
t.plan(3)
|
||||
try {
|
||||
Fastify({ jsonShorthand: 'hello' })
|
||||
t.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.code, 'FST_ERR_INIT_OPTS_INVALID')
|
||||
t.match(e.message, /must be boolean/)
|
||||
t.pass()
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw on unsupported method', t => {
|
||||
test('Should throw on unsupported method', async (t) => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
try {
|
||||
@@ -96,13 +82,13 @@ test('Should throw on unsupported method', t => {
|
||||
schema: {},
|
||||
handler: function (req, reply) {}
|
||||
})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw on missing handler', t => {
|
||||
test('Should throw on missing handler', (t) => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
try {
|
||||
@@ -110,15 +96,15 @@ test('Should throw on missing handler', t => {
|
||||
method: 'GET',
|
||||
url: '/'
|
||||
})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw if one method is unsupported', t => {
|
||||
const fastify = Fastify()
|
||||
test('Should throw if one method is unsupported', async (t) => {
|
||||
t.plan(1)
|
||||
const fastify = Fastify()
|
||||
try {
|
||||
fastify.route({
|
||||
method: ['GET', 'TROLL'],
|
||||
@@ -126,28 +112,27 @@ test('Should throw if one method is unsupported', t => {
|
||||
schema: {},
|
||||
handler: function (req, reply) {}
|
||||
})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw on duplicate content type parser', t => {
|
||||
test('Should throw on duplicate content type parser', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const fastify = Fastify()
|
||||
function customParser (req, payload, done) { done(null, '') }
|
||||
|
||||
fastify.addContentTypeParser('application/qq', customParser)
|
||||
try {
|
||||
fastify.addContentTypeParser('application/qq', customParser)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw on duplicate decorator', t => {
|
||||
test('Should throw on duplicate decorator', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const fastify = Fastify()
|
||||
@@ -156,31 +141,30 @@ test('Should throw on duplicate decorator', t => {
|
||||
fastify.decorate('foo', fooObj)
|
||||
try {
|
||||
fastify.decorate('foo', fooObj)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should not throw on duplicate decorator encapsulation', t => {
|
||||
test('Should not throw on duplicate decorator encapsulation', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const fastify = Fastify()
|
||||
const foo2Obj = {}
|
||||
|
||||
fastify.decorate('foo2', foo2Obj)
|
||||
|
||||
fastify.register(function (fastify, opts, done) {
|
||||
t.doesNotThrow(() => {
|
||||
t.assert.doesNotThrow(() => {
|
||||
fastify.decorate('foo2', foo2Obj)
|
||||
})
|
||||
done()
|
||||
})
|
||||
|
||||
fastify.ready()
|
||||
await fastify.ready()
|
||||
})
|
||||
|
||||
test('Should throw on duplicate request decorator', t => {
|
||||
test('Should throw on duplicate request decorator', async (t) => {
|
||||
t.plan(2)
|
||||
|
||||
const fastify = Fastify()
|
||||
@@ -188,28 +172,28 @@ test('Should throw on duplicate request decorator', t => {
|
||||
fastify.decorateRequest('foo', null)
|
||||
try {
|
||||
fastify.decorateRequest('foo', null)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.code, 'FST_ERR_DEC_ALREADY_PRESENT')
|
||||
t.equal(e.message, 'The decorator \'foo\' has already been added!')
|
||||
t.assert.strictEqual(e.code, 'FST_ERR_DEC_ALREADY_PRESENT')
|
||||
t.assert.strictEqual(e.message, 'The decorator \'foo\' has already been added!')
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw if request decorator dependencies are not met', t => {
|
||||
test('Should throw if request decorator dependencies are not met', async (t) => {
|
||||
t.plan(2)
|
||||
|
||||
const fastify = Fastify()
|
||||
|
||||
try {
|
||||
fastify.decorateRequest('bar', null, ['world'])
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.equal(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
|
||||
t.equal(e.message, 'The decorator is missing dependency \'world\'.')
|
||||
t.assert.strictEqual(e.code, 'FST_ERR_DEC_MISSING_DEPENDENCY')
|
||||
t.assert.strictEqual(e.message, 'The decorator is missing dependency \'world\'.')
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw on duplicate reply decorator', t => {
|
||||
test('Should throw on duplicate reply decorator', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const fastify = Fastify()
|
||||
@@ -217,149 +201,149 @@ test('Should throw on duplicate reply decorator', t => {
|
||||
fastify.decorateReply('foo', null)
|
||||
try {
|
||||
fastify.decorateReply('foo', null)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.ok(/has already been added/.test(e.message))
|
||||
t.assert.ok(/has already been added/.test(e.message))
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw if reply decorator dependencies are not met', t => {
|
||||
test('Should throw if reply decorator dependencies are not met', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const fastify = Fastify()
|
||||
|
||||
try {
|
||||
fastify.decorateReply('bar', null, ['world'])
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.ok(/missing dependency/.test(e.message))
|
||||
t.assert.ok(/missing dependency/.test(e.message))
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw if handler as the third parameter to the shortcut method is missing and the second parameter is not a function and also not an object', t => {
|
||||
test('Should throw if handler as the third parameter to the shortcut method is missing and the second parameter is not a function and also not an object', async (t) => {
|
||||
t.plan(5)
|
||||
|
||||
const fastify = Fastify()
|
||||
|
||||
try {
|
||||
fastify.get('/foo/1', '')
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/2', 1)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/3', [])
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/4', undefined)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/5', null)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw if handler as the third parameter to the shortcut method is missing and the second parameter is not a function and also not an object', t => {
|
||||
test('Should throw if handler as the third parameter to the shortcut method is missing and the second parameter is not a function and also not an object', async (t) => {
|
||||
t.plan(5)
|
||||
|
||||
const fastify = Fastify()
|
||||
|
||||
try {
|
||||
fastify.get('/foo/1', '')
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/2', 1)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/3', [])
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/4', undefined)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/5', null)
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw if there is handler function as the third parameter to the shortcut method and options as the second parameter is not an object', t => {
|
||||
test('Should throw if there is handler function as the third parameter to the shortcut method and options as the second parameter is not an object', async (t) => {
|
||||
t.plan(5)
|
||||
|
||||
const fastify = Fastify()
|
||||
|
||||
try {
|
||||
fastify.get('/foo/1', '', (req, res) => {})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/2', 1, (req, res) => {})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/3', [], (req, res) => {})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/4', undefined, (req, res) => {})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
|
||||
try {
|
||||
fastify.get('/foo/5', null, (req, res) => {})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
test('Should throw if found duplicate handler as the third parameter to the shortcut method and in options', t => {
|
||||
test('Should throw if found duplicate handler as the third parameter to the shortcut method and in options', async (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const fastify = Fastify()
|
||||
@@ -368,8 +352,8 @@ test('Should throw if found duplicate handler as the third parameter to the shor
|
||||
fastify.get('/foo/abc', {
|
||||
handler: (req, res) => {}
|
||||
}, (req, res) => {})
|
||||
t.fail()
|
||||
t.assert.fail()
|
||||
} catch (e) {
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user