-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathrequire-plugins.test.ts
More file actions
44 lines (37 loc) · 1.87 KB
/
Copy pathrequire-plugins.test.ts
File metadata and controls
44 lines (37 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { PrismaClient } from "@trigger.dev/database";
import { afterEach, describe, expect, it, vi } from "vitest";
import loader from "./index.js";
// The plugin module `@triggerdotdev/plugins/rbac` is not installed in this
// repo (it lives in the cloud monorepo), so a real dynamic import inside
// the loader will reliably fail with ERR_MODULE_NOT_FOUND. These tests
// exercise the loader's branching on that natural failure — no module
// mocking required.
// The fallback's isUsingPlugin() returns false synchronously without
// touching prisma, so a placeholder client is fine for tests that only
// drive the loader path.
const prismaPlaceholder = {} as unknown as PrismaClient;
describe("LazyController plugin loading", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("falls back silently when REQUIRE_PLUGINS is unset and the plugin is missing", async () => {
vi.stubEnv("REQUIRE_PLUGINS", "");
const controller = loader.create(prismaPlaceholder);
await expect(controller.isUsingPlugin()).resolves.toBe(false);
});
it("throws when REQUIRE_PLUGINS=1 and the plugin is missing", async () => {
vi.stubEnv("REQUIRE_PLUGINS", "1");
const controller = loader.create(prismaPlaceholder);
await expect(controller.isUsingPlugin()).rejects.toThrow(/REQUIRE_PLUGINS=1/);
});
it("forceFallback wins over REQUIRE_PLUGINS=1 (so tests inheriting the env aren't broken)", async () => {
vi.stubEnv("REQUIRE_PLUGINS", "1");
const controller = loader.create(prismaPlaceholder, { forceFallback: true });
await expect(controller.isUsingPlugin()).resolves.toBe(false);
});
it("treats any non-'1' REQUIRE_PLUGINS value as unset (must be exactly '1' to enforce)", async () => {
vi.stubEnv("REQUIRE_PLUGINS", "true");
const controller = loader.create(prismaPlaceholder);
await expect(controller.isUsingPlugin()).resolves.toBe(false);
});
});