-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor test MongoDB setup to mongodb-memory-server and remove CI container workaround #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
527a678
db151e9
126a35b
253e56b
986715c
520e452
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||
| import packageJson from "../package.json" with { type: "json" }; | ||||||
| import { AuthPluginOptions } from "./plugins/auth.js"; | ||||||
| import { InitMongoPluginOptions } from "./plugins/init-mongo.js"; | ||||||
| import AutoLoad, { AutoloadPluginOptions } from "@fastify/autoload"; | ||||||
| import { TypeBoxTypeProvider } from "@fastify/type-provider-typebox"; | ||||||
| import { | ||||||
|
|
@@ -19,10 +20,9 @@ const __dirname = path.dirname(__filename); | |||||
|
|
||||||
| export type AppOptions = { | ||||||
| // Place your custom options for app below here. | ||||||
| // MongoDB URI (Optional) | ||||||
| // mongoUri: string; | ||||||
| } & FastifyServerOptions & | ||||||
| Partial<AutoloadPluginOptions> & | ||||||
| InitMongoPluginOptions & | ||||||
|
||||||
| InitMongoPluginOptions & | |
| Partial<InitMongoPluginOptions> & |
Copilot
AI
Feb 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mongoUri field is retrieved as required using getOption with the non-null assertion operator (!). However, based on the PR description stating MongoDB should be "optional", this should use getOption with required=false to allow undefined values. This should be: mongoUri: getOption("MONGO_URI", false) without the non-null assertion.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,31 @@ | ||
| import fp from "fastify-plugin"; | ||
| import { Collection, Document } from "mongodb"; | ||
|
|
||
| // import { Collection, Document } from "mongodb"; | ||
|
|
||
| export type InitMongoPluginOptions = Record<never, unknown>; | ||
| export type InitMongoPluginOptions = { | ||
| // MongoDB URI | ||
| mongoUri: string; | ||
| }; | ||
|
Comment on lines
+4
to
+7
|
||
|
|
||
| // The use of fastify-plugin is required to be able | ||
| // to export the decorators to the outer scope | ||
| export default fp<InitMongoPluginOptions>(async (fastify, opts) => { | ||
| await fastify.register(import("@fastify/mongodb"), { | ||
| url: opts.mongoUri, | ||
| forceClose: true, | ||
| }); | ||
| fastify.addHook("onReady", async () => { | ||
| // Initialize the MongoDB database | ||
| // await fastify.mongo | ||
| // .db!.collection("example") | ||
| // .createIndex({ example: 1 }); | ||
| fastify.decorate("collections", { | ||
| example: fastify.mongo.db!.collection("example"), | ||
| }); | ||
| await fastify.collections.example.createIndex({ example: 1 }); | ||
|
Comment on lines
16
to
+21
|
||
| }); | ||
| }); | ||
|
|
||
| // declare module "fastify" { | ||
| // export interface FastifyInstance { | ||
| // collections: { | ||
| // example: Collection<Document>; | ||
| // }; | ||
| // } | ||
| // } | ||
| declare module "fastify" { | ||
| export interface FastifyInstance { | ||
| collections: { | ||
| example: Collection<Document>; | ||
| }; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test timeout flag (--test-timeout=5000) has been removed from the test script. With the MongoDB memory server being created per test, initialization could take longer than the default Node.js test timeout (30 seconds should be fine). However, if tests start failing due to timeout issues during MongoDB initialization, consider adding this flag back or increasing it. Monitor test execution times after this change.