Added CypressStrictMode

This commit is contained in:
2022-08-15 11:51:40 +02:00
parent c0a0ea66a6
commit e20fea679a
4 changed files with 24 additions and 4 deletions

View File

@@ -1,9 +1,9 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { Provider } from "react-redux";
import { createGlobalStyle } from "styled-components";
import App from "./App";
import { store } from "./app/store";
import { CypressStrictMode } from "./infrastructure/CypressStrictMode";
import "./infrastructure/i18n/init";
import { OidcProvider } from "./infrastructure/sso/OidcProvider";
import { Loader } from "./infrastructure/wrappers/WithPageSuspense";
@@ -27,7 +27,7 @@ const GlobalStyle = createGlobalStyle`
`;
root.render(
<React.StrictMode>
<CypressStrictMode>
<GlobalStyle />
<Provider store={store}>
<OidcProvider>
@@ -36,7 +36,7 @@ root.render(
</Loader>
</OidcProvider>
</Provider>
</React.StrictMode>,
</CypressStrictMode>,
);
// If you want to start measuring performance in your app, pass a function

View File

@@ -0,0 +1,16 @@
import React, { FunctionComponent, ReactNode } from "react";
type Props = { children?: ReactNode };
/**
* React StrictMode that disables itself when detected to be running in Cypress
*/
export const CypressStrictMode: FunctionComponent<Props> = ({ children }) => {
const isInCypress = (window as any).Cypress;
if (isInCypress) {
return <>{children}</>;
} else {
return <React.StrictMode>{children}</React.StrictMode>;
}
};