Skip to content

Commit

Permalink
Revert "Mock unleash for e2e tests"
Browse files Browse the repository at this point in the history
This reverts commit 4154a7f.
  • Loading branch information
mpanne committed Feb 12, 2025
1 parent ef2f68c commit 89a36aa
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 726 deletions.
590 changes: 6 additions & 584 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions packages/dito/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@ import type { EntryContext } from "@remix-run/node";
import { createReadableStreamFromReadable } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import { isbot } from "isbot";
import { mockServer } from "mocks/node";
import { renderToPipeableStream } from "react-dom/server";
import logResponseStatus from "utils/logging";
import { NonceProvider } from "utils/nonce";

if (process.env.MOCK_EXTERNAL_APIS && process.env.NODE_ENV !== "production") {
console.warn("Mock external APIs.");
mockServer.listen({
// This is going to perform unhandled requests
// but print no warning whatsoever when they happen.
onUnhandledRequest: "bypass",
});
}

const ABORT_DELAY = 5_000;
export const STRAPI_MEDIA_URL =
process.env.STRAPI_MEDIA_URL ||
Expand Down
4 changes: 0 additions & 4 deletions packages/dito/app/mocks/node.ts

This file was deleted.

94 changes: 0 additions & 94 deletions packages/dito/app/mocks/stubs/unleash/features.json

This file was deleted.

20 changes: 0 additions & 20 deletions packages/dito/app/mocks/unleashHandlers.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/dito/app/resources/features.ts

This file was deleted.

12 changes: 8 additions & 4 deletions packages/dito/app/routes/interoperabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ import Header from "@digitalcheck/shared/components/Header";
import Heading from "@digitalcheck/shared/components/Heading";
import Image from "@digitalcheck/shared/components/Image";
import RichText from "@digitalcheck/shared/components/RichText";
import { MetaFunction } from "@remix-run/react";
import { MetaFunction, useLoaderData } from "@remix-run/react";
import Accordion from "components/Accordion";
import FeedbackForm from "components/FeedbackForm";
import SupportBanner from "components/SupportBanner";
import TableOfContents from "components/TableOfContents";
import { interoperability } from "resources/content";
import { features } from "resources/features";
import { ROUTE_INTEROPERABILITY } from "resources/staticRoutes";
import { twJoin } from "tailwind-merge";
import { useFeatureFlag } from "utils/featureFlags";
import { getFeatureFlag } from "utils/featureFlags.server";
import prependMetaTitle from "utils/metaTitle";

export const meta: MetaFunction = ({ matches }) => {
return prependMetaTitle(ROUTE_INTEROPERABILITY.title, matches);
};

export function loader() {
const showPage = getFeatureFlag("digitalcheck.show-io-landingpage");
return { showPage };
}

export default function Interoperability() {
const showPage = useFeatureFlag(features.showIOLandingPage);
const { showPage } = useLoaderData<typeof loader>();

if (!showPage) {
throw new Response("Feature is not enabled for this environment", {

Check warning on line 31 in packages/dito/app/routes/interoperabel.tsx

View workflow job for this annotation

GitHub Actions / check-test-build-deploy (dito) / check-and-test-shared / check-and-test

Expected an error object to be thrown

Check warning on line 31 in packages/dito/app/routes/interoperabel.tsx

View workflow job for this annotation

GitHub Actions / check-test-build-deploy (dito) / check-and-test-shared / check-and-test

Expected an error object to be thrown
Expand Down
3 changes: 1 addition & 2 deletions packages/dito/app/routes/vorpruefung.ergebnis/ResultForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Textarea from "@digitalcheck/shared/components/Textarea";
import { useForm } from "@rvf/remix";
import React, { Dispatch, SetStateAction, useState } from "react";
import { preCheck } from "resources/content";
import { features } from "resources/features";
import { PreCheckAnswers } from "routes/vorpruefung.$questionId/route";
import getResultValidatorForAnswers from "routes/vorpruefung.ergebnis/resultValidation";
import { useFeatureFlag } from "utils/featureFlags";
Expand All @@ -23,7 +22,7 @@ export default function ResultForm({
answers: PreCheckAnswers;
setPolicyTitle: Dispatch<SetStateAction<string>>;
}>) {
const showSaveToPdf = useFeatureFlag(features.showSaveToPdfOption);
const showSaveToPdf = useFeatureFlag("digitalcheck.show-save-to-pdf-option");

const [showEmailAlert, setShowEmailAlert] = useState<boolean>(false);
const form = useForm({
Expand Down
20 changes: 20 additions & 0 deletions packages/dito/app/utils/featureFlags.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@ const unleash = initialize({
},
});

const DEFAULT_FLAG_STATE = false;
const DEFAULT_FLAG_STATE_CI = true;

let isUnleashInitialized = false;

unleash.on("ready", logger.log);
unleash.on("synchronized", () => {
isUnleashInitialized = true;
logger.log("Unleash is initialized.");
});
unleash.on("error", logger.error);
unleash.on("warn", logger.warn);

export const getFeatureFlag = (name: string): boolean => {
if (isCI) {
logger.warn(
`Unleash not available during CI. Defaulting "${name}" to ${DEFAULT_FLAG_STATE_CI}.`,
);
return DEFAULT_FLAG_STATE_CI;
} else if (!isUnleashInitialized) {
logger.warn(
`Unleash is not initialized. Defaulting "${name}" to ${DEFAULT_FLAG_STATE}.`,
);
}

return unleash.isEnabled(name);
};
export const getFeatureFlags = () =>
Object.fromEntries(
unleash
Expand Down
4 changes: 1 addition & 3 deletions packages/dito/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@rvf/remix": "^6.3.0",
"@rvf/zod": "^6.0.0",
"@strapi/blocks-react-renderer": "^1.0.1",
"@types/node": "^22.13.1",
"isbot": "^5.1.4",
"marked": "^15.0.0",
"mime-types": "^2.1.35",
Expand All @@ -46,8 +45,7 @@
"@remix-run/eslint-config": "^2.15.0",
"@types/mime-types": "^2.1.4",
"dotenv": "^16.4.5",
"jsdom": "^26.0.0",
"msw": "^2.7.0"
"jsdom": "^26.0.0"
},
"engines": {
"node": ">=20.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/dito/tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dotenv.config({ path: path.resolve(__dirname, "../", ".env.test") });
const config: PlaywrightTestConfig = {
...baseConfig,
webServer: {
command: "MOCK_EXTERNAL_APIS=true npm run dev -- --port 5172",
command: "npm run dev -- --port 5172",
port: 5172,
timeout: parseInt(process.env.WAIT_ON_TIMEOUT ?? `${5 * 1000}`),
},
Expand Down

0 comments on commit 89a36aa

Please sign in to comment.