Skip to content

Commit f8ce991

Browse files
committed
add e2e test for env vars
1 parent a9f7ec4 commit f8ce991

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

examples/api/.dev.vars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXTJS_ENV=development

examples/api/.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEST_ENV_VAR=TEST_VALUE

examples/api/app/api/env/route.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function GET() {
2+
return new Response(JSON.stringify(process.env));
3+
}

examples/api/e2e/base.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ test("the hello-world api POST route works as intended", async ({ page }) => {
3030
expect(res.headers()["content-type"]).toContain("text/plain");
3131
await expect(res.text()).resolves.toEqual("Hello post-World! body=some body");
3232
});
33+
34+
test("sets environment variables from the Next.js env file", async ({ page }) => {
35+
const res = await page.request.get("/api/env");
36+
expect(res.json()).toContain({ TEST_ENV_VAR: "TEST_VALUE" });
37+
});

0 commit comments

Comments
 (0)