|
1 | | -import { mkdir, writeFile } from "node:fs/promises"; |
| 1 | +import { mkdir, readFile, writeFile } from "node:fs/promises"; |
2 | 2 |
|
3 | 3 | import { it } from "./it"; |
4 | 4 |
|
@@ -61,6 +61,37 @@ it("generates valid script tags for SvelteKit", { timeout: 30_000 }, async ({ |
61 | 61 | }); |
62 | 62 | }); |
63 | 63 |
|
| 64 | +it("adds the env register import to the framework config", { timeout: 30_000 }, async ({ |
| 65 | + expect, |
| 66 | + project, |
| 67 | + prismic, |
| 68 | +}) => { |
| 69 | + const configPath = new URL("next.config.mjs", project); |
| 70 | + await writeFile(configPath, "export default {};\n"); |
| 71 | + |
| 72 | + const { exitCode } = await prismic("gen", ["setup", "--no-install"]); |
| 73 | + expect(exitCode).toBe(0); |
| 74 | + |
| 75 | + const contents = await readFile(configPath, "utf8"); |
| 76 | + expect(contents).toBe('import "prismic/env/register";\n\nexport default {};\n'); |
| 77 | +}); |
| 78 | + |
| 79 | +it("skips the env register import for a CommonJS config", { timeout: 30_000 }, async ({ |
| 80 | + expect, |
| 81 | + project, |
| 82 | + prismic, |
| 83 | +}) => { |
| 84 | + // The fixture's package.json has no "type": "module", so a .js config is CommonJS. |
| 85 | + const configPath = new URL("next.config.js", project); |
| 86 | + await writeFile(configPath, "module.exports = {};\n"); |
| 87 | + |
| 88 | + const { exitCode } = await prismic("gen", ["setup", "--no-install"]); |
| 89 | + expect(exitCode).toBe(0); |
| 90 | + |
| 91 | + const contents = await readFile(configPath, "utf8"); |
| 92 | + expect(contents).toBe("module.exports = {};\n"); |
| 93 | +}); |
| 94 | + |
64 | 95 | it("skips installation with --no-install", async ({ expect, project, prismic }) => { |
65 | 96 | const { exitCode, stdout } = await prismic("gen", ["setup", "--no-install"]); |
66 | 97 | expect(exitCode).toBe(0); |
|
0 commit comments