Skip to content

Commit

Permalink
chore: combines two environment variables into a single isE2E variable
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherferreira9 committed Feb 13, 2025
1 parent e00b97f commit c14d237
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .e2e.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
export MM_TEST_ACCOUNT_SRP='word1 word... word12'
export MM_TEST_ACCOUNT_ADDRESS='0x...'
export MM_TEST_ACCOUNT_PRIVATE_KEY=''
export IS_TEST="true"
export IS_E2E="true"
# Temporary mechanism to enable security alerts API prior to release.
export MM_SECURITY_ALERTS_API_ENABLED="true"
2 changes: 1 addition & 1 deletion .js.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export SENTRY_DISABLE_AUTO_UPLOAD="true"

# ENV vars for e2e tests
# enable e2e tests when value is true
export IS_TEST=""
export IS_E2E=""
# defined as secrets to run on Bitrise CI
# but have to be defined here for local tests
export MM_TEST_ACCOUNT_SRP=""
Expand Down
4 changes: 2 additions & 2 deletions app/components/Nav/Main/MainNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import { useMetrics } from '../../../components/hooks/useMetrics';
import DeprecatedNetworkDetails from '../../UI/DeprecatedNetworkModal';
import ConfirmAddAsset from '../../UI/ConfirmAddAsset';
import { AesCryptoTestForm } from '../../Views/AesCryptoTestForm';
import { isTest } from '../../../util/test/utils';
import { isE2E } from '../../../util/test/utils';
import { selectPermissionControllerState } from '../../../selectors/snaps/permissionController';
import NftDetails from '../../Views/NftDetails';
import NftDetailsFullImage from '../../Views/NftDetails/NFtDetailsFullImage';
Expand Down Expand Up @@ -290,7 +290,7 @@ const SettingsFlow = () => (
*
* If this is in production, it is a bug.
*/
isTest && (
isE2E && (
<Stack.Screen
name="AesCryptoTestForm"
component={AesCryptoTestForm}
Expand Down
6 changes: 3 additions & 3 deletions app/components/UI/OnboardingWizard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
import { useTheme } from '../../../util/theme';
import Device from '../../../util/device';
import StorageWrapper from '../../../store/storage-wrapper';
import { isTest } from '../../../util/test/utils';
import { isE2E } from '../../../util/test/utils';
import { useMetrics } from '../../hooks/useMetrics';
import { RootState } from '../../../reducers';

Expand Down Expand Up @@ -118,9 +118,9 @@ const OnboardingWizard = ({
};

// Since react-native-default-preference is not covered by the fixtures,
// when isTest is `true`, if the ONBOARDING_WIZARD is marked as 'explored',
// when isE2E is `true`, if the ONBOARDING_WIZARD is marked as 'explored',
// it indicates that it was provided by fixtures, triggering the call to closeOnboardingWizard().
if (isTest && step === 1) {
if (isE2E && step === 1) {
const inTestCloseOnboardingWizard = async () => {
const wizardStep = await StorageWrapper.getItem(ONBOARDING_WIZARD);
if (wizardStep === EXPLORED) {
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/BrowserTab/BrowserTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { useMetrics } from '../../../components/hooks/useMetrics';
import { trackDappViewedEvent } from '../../../util/metrics';
import trackErrorAsAnalytics from '../../../util/metrics/TrackError/trackErrorAsAnalytics';
import { selectPermissionControllerState } from '../../../selectors/snaps/permissionController';
import { isTest } from '../../../util/test/utils.js';
import { isE2E } from '../../../util/test/utils.js';
import { EXTERNAL_LINK_TYPE } from '../../../constants/browser';
import { PermissionKeys } from '../../../core/Permissions/specifications';
import { CaveatTypes } from '../../../core/Permissions/constants';
Expand Down Expand Up @@ -1368,7 +1368,7 @@ export const BrowserTab: React.FC<BrowserTabProps> = ({
testID={BrowserViewSelectorsIDs.BROWSER_WEBVIEW_ID}
applicationNameForUserAgent={'WebView MetaMaskMobile'}
onFileDownload={handleOnFileDownload}
webviewDebuggingEnabled={isTest}
webviewDebuggingEnabled={isE2E}
/>
{ipfsBannerVisible && (
<IpfsBanner setIpfsBannerVisible={setIpfsBannerVisible} />
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/ErrorBoundary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
} from '../../../components/hooks/useMetrics';
import AppConstants from '../../../core/AppConstants';
import { useSelector } from 'react-redux';
import { isTest } from '../../../util/test/utils';
import { isE2E } from '../../../util/test/utils';
// eslint-disable-next-line import/no-commonjs
const WarningIcon = require('./warning-icon.png');

Expand Down Expand Up @@ -270,7 +270,7 @@ export const Fallback = (props) => {
}
/>

{isTest && (
{isE2E && (
<Text style={styles.text}>
<Text onPress={props.showExportSeedphrase} style={styles.link}>
{strings('error_screen.save_seedphrase_2')}
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/OnboardingCarousel/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import renderWithProvider from '../../../util/test/renderWithProvider';

jest.mock('../../../util/metrics/TrackOnboarding/trackOnboarding');
jest.mock('../../../util/test/utils', () => ({
isTest: true,
isE2E: true,
}));

const mockNavigate: jest.Mock = jest.fn();
Expand All @@ -26,7 +26,7 @@ describe('OnboardingCarousel', () => {
expect(toJSON()).toMatchSnapshot();
});

it('should render the App Start Time text when isTest is true', async () => {
it('should render the App Start Time text when isE2E is true', async () => {
const { toJSON, getByTestId } = renderWithProvider(
<OnboardingCarousel navigation={mockNavigation}/>
);
Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/OnboardingCarousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { WELCOME_SCREEN_CAROUSEL_TITLE_ID } from '../../../../wdio/screen-object
import { OnboardingCarouselSelectorIDs } from '../../../../e2e/selectors/Onboarding/OnboardingCarousel.selectors';
import generateTestId from '../../../../wdio/utils/generateTestId';
import trackOnboarding from '../../../util/metrics/TrackOnboarding/trackOnboarding';
import { isTest } from '../../../util/test/utils';
import { isE2E } from '../../../util/test/utils';
import StorageWrapper from '../../../store/storage-wrapper';
import { Dispatch } from 'redux';
import {
Expand Down Expand Up @@ -250,7 +250,7 @@ export const OnboardingCarousel: React.FC<OnboardingCarouselProps> = ({
<Text style={styles.title}>
{strings(`onboarding_carousel.title${key}`)}
</Text>
{isTest && (
{isE2E && (
// This Text component is used to grab the App Start Time for our E2E test
// ColdStartToOnboardingScreen.feature
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { uint8ArrayToMnemonic } from '../../../util/mnemonic';
import { passwordRequirementsMet } from '../../../util/password';
import { Authentication } from '../../../core/';

import { isTest } from '../../../util/test/utils';
import { isE2E } from '../../../util/test/utils';
import Device from '../../../util/device';
import { strings } from '../../../../locales/i18n';
import { isHardwareAccount } from '../../../util/address';
Expand Down Expand Up @@ -517,7 +517,7 @@ const RevealPrivateCredential = ({
</Text>
</TouchableOpacity>
</Text>
{isTest ? (
{isE2E ? (
<Button
label={strings('reveal_credential.reveal_credential', {
credentialName: isPrivateKeyReveal
Expand Down
12 changes: 6 additions & 6 deletions app/components/Views/Root/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import ErrorBoundary from '../ErrorBoundary';
import { useAppTheme, ThemeContext } from '../../../util/theme';
import { ToastContextWrapper } from '../../../component-library/components/Toast';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { isTest } from '../../../util/test/utils';
import { isE2E } from '../../../util/test/utils';

/**
* Top level of the component hierarchy
Expand Down Expand Up @@ -50,21 +50,21 @@ export default class Root extends PureComponent {

this.state = {
isLoading: true, // Track loading state
isTest,
isE2E,
};
}

async componentDidMount() {
const { isTest } = this.state;
if (isTest) {
const { isE2E } = this.state;
if (isE2E) {
await this.waitForStore();
this.setState({ isLoading: false });
}
}

render() {
const { isTest, isLoading } = this.state;
if (isTest && isLoading) {
const { isE2E, isLoading } = this.state;
if (isE2E && isLoading) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions app/components/Views/Settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createSnapsSettingsListNavDetails } from '../Snaps/SnapsSettingsList/Sn
import { TextColor } from '../../../component-library/components/Texts/Text';
import { useMetrics } from '../../../components/hooks/useMetrics';
import { isNotificationsFeatureEnabled } from '../../../util/notifications';
import { isTest } from '../../../util/test/utils';
import { isE2E } from '../../../util/test/utils';
import { isPermissionsSettingsV1Enabled } from '../../../util/networks';

const createStyles = (colors: Colors) =>
Expand Down Expand Up @@ -273,7 +273,7 @@ const Settings = () => {
*
* If this is shown in production, it is a bug.
*/
isTest && (
isE2E && (
<SettingsDrawer
title={strings('app_settings.aes_crypto_test_form_title')}
description={strings(
Expand Down
2 changes: 1 addition & 1 deletion app/core/Engine/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ export class Engine {
const userStorageController = new UserStorageController.Controller({
getMetaMetricsState: () => MetaMetrics.getInstance().isEnabled(),
env: {
isAccountSyncingEnabled: Boolean(process.env.IS_TEST),
isAccountSyncingEnabled: Boolean(process.env.IS_E2E),
},
config: {
accountSyncing: {
Expand Down
2 changes: 1 addition & 1 deletion app/core/Performance/Performance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Performance', () => {

it('should not log performance numbers in production', () => {
jest.mock('../../util/test/utils', () => ({
isTest: true, // or false, depending on what you want to test
isE2E: true, // or false, depending on what you want to test
}));

// Mock console.info to verify its calls
Expand Down
4 changes: 2 additions & 2 deletions app/core/Performance/Performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import performance, { PerformanceObserver } from 'react-native-performance';
import StorageWrapper from '../../store/storage-wrapper';
import { TraceName, TraceOperation, endTrace, trace } from '../../util/trace';
import getUIStartupSpan from './UIStartup';
import { isTest } from '../../util/test/utils';
import { isE2E } from '../../util/test/utils';

/**
* Service for measuring app performance
Expand Down Expand Up @@ -47,7 +47,7 @@ class Performance {
// the total app start time is then the maximum of the two durations
const appStartTime = Math.max(nativeLaunchDuration, jsBundleDuration);

if (isTest) {
if (isE2E) {
// eslint-disable-next-line no-console
console.info(
`-------------------------------------------------------`,
Expand Down
2 changes: 1 addition & 1 deletion app/store/storage-wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('StorageWrapper', () => {
});

it('use ReadOnlyStore on E2E', async () => {
process.env.IS_TEST = 'true';
process.env.IS_E2E = 'true';

const getItemSpy = jest.spyOn(StorageWrapper, 'getItem');
const setItemSpy = jest.spyOn(StorageWrapper, 'setItem');
Expand Down
4 changes: 2 additions & 2 deletions app/util/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const testConfig = {};
/**
* TODO: Update this condition once we change E2E builds to use release instead of debug
*/
export const isTest = process.env.METAMASK_ENVIRONMENT !== 'production';
export const isE2E = process.env.IS_TEST === 'true';
export const isE2E = process.env.IS_E2E === 'true' && process.env.METAMASK_ENVIRONMENT !== 'production';

export const getFixturesServerPortInApp = () =>
testConfig.fixtureServerPort ?? FIXTURE_SERVER_PORT;
2 changes: 1 addition & 1 deletion docs/readme/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Detox serves as our primary mobile automation framework, with most of our tests
#### Setup and Execution

- **Test Wallet**: Requires a wallet with access to testnet and mainnet. On Bitrise CI, this wallet is created using a secret recovery phrase from environment variables. For local testing, retrieve the phrase from the `.e2e.env` file.
- **Environment Variable**: Set `IS_TEST='true'` to enable the test environment. Refer to the `.e2e.env` file in the mobile 1Password vault for the complete list of environment variables.
- **Environment Variable**: Set `IS_E2E='true'` to enable the test environment. Refer to the `.e2e.env` file in the mobile 1Password vault for the complete list of environment variables.
- **Warning Logs**: Warning logs may sometimes cause test failures by interfering with automation interactions. To prevent this, disable warning logs during test execution.

#### Default Devices
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
"test:unit": "jest ./app/ ./locales/",
"test:unit:update": "time jest -u ./app/",
"test:api-specs": "detox reset-lock-file && detox test -c ios.sim.apiSpecs",
"test:e2e:ios:build:qa-release": "IS_TEST='true' detox build -c ios.sim.qa",
"test:e2e:ios:run:qa-release": "IS_TEST='true' detox test -c ios.sim.qa",
"test:e2e:android:build:qa-release": "NO_FLIPPER='1' IS_TEST='true' detox build -c android.emu.release.qa",
"test:e2e:android:run:qa-release": "NO_FLIPPER='1' IS_TEST='true' detox test -c android.emu.release.qa --headless --record-logs all",
"test:e2e:ios:debug:build": "IS_TEST='true' detox build -c ios.sim.debug",
"test:e2e:ios:debug:run": "IS_TEST='true' detox reset-lock-file && detox test -c ios.sim.debug",
"test:e2e:android:debug:build": "IS_TEST='true' detox build -c android.emu.debug",
"test:e2e:android:debug:run": "IS_TEST='true' detox test -c android.emu.debug",
"test:e2e:ios:build:qa-release": "IS_E2E='true' detox build -c ios.sim.qa",
"test:e2e:ios:run:qa-release": "IS_E2E='true' detox test -c ios.sim.qa",
"test:e2e:android:build:qa-release": "NO_FLIPPER='1' IS_E2E='true' detox build -c android.emu.release.qa",
"test:e2e:android:run:qa-release": "NO_FLIPPER='1' IS_E2E='true' detox test -c android.emu.release.qa --headless --record-logs all",
"test:e2e:ios:debug:build": "IS_E2E='true' detox build -c ios.sim.debug",
"test:e2e:ios:debug:run": "IS_E2E='true' detox reset-lock-file && detox test -c ios.sim.debug",
"test:e2e:android:debug:build": "IS_E2E='true' detox build -c android.emu.debug",
"test:e2e:android:debug:run": "IS_E2E='true' detox test -c android.emu.debug",
"test:wdio:ios": "yarn wdio ./wdio/config/ios.config.debug.js",
"test:wdio:ios:browserstack": "yarn wdio ./wdio/config/ios.config.browserstack.js",
"test:wdio:ios:browserstack:local": "yarn wdio ./wdio/config/ios.config.browserstack.local.js",
Expand Down
6 changes: 3 additions & 3 deletions shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import { decode, encode } from 'base-64';
import {
FIXTURE_SERVER_PORT,
isTest,
isE2E,
testConfig,
} from './app/util/test/utils.js';
import { LaunchArguments } from 'react-native-launch-arguments';
import { defaultMockPort } from './e2e/api-mocking/mock-config/mockUrlCollection.json';

// In a testing environment, assign the fixtureServerPort to use a deterministic port
if (isTest) {
if (isE2E) {
const raw = LaunchArguments.value();
testConfig.fixtureServerPort = raw?.fixtureServerPort
? raw.fixtureServerPort
Expand Down Expand Up @@ -59,7 +59,7 @@ if (typeof localStorage !== 'undefined') {
// crypto is loaded first, so it can populate global.crypto
// require('crypto')

if (isTest) {
if (isE2E) {
(async () => {
const raw = LaunchArguments.value();
const mockServerPort = raw?.mockServerPort ?? defaultMockPort;
Expand Down

0 comments on commit c14d237

Please sign in to comment.