Skip to content

Commit

Permalink
Improve DX if any config is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Sep 1, 2023
1 parent ff37429 commit 32940c4
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/libs/E2E/reactNativeLaunchingTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import Performance from '../Performance';
import * as Metrics from '../Metrics';

// start the usual app
Performance.markStart('regularAppStart');
Expand All @@ -19,6 +20,11 @@ console.debug('==========================');
console.debug('==== Running e2e test ====');
console.debug('==========================');

// Check if the performance module is available
if (!Metrics.canCapturePerformanceMetrics()) {
throw new Error('Performance module not available! Please set CAPTURE_METRICS=true in your environment file!');
}

// import your test here, define its name and config first in e2e/config.js
const tests = {
[E2EConfig.TEST_NAMES.AppStartTime]: require('./tests/appStartTimeTest.e2e').default,
Expand All @@ -36,20 +42,28 @@ const appReady = new Promise((resolve) => {
});
});

E2EClient.getTestConfig().then((config) => {
const test = tests[config.name];
if (!test) {
// instead of throwing, report the error to the server, which is better for DX
return E2EClient.submitTestResults({
name: config.name,
error: `Test '${config.name}' not found`,
});
}
console.debug(`[E2E] Configured for test ${config.name}. Waiting for app to become ready`);

appReady.then(() => {
console.debug('[E2E] App is ready, running test…');
Performance.measureFailSafe('appStartedToReady', 'regularAppStart');
test();
E2EClient.getTestConfig()
.then((config) => {
const test = tests[config.name];
if (!test) {
// instead of throwing, report the error to the server, which is better for DX
return E2EClient.submitTestResults({
name: config.name,
error: `Test '${config.name}' not found`,
});
}

console.debug(`[E2E] Configured for test ${config.name}. Waiting for app to become ready`);
appReady
.then(() => {
console.debug('[E2E] App is ready, running test…');
Performance.measureFailSafe('appStartedToReady', 'regularAppStart');
test();
})
.catch((error) => {
console.error('[E2E] Error while waiting for app to become ready', error);
});
})
.catch((error) => {
console.error("[E2E] Error while running test. Couldn't get test config!", error);
});
});

0 comments on commit 32940c4

Please sign in to comment.