Skip to content

Open-source document signature platform. Not affiliated with DocuSign.

TypeScript

Run the end-to-end test against a production build

Claudee1ad0f43218e
diff --git a/playwright.config.ts b/playwright.config.ts
index ab3922e..4d2fe4a 100644
--- a/playwright.config.ts
+++ b/playwright.config.ts
@@ -9,6 +9,10 @@ import { defineConfig, devices } from "@playwright/test";
// npm run test:e2e
//
// The test database is wiped on every run. It must have "e2e" in its name.
+//
+// The app is built and started in production mode, so the test sees the same
+// headers, bundles and Content Security Policy as a real deployment. Set
+// E2E_DEV=1 to run against "next dev" instead, which starts faster.
const port = Number(process.env.E2E_PORT ?? 3100);
const baseURL = `http://localhost:${String(port)}`;
@@ -41,7 +45,10 @@ export default defineConfig({
trace: "retain-on-failure",
},
webServer: {
- command: `npx next dev --port ${String(port)}`,
+ command:
+ process.env.E2E_DEV === "1"
+ ? `npx next dev --port ${String(port)}`
+ : `npx next build && npx next start --port ${String(port)}`,
env: {
APP_URL: baseURL,
BETTER_AUTH_SECRET: "e2e-only-secret-not-used-anywhere-else-0123456789",
@@ -50,11 +57,14 @@ export default defineConfig({
EMAIL_CAPTURE_DIR: e2eOutboxDir,
EMAIL_DRIVER: "capture",
NEXT_TELEMETRY_DISABLED: "1",
+ // The breach check calls an outside service; the test must not.
+ PASSWORD_BREACH_CHECK: "off",
STORAGE_DRIVER: "local",
STORAGE_LOCAL_DIR: path.join(e2eDataDir, "storage"),
+ SUPPORT_EMAIL: "[email protected]",
},
reuseExistingServer: false,
- timeout: 180_000,
+ timeout: 300_000,
url: `${baseURL}/login`,
},
workers: 1,
diff --git a/src/lib/services/email.ts b/src/lib/services/email.ts
index 6edfec3..eecdb14 100644
--- a/src/lib/services/email.ts
+++ b/src/lib/services/email.ts
@@ -5,7 +5,7 @@ import path from "node:path";
import { Resend } from "resend";
import { type EmailTemplateKind } from "../types/domain.ts";
-import { getEnv, type EnvSource } from "../utils/env.ts";
+import { getEnv, isLocalDeployment, type EnvSource } from "../utils/env.ts";
import { assertServiceConfig } from "./service-config.ts";
const EMAIL_ENV_KEYS = [
@@ -120,7 +120,9 @@ export function resolveEmailDriver(env: EnvSource = process.env): EmailDriver {
* JSON file so a person (or the end-to-end test) can read the links in it.
*/
function createCaptureEmailService(env: EnvSource): EmailService {
- if (env.NODE_ENV === "production") {
+ // Allowed in development, and for a production build that is being run on
+ // localhost (which is what the end-to-end test does). Never on a real site.
+ if (env.NODE_ENV === "production" && !isLocalDeployment(env)) {
throw new Error(
"EMAIL_DRIVER=capture drops every email and cannot be used in production.",
);