This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"build": "rm -rf dist && tsc --sourceMap -p ./" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Debug src/index.ts", | |
"type": "node", | |
"request": "launch", | |
"env": { | |
"TS_NODE_FILES": "true" | |
}, | |
"runtimeArgs": ["-r", "ts-node/register"], | |
"args": ["${workspaceFolder}/src/index.ts"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fastify from "fastify"; | |
import { Server, IncomingMessage, ServerResponse } from "http"; | |
import statusRoutes from "../modules/routes/status"; | |
describe("/status", () => { | |
let server: fastify.FastifyInstance<Server, IncomingMessage, ServerResponse>; | |
beforeAll(() => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"test": "NODE_ENV=test npx jest --verbose --runInBand" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
rootDir: "src", | |
testMatch: ["**/__tests__/**/*.test.(ts|tsx|js|jsx)"], | |
verbose: false, | |
clearMocks: true, | |
resetModules: true, | |
coveragePathIgnorePatterns: [ | |
"/node_modules/", | |
"/__fixtures__/", | |
"/__tests__/", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm i jest ts-jest @types/jest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// at the top | |
import vehiclesRoutes from "./modules/routes/vehicles"; | |
import db from "./modules/db"; | |
// after server was created | |
server.register(db, { uri: "mongodb://localhost:27017/vehicles" }); | |
server.register(vehiclesRoutes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fp from "fastify-plugin"; | |
export default fp(async (server, opts, next) => { | |
server.get("/vehicles/:id", {}, async (request, reply) => { | |
try { | |
const _id = request.params.id; | |
const vehicle = await server.db.models.Vehicle.findOne({ | |
_id | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fastify from "fastify"; | |
import * as http from "http"; | |
import { Db } from "../modules/db"; | |
declare module "fastify" { | |
export interface FastifyInstance< | |
HttpServer = http.Server, | |
HttpRequest = http.IncomingMessage, | |
HttpResponse = http.ServerResponse | |
> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Model } from "mongoose"; | |
import * as Mongoose from "mongoose"; | |
import { VehicleModel, Vehicle } from "./models/vehicle"; | |
import * as fp from "fastify-plugin"; | |
export interface Models { | |
Vehicle: Model<VehicleModel>; | |
} |