|
1 | | -import { describe, expect, it } from "vitest"; |
| 1 | +import { describe, expect, it, vi } from "vitest"; |
2 | 2 | import type { Nitro } from "nitro/types"; |
3 | 3 |
|
4 | | -import storage from "../../src/build/virtual/storage.ts"; |
| 4 | +const mockedDeps = new Set<string>(); |
| 5 | + |
| 6 | +vi.mock("../../src/utils/dep.ts", async (importOriginal) => { |
| 7 | + const original = await importOriginal<typeof import("../../src/utils/dep.ts")>(); |
| 8 | + return { |
| 9 | + ...original, |
| 10 | + isDepInstalled: (id: string, dir: string) => |
| 11 | + mockedDeps.has(id) || original.isDepInstalled(id, dir), |
| 12 | + }; |
| 13 | +}); |
| 14 | + |
| 15 | +const { default: storage } = await import("../../src/build/virtual/storage.ts"); |
5 | 16 |
|
6 | 17 | function createNitroStub( |
7 | 18 | tracingChannel: Nitro["options"]["tracingChannel"], |
@@ -49,6 +60,18 @@ describe("virtual/storage template", () => { |
49 | 60 | ); |
50 | 61 | }); |
51 | 62 |
|
| 63 | + it("uses the driver import specifier when it differs from the package name", () => { |
| 64 | + mockedDeps.add("uploadthing"); |
| 65 | + try { |
| 66 | + const template = storage( |
| 67 | + createNitroStub(undefined, { "/files": { driver: "uploadthing", token: "x" } }) |
| 68 | + ).template(); |
| 69 | + expect(template).toContain(`lib: () => import("uploadthing/server")`); |
| 70 | + } finally { |
| 71 | + mockedDeps.clear(); |
| 72 | + } |
| 73 | + }); |
| 74 | + |
52 | 75 | it("does not provide `lib` for dependencies that are not installed", () => { |
53 | 76 | const template = storage( |
54 | 77 | createNitroStub(undefined, { "/cache": { driver: "redis", base: "cache" } }) |
|
0 commit comments