Skip to content

Commit

Permalink
Add test helper utility in TypeScript template (#554)
Browse files Browse the repository at this point in the history
* Add test helper utility in TypeScript template

* Increase tap's `--timeout` flag to `300`
  • Loading branch information
nooreldeensalah authored Sep 21, 2022
1 parent c694d12 commit 9c1eded
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"lint": "standard",
"lint:fix": "standard --fix",
"unit": "tap \"test/**/*.test.{js,ts}\" \"templates/**/*.test.{js,ts}\" --timeout 120",
"unit": "tap \"test/**/*.test.{js,ts}\" \"templates/**/*.test.{js,ts}\" --timeout 300",
"pretest": "xcopy /e /k /i . \"..\\node_modules\\fastify-cli\" || rsync -r --exclude=node_modules ./ node_modules/fastify-cli || echo 'this is fine'",
"test": "npm run lint && npm run unit && npm run test:typescript",
"test:typescript": "tsd templates/plugin && tsc --project templates/app-ts/tsconfig.json && del-cli templates/app-ts/dist"
Expand Down
14 changes: 7 additions & 7 deletions templates/app-ts/test/helper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// This file contains code that we reuse between our tests.
import Fastify from 'fastify'
import fp from 'fastify-plugin'
import App from '../src/app'
const helper = require('fastify-cli/helper.js')
import * as path from 'path'
import * as tap from 'tap';

export type Test = typeof tap['Test']['prototype'];

const AppPath = path.join(__dirname, '..', 'src', 'app.ts')

// Fill in this config with all the configurations
// needed for testing the application
async function config () {
Expand All @@ -14,14 +15,13 @@ async function config () {

// Automatically build and tear down our instance
async function build (t: Test) {
const app = Fastify()
// you can set all the options supported by the fastify CLI command
const argv = [AppPath]

// 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();
const app = await helper.build(argv, await config())

// Tear down our app after we are done
t.teardown(() => void app.close())
Expand Down

0 comments on commit 9c1eded

Please sign in to comment.