Aktueller Stand
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const { test } = require('node:test')
|
||||
const FjsCompiler = require('../index')
|
||||
|
||||
t.test('Use input schema duplicate in the externalSchemas', async t => {
|
||||
test('Use input schema duplicate in the externalSchemas', async t => {
|
||||
t.plan(1)
|
||||
const externalSchemas = {
|
||||
schema1: {
|
||||
@@ -22,5 +22,5 @@ t.test('Use input schema duplicate in the externalSchemas', async t => {
|
||||
compiler({ schema: externalSchemas.schema1 })
|
||||
compiler({ schema: externalSchemas.schema2 })
|
||||
|
||||
t.pass()
|
||||
t.assert.ok(true)
|
||||
})
|
||||
|
||||
14
backend/node_modules/@fastify/fast-json-stringify-compiler/test/plugin.test.js
generated
vendored
14
backend/node_modules/@fastify/fast-json-stringify-compiler/test/plugin.test.js
generated
vendored
@@ -1,10 +1,10 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const { test } = require('node:test')
|
||||
const fastify = require('fastify')
|
||||
const FjsCompiler = require('../index')
|
||||
|
||||
const echo = async (req, reply) => { return req.body }
|
||||
const echo = async (req) => { return req.body }
|
||||
|
||||
const sampleSchema = Object.freeze({
|
||||
$id: 'example1',
|
||||
@@ -27,16 +27,16 @@ const externalSchemas2 = Object.freeze({
|
||||
|
||||
const fastifyFjsOptionsDefault = Object.freeze({})
|
||||
|
||||
t.test('basic usage', t => {
|
||||
test('basic usage', t => {
|
||||
t.plan(1)
|
||||
const factory = FjsCompiler()
|
||||
const compiler = factory(externalSchemas1, fastifyFjsOptionsDefault)
|
||||
const serializeFunc = compiler({ schema: sampleSchema })
|
||||
const result = serializeFunc({ name: 'hello' })
|
||||
t.equal(result, '{"name":"hello"}')
|
||||
t.assert.equal(result, '{"name":"hello"}')
|
||||
})
|
||||
|
||||
t.test('fastify integration', async t => {
|
||||
test('fastify integration', async t => {
|
||||
const factory = FjsCompiler()
|
||||
|
||||
const app = fastify({
|
||||
@@ -73,6 +73,6 @@ t.test('fastify integration', async t => {
|
||||
}
|
||||
})
|
||||
|
||||
t.equal(res.statusCode, 200)
|
||||
t.same(res.json(), { name: 'serialize me' })
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
t.assert.deepStrictEqual(res.json(), { name: 'serialize me' })
|
||||
})
|
||||
|
||||
52
backend/node_modules/@fastify/fast-json-stringify-compiler/test/standalone.test.js
generated
vendored
52
backend/node_modules/@fastify/fast-json-stringify-compiler/test/standalone.test.js
generated
vendored
@@ -1,8 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const t = require('tap')
|
||||
const fs = require('node:fs')
|
||||
const path = require('node:path')
|
||||
const { test } = require('node:test')
|
||||
const fastify = require('fastify')
|
||||
const sanitize = require('sanitize-filename')
|
||||
|
||||
@@ -16,23 +16,23 @@ function generateFileName (routeOpts) {
|
||||
return fileName
|
||||
}
|
||||
|
||||
t.test('standalone', t => {
|
||||
test('standalone', async t => {
|
||||
t.plan(5)
|
||||
|
||||
t.teardown(async () => {
|
||||
t.after(async () => {
|
||||
for (const fileName of generatedFileNames) {
|
||||
try {
|
||||
await fs.promises.unlink(path.join(__dirname, fileName))
|
||||
} catch (e) {}
|
||||
} catch {}
|
||||
}
|
||||
})
|
||||
|
||||
t.test('errors', t => {
|
||||
t.plan(2)
|
||||
t.throws(() => {
|
||||
t.assert.throws(() => {
|
||||
FjsStandaloneCompiler()
|
||||
}, 'missing restoreFunction')
|
||||
t.throws(() => {
|
||||
t.assert.throws(() => {
|
||||
FjsStandaloneCompiler({ readMode: false })
|
||||
}, 'missing storeFunction')
|
||||
})
|
||||
@@ -74,28 +74,28 @@ t.test('standalone', t => {
|
||||
const factory = FjsStandaloneCompiler({
|
||||
readMode: false,
|
||||
storeFunction (routeOpts, schemaSerializerCode) {
|
||||
t.same(routeOpts, endpointSchema)
|
||||
t.type(schemaSerializerCode, 'string')
|
||||
t.assert.deepStrictEqual(routeOpts, endpointSchema)
|
||||
t.assert.ok(typeof schemaSerializerCode === 'string')
|
||||
fs.writeFileSync(path.join(__dirname, '/fjs-generated.js'), schemaSerializerCode)
|
||||
generatedFileNames.push('/fjs-generated.js')
|
||||
t.pass('stored the serializer function')
|
||||
t.assert.ok('stored the serializer function')
|
||||
}
|
||||
})
|
||||
|
||||
const compiler = factory(schemaMap)
|
||||
compiler(endpointSchema)
|
||||
t.pass('compiled the endpoint schema')
|
||||
t.assert.ok('compiled the endpoint schema')
|
||||
|
||||
t.test('usage standalone code', t => {
|
||||
t.plan(3)
|
||||
const standaloneSerializer = require('./fjs-generated')
|
||||
t.ok(standaloneSerializer)
|
||||
t.assert.ok(standaloneSerializer)
|
||||
|
||||
const valid = standaloneSerializer({ hello: 'world' })
|
||||
t.same(valid, JSON.stringify({ hello: 'world' }))
|
||||
t.assert.deepStrictEqual(valid, JSON.stringify({ hello: 'world' }))
|
||||
|
||||
const invalid = standaloneSerializer({ hello: [] })
|
||||
t.same(invalid, '{"hello":""}')
|
||||
t.assert.deepStrictEqual(invalid, '{"hello":""}')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -106,9 +106,9 @@ t.test('standalone', t => {
|
||||
readMode: false,
|
||||
storeFunction (routeOpts, schemaSerializationCode) {
|
||||
const fileName = generateFileName(routeOpts)
|
||||
t.ok(routeOpts)
|
||||
t.assert.ok(routeOpts)
|
||||
fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
|
||||
t.pass(`stored the serializer function ${fileName}`)
|
||||
t.assert.ok(`stored the serializer function ${fileName}`)
|
||||
},
|
||||
restoreFunction () {
|
||||
t.fail('write mode ON')
|
||||
@@ -119,16 +119,16 @@ t.test('standalone', t => {
|
||||
await app.ready()
|
||||
})
|
||||
|
||||
t.test('fastify integration - writeMode forces standalone', async t => {
|
||||
await t.test('fastify integration - writeMode forces standalone', async t => {
|
||||
t.plan(4)
|
||||
|
||||
const factory = FjsStandaloneCompiler({
|
||||
readMode: false,
|
||||
storeFunction (routeOpts, schemaSerializationCode) {
|
||||
const fileName = generateFileName(routeOpts)
|
||||
t.ok(routeOpts)
|
||||
t.assert.ok(routeOpts)
|
||||
fs.writeFileSync(path.join(__dirname, fileName), schemaSerializationCode)
|
||||
t.pass(`stored the serializer function ${fileName}`)
|
||||
t.assert.ok(`stored the serializer function ${fileName}`)
|
||||
},
|
||||
restoreFunction () {
|
||||
t.fail('write mode ON')
|
||||
@@ -143,7 +143,7 @@ t.test('standalone', t => {
|
||||
await app.ready()
|
||||
})
|
||||
|
||||
t.test('fastify integration - readMode', async t => {
|
||||
await t.test('fastify integration - readMode', async t => {
|
||||
t.plan(6)
|
||||
|
||||
const factory = FjsStandaloneCompiler({
|
||||
@@ -153,7 +153,7 @@ t.test('standalone', t => {
|
||||
},
|
||||
restoreFunction (routeOpts) {
|
||||
const fileName = generateFileName(routeOpts)
|
||||
t.pass(`restore the serializer function ${fileName}}`)
|
||||
t.assert.ok(`restore the serializer function ${fileName}}`)
|
||||
return require(path.join(__dirname, fileName))
|
||||
}
|
||||
})
|
||||
@@ -165,15 +165,15 @@ t.test('standalone', t => {
|
||||
url: '/foo',
|
||||
method: 'POST'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.payload, JSON.stringify({ hello: 'world' }))
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
t.assert.equal(res.payload, JSON.stringify({ hello: 'world' }))
|
||||
|
||||
res = await app.inject({
|
||||
url: '/bar?lang=it',
|
||||
method: 'GET'
|
||||
})
|
||||
t.equal(res.statusCode, 200)
|
||||
t.equal(res.payload, JSON.stringify({ lang: 'en' }))
|
||||
t.assert.equal(res.statusCode, 200)
|
||||
t.assert.equal(res.payload, JSON.stringify({ lang: 'en' }))
|
||||
})
|
||||
|
||||
function buildApp (factory, serializerOpts) {
|
||||
|
||||
Reference in New Issue
Block a user