Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ADMINS=
MONTHLY_CRON_ENABLED=

# Functional tests
E2E_TEST_ENV=local
E2E_TEST_ENV="not running e2e tests"
E2E_TEST_SECRET=test-secret
E2E_TEST_ACCOUNT_BASE_EMAIL=test-account
E2E_TEST_ACCOUNT_BASE_PASSWORD=test-password
Expand Down
7 changes: 6 additions & 1 deletion src/app/functions/server/getExperiments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe("getExperiments", () => {
});

it("calls Cirrus V2 when feature flag is enabled with preview param", async () => {
process.env.NEXT_RUNTIME = "test";
process.env.NIMBUS_SIDECAR_URL = "https://cirrus.example";
getEnabledFeatureFlagsMock.mockReturnValue([
"CirrusV2",
Expand Down Expand Up @@ -150,6 +151,8 @@ describe("getExperiments", () => {
previewMode: true,
}),
);

delete process.env.NEXT_RUNTIME;
});

it("calls Cirrus V1 when featurn flag is disabled", async () => {
Expand Down Expand Up @@ -188,7 +191,8 @@ describe("getExperiments", () => {
);
});

it("fallsback to defaultExperimentData when not experiment data is returned by Cirrus", async () => {
it("fallsback to defaultExperimentData when no experiment data is returned by Cirrus", async () => {
process.env.NEXT_RUNTIME = "test";
process.env.NIMBUS_SIDECAR_URL = "https://cirrus.example";
getEnabledFeatureFlagsMock.mockReturnValue([
"CirrusV2",
Expand Down Expand Up @@ -235,6 +239,7 @@ describe("getExperiments", () => {
previewMode: true,
}),
);
delete process.env.NEXT_RUNTIME;
});

it("logs error, captures exception, and returns defaultExperimentData on error response", async () => {
Expand Down
8 changes: 7 additions & 1 deletion src/app/functions/server/getExperiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ export async function getExperiments(params: {
serverUrl.pathname += "v1/features";
}

const nextHeaders = await loadNextHeaders();
const nextHeaders =
// We also check for experiments in cron jobs, where there are
// no HTTP requests. Skip the headers there; we don't need to
// force-enable experiments in cronjobs.
typeof process.env.NEXT_RUNTIME === "string"
? await loadNextHeaders()
: null;
let previewMode = false;
if (nextHeaders) {
const headersList = await nextHeaders.headers();
Expand Down
11 changes: 10 additions & 1 deletion src/db/tables/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ export async function getEnabledFeatureFlags(
options: { isSignedOut?: false; email: string } | { isSignedOut: true },
): Promise<FeatureFlagName[]> {
// Force feature flags for E2E tests via URL query params
if (process.env.E2E_TEST_ENV === "local") {
if (
// Check that we're running under Next.js; in cronjobs
// there's no request to inspect. We're not force-enabling
// feature flags in that environment anyway.
typeof process.env.NEXT_RUNTIME === "string" &&
// When running end-to-end tests locally or in a PR,
// we can force-enable feature flags that haven't been enabled
// yet on stage or on prod:
process.env.E2E_TEST_ENV === "local"
) {
const { headers } = await import("next/headers");
const forcedFeatureFlags = (await headers()).get("x-forced-feature-flags");

Expand Down
Loading