|
1 | 1 | import { promises as fsp } from "node:fs"; |
2 | | -import { resolve, join, relative, basename } from "pathe"; |
3 | | -import { describe, expect, it } from "vitest"; |
4 | | -import { setupTest, startServer, testNitro } from "../tests"; |
5 | | -import { readlink } from "node:fs/promises"; |
| 2 | +import { resolve, join, basename } from "pathe"; |
| 3 | +import { describe, expect, it, afterAll } from "vitest"; |
| 4 | +import { setupTest, startServer, testNitro, fixtureDir } from "../tests"; |
6 | 5 |
|
7 | 6 | describe("nitro:preset:vercel", async () => { |
8 | 7 | const ctx = await setupTest("vercel"); |
@@ -591,3 +590,68 @@ describe("nitro:preset:vercel", async () => { |
591 | 590 | } |
592 | 591 | ); |
593 | 592 | }); |
| 593 | + |
| 594 | +describe("nitro:preset:vercel:bun", async () => { |
| 595 | + const ctx = await setupTest("vercel", { |
| 596 | + config: { |
| 597 | + preset: "vercel", |
| 598 | + vercel: { |
| 599 | + functions: { |
| 600 | + runtime: "bun1.x", |
| 601 | + }, |
| 602 | + }, |
| 603 | + }, |
| 604 | + }); |
| 605 | + |
| 606 | + it("should generate function config with bun runtime", async () => { |
| 607 | + const config = await fsp |
| 608 | + .readFile( |
| 609 | + resolve(ctx.outDir, "functions/__fallback.func/.vc-config.json"), |
| 610 | + "utf8" |
| 611 | + ) |
| 612 | + .then((r) => JSON.parse(r)); |
| 613 | + expect(config).toMatchInlineSnapshot(` |
| 614 | + { |
| 615 | + "handler": "index.mjs", |
| 616 | + "launcherType": "Nodejs", |
| 617 | + "runtime": "bun1.x", |
| 618 | + "shouldAddHelpers": false, |
| 619 | + "supportsResponseStreaming": true, |
| 620 | + } |
| 621 | + `); |
| 622 | + }); |
| 623 | +}); |
| 624 | + |
| 625 | +describe("nitro:preset:vercel:bun-verceljson", async () => { |
| 626 | + const vercelJsonPath = join(fixtureDir, "vercel.json"); |
| 627 | + // Need to make sure vercel.json is created before setupTest is called |
| 628 | + await fsp.writeFile(vercelJsonPath, JSON.stringify({ bunVersion: "1.x" })); |
| 629 | + |
| 630 | + const ctx = await setupTest("vercel", { |
| 631 | + config: { |
| 632 | + preset: "vercel", |
| 633 | + }, |
| 634 | + }); |
| 635 | + |
| 636 | + afterAll(async () => { |
| 637 | + await fsp.unlink(vercelJsonPath).catch(() => {}); |
| 638 | + }); |
| 639 | + |
| 640 | + it("should detect bun runtime from vercel.json", async () => { |
| 641 | + const config = await fsp |
| 642 | + .readFile( |
| 643 | + resolve(ctx.outDir, "functions/__fallback.func/.vc-config.json"), |
| 644 | + "utf8" |
| 645 | + ) |
| 646 | + .then((r) => JSON.parse(r)); |
| 647 | + expect(config).toMatchInlineSnapshot(` |
| 648 | + { |
| 649 | + "handler": "index.mjs", |
| 650 | + "launcherType": "Nodejs", |
| 651 | + "runtime": "bun1.x", |
| 652 | + "shouldAddHelpers": false, |
| 653 | + "supportsResponseStreaming": true, |
| 654 | + } |
| 655 | + `); |
| 656 | + }); |
| 657 | +}); |
0 commit comments