Skip to content

Commit

Permalink
Merge pull request #30502 from margelo/e2e/add-typing-tests
Browse files Browse the repository at this point in the history
[DEV] E2e/add typing tests
  • Loading branch information
mountiny authored Nov 6, 2023
2 parents 87cff84 + 7a38570 commit f0d5bd3
Show file tree
Hide file tree
Showing 24 changed files with 2,250 additions and 73 deletions.
11 changes: 7 additions & 4 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ require('dotenv').config();

const defaultConfig = getDefaultConfig(__dirname);

const isUsingMockAPI = process.env.E2E_TESTING === 'true';
const isE2ETesting = process.env.E2E_TESTING === 'true';

if (isUsingMockAPI) {
if (isE2ETesting) {
// eslint-disable-next-line no-console
console.log('⚠️⚠️⚠️⚠️ Using mock API ⚠️⚠️⚠️⚠️');
}

const e2eSourceExts = ['e2e.js', 'e2e.ts'];

/**
* Metro configuration
* https://facebook.github.io/metro/docs/configuration
Expand All @@ -22,10 +24,11 @@ if (isUsingMockAPI) {
const config = {
resolver: {
assetExts: _.filter(defaultAssetExts, (ext) => ext !== 'svg'),
sourceExts: [...defaultSourceExts, 'jsx', 'svg'],
// When we run the e2e tests we want files that have the extension e2e.js to be resolved as source files
sourceExts: [...(isE2ETesting ? e2eSourceExts : []), ...defaultSourceExts, 'jsx', 'svg'],
resolveRequest: (context, moduleName, platform) => {
const resolution = context.resolveRequest(context, moduleName, platform);
if (isUsingMockAPI && moduleName.includes('/API')) {
if (isE2ETesting && moduleName.includes('/API')) {
const originalPath = resolution.filePath;
const mockPath = originalPath.replace('src/libs/API.ts', 'src/libs/E2E/API.mock.js').replace('/src/libs/API.js/', 'src/libs/E2E/API.mock.js');
// eslint-disable-next-line no-console
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
"analyze-packages": "ANALYZE_BUNDLE=true webpack --config config/webpack/webpack.common.js --env envFile=.env.production",
"symbolicate:android": "npx metro-symbolicate android/app/build/generated/sourcemaps/react/release/index.android.bundle.map",
"symbolicate:ios": "npx metro-symbolicate main.jsbundle.map",
"test:e2e:main": "node tests/e2e/testRunner.js --development --branch main --skipCheckout",
"test:e2e:delta": "node tests/e2e/testRunner.js --development --branch main --label delta --skipCheckout",
"test:e2e:dev": "node tests/e2e/testRunner.js --development --skipCheckout --config ./config.dev.js --buildMode skip --skipInstallDeps",
"test:e2e:main": "node tests/e2e/testRunner.js --development --skipCheckout",
"test:e2e:delta": "node tests/e2e/testRunner.js --development --label delta --skipCheckout --skipInstallDeps",
"test:e2e:compare": "node tests/e2e/merge.js",
"gh-actions-unused-styles": "./.github/scripts/findUnusedKeys.sh",
"workflow-test": "./workflow_tests/scripts/runWorkflowTests.sh",
Expand Down
13 changes: 10 additions & 3 deletions src/libs/E2E/API.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import mockAuthenticatePusher from './apiMocks/authenticatePusher';
import mockBeginSignin from './apiMocks/beginSignin';
import mockOpenApp from './apiMocks/openApp';
import mockOpenReport from './apiMocks/openReport';
import mockReadNewestAction from './apiMocks/readNewestAction';
import mockSigninUser from './apiMocks/signinUser';

/**
Expand All @@ -20,17 +21,23 @@ const mocks = {
OpenApp: mockOpenApp,
ReconnectApp: mockOpenApp,
OpenReport: mockOpenReport,
ReconnectToReport: mockOpenReport,
AuthenticatePusher: mockAuthenticatePusher,
ReadNewestAction: mockReadNewestAction,
};

function mockCall(command, apiCommandParameters, tag) {
const mockResponse = mocks[command] && mocks[command](apiCommandParameters);
if (!mockResponse || !_.isArray(mockResponse.onyxData)) {
Log.warn(`[${tag}] for command ${command} is not mocked yet!`);
if (!mockResponse) {
Log.warn(`[${tag}] for command ${command} is not mocked yet! ⚠️`);
return;
}

return Onyx.update(mockResponse.onyxData);
if (_.isArray(mockResponse.onyxData)) {
return Onyx.update(mockResponse.onyxData);
}

return Promise.resolve(mockResponse);
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/libs/E2E/actions/waitForKeyboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Keyboard} from 'react-native';

export default function waitForKeyboard() {
return new Promise((resolve) => {
function checkKeyboard() {
if (Keyboard.isVisible()) {
resolve();
} else {
console.debug(`[E2E] Waiting for keyboard to appear…`);
setTimeout(checkKeyboard, 1000);
}
}
checkKeyboard();
});
}
Loading

0 comments on commit f0d5bd3

Please sign in to comment.