feat: updates

This commit is contained in:
qier222 2022-10-28 20:29:04 +08:00
parent a1b0bcf4d3
commit 884f3df41a
No known key found for this signature in database
198 changed files with 4572 additions and 5336 deletions

View file

@ -0,0 +1,35 @@
// This file contains code that we reuse between our tests.
import Fastify from 'fastify'
import fp from 'fastify-plugin'
import App from '../src/app'
import * as tap from 'tap';
export type Test = typeof tap['Test']['prototype'];
// Fill in this config with all the configurations
// needed for testing the application
async function config () {
return {}
}
// Automatically build and tear down our instance
async function build (t: Test) {
const app = Fastify()
// fastify-plugin ensures that all decorators
// are exposed for testing purposes, this is
// different from the production setup
void app.register(fp(App), await config())
await app.ready();
// Tear down our app after we are done
t.teardown(() => void app.close())
return app
}
export {
config,
build
}

View file

@ -0,0 +1,11 @@
import { test } from 'tap'
import Fastify from 'fastify'
import Support from '../../src/plugins/support'
test('support works standalone', async (t) => {
const fastify = Fastify()
void fastify.register(Support)
await fastify.ready()
t.equal(fastify.someSupport(), 'hugs')
})

View file

@ -0,0 +1,12 @@
import { test } from 'tap'
import { build } from '../helper'
test('example is loaded', async (t) => {
const app = await build(t)
const res = await app.inject({
url: '/example'
})
t.equal(res.payload, 'this is an example')
})

View file

@ -0,0 +1,11 @@
import { test } from 'tap'
import { build } from '../helper'
test('default root route', async (t) => {
const app = await build(t)
const res = await app.inject({
url: '/'
})
t.same(JSON.parse(res.payload), { root: true })
})

View file

@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"noEmit": true
},
"include": ["../src/**/*.ts", "**/*.ts"]
}