mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
refactor modes implementation and improve validation handling
refactor `code` and `hybrid` modes for better type safety and configuration flexibility. add `_isProd` helper to standardize environment checks and improve plugin syncing warnings. adjust validation logic for clean JSON schema handling and enhance test coverage for modes.
This commit is contained in:
42
app/__test__/app/modes.test.ts
Normal file
42
app/__test__/app/modes.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { code, hybrid } from "modes";
|
||||
|
||||
describe("modes", () => {
|
||||
describe("code", () => {
|
||||
test("verify base configuration", async () => {
|
||||
const c = code({}) as any;
|
||||
const config = await c.app?.({} as any);
|
||||
expect(Object.keys(config)).toEqual(["options"]);
|
||||
expect(config.options.mode).toEqual("code");
|
||||
expect(config.options.plugins).toEqual([]);
|
||||
expect(config.options.manager.skipValidation).toEqual(false);
|
||||
expect(config.options.manager.onModulesBuilt).toBeDefined();
|
||||
});
|
||||
|
||||
test("keeps overrides", async () => {
|
||||
const c = code({
|
||||
connection: {
|
||||
url: ":memory:",
|
||||
},
|
||||
}) as any;
|
||||
const config = await c.app?.({} as any);
|
||||
expect(config.connection.url).toEqual(":memory:");
|
||||
});
|
||||
});
|
||||
|
||||
describe("hybrid", () => {
|
||||
test("fails if no reader is provided", () => {
|
||||
// @ts-ignore
|
||||
expect(hybrid({} as any).app?.({} as any)).rejects.toThrow(/reader/);
|
||||
});
|
||||
test("verify base configuration", async () => {
|
||||
const c = hybrid({ reader: async () => ({}) }) as any;
|
||||
const config = await c.app?.({} as any);
|
||||
expect(Object.keys(config)).toEqual(["reader", "beforeBuild", "config", "options"]);
|
||||
expect(config.options.mode).toEqual("db");
|
||||
expect(config.options.plugins).toEqual([]);
|
||||
expect(config.options.manager.skipValidation).toEqual(false);
|
||||
expect(config.options.manager.onModulesBuilt).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user