Skip to content

Commit

Permalink
update comments
Browse files Browse the repository at this point in the history
Signed-off-by: Hanno J. Gödecke <die.drei99@yahoo.de>
  • Loading branch information
hannojg committed Oct 13, 2022
1 parent 37e7986 commit 4c677ca
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion e2e/compare/math.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* base implementation from: https://github.com/callstack/reassure/blob/main/packages/reassure-compare/src/compare.ts
* Base implementation from: https://github.com/callstack/reassure/blob/main/packages/reassure-compare/src/compare.ts
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion e2e/measure/math.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const _ = require('underscore');
const {DROP_WORST} = require('../config');

// simple outlier removal, where we remove at the head and tail entries
// Simple outlier removal, where we remove at the head and tail entries
const filterOutliers = (data) => {
// Copy the values, rather than operating on references to existing values
const values = [...data].sort();
Expand Down
4 changes: 2 additions & 2 deletions e2e/server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ module.exports = {
// The app calls this endpoint to know which test to run
testConfig: '/test_config',

// when running a test the app reports the results to this endpoint
// When running a test the app reports the results to this endpoint
testResults: '/test_results',

// when the app is done running a test it calls this endpoint
// When the app is done running a test it calls this endpoint
testDone: '/test_done',
};
33 changes: 16 additions & 17 deletions e2e/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ const args = process.argv.slice(2);

const baselineBranch = process.env.baseline || DEFAULT_BASELINE_BRANCH;

// clear all files from previous jobs
// Clear all files from previous jobs
try {
fs.rmSync(OUTPUT_DIR, {recursive: true, force: true});
fs.mkdirSync(OUTPUT_DIR);
} catch (error) {
// do nothing
// Do nothing
console.error(error);
}

Expand All @@ -51,7 +51,7 @@ const restartApp = async () => {
};

const runTestsOnBranch = async (branch, baselineOrCompare) => {
// switch branch and install dependencies
// Switch branch and install dependencies
const progress = Logger.progressInfo(`Preparing ${baselineOrCompare} tests on branch '${branch}'`);
await execAsync(`git switch ${branch}`);

Expand All @@ -60,28 +60,28 @@ const runTestsOnBranch = async (branch, baselineOrCompare) => {
await execAsync('npm i');
}

// build app
// Build app
if (!args.includes('--skipBuild')) {
progress.updateText(`Preparing ${baselineOrCompare} tests on branch '${branch}' - building app`);
await execAsync('npm run android-build-e2e');
}
progress.done();

// install app and reverse ports
// Install app and reverse ports
let progressLog = Logger.progressInfo('Installing app');
await installApp('android');
Logger.log('Reversing port (for connecting to testing server) …');
await reversePort();
progressLog.done();

// start the HTTP server
// Start the HTTP server
const server = createServerInstance();
await server.start();

// create a dict in which we will store the run durations for all tests
// Create a dict in which we will store the run durations for all tests
const durationsByTestName = {};

// collect results while tests are being executed
// Collect results while tests are being executed
server.addTestResultListener((testResult) => {
if (testResult.error != null) {
throw new Error(`Test '${testResult.name}' failed with error: ${testResult.error}`);
Expand All @@ -94,7 +94,7 @@ const runTestsOnBranch = async (branch, baselineOrCompare) => {
durationsByTestName[testResult.name] = (durationsByTestName[testResult.name] || []).concat(testResult.duration);
});

// run the tests
// Run the tests
const numOfTests = _.values(TESTS_CONFIG).length;
for (let testIndex = 0; testIndex < numOfTests; testIndex++) {
const config = _.values(TESTS_CONFIG)[testIndex];
Expand Down Expand Up @@ -127,7 +127,7 @@ const runTestsOnBranch = async (branch, baselineOrCompare) => {

await restartApp();

// wait for a test to finish by waiting on its done call to the http server
// Wait for a test to finish by waiting on its done call to the http server
try {
await withFailTimeout(new Promise((resolve) => {
const cleanup = server.addTestDoneListener(() => {
Expand All @@ -138,16 +138,16 @@ const runTestsOnBranch = async (branch, baselineOrCompare) => {
}), progressText);
await stopVideoRecording(false);
} catch (e) {
// when we fail due to a timeout it's interesting to take a screenshot of the emulator to see whats going on
// When we fail due to a timeout it's interesting to take a screenshot of the emulator to see whats going on
await stopVideoRecording(true);
testLog.done();
throw e; // rethrow to abort execution
throw e; // Rethrow to abort execution
}
}
testLog.done();
}

// calculate statistics and write them to our work file
// Calculate statistics and write them to our work file
progressLog = Logger.progressInfo('Calculating statics and writing results');
const outputFileName = `${OUTPUT_DIR}/${baselineOrCompare}.json`;
for (const testName of _.keys(durationsByTestName)) {
Expand All @@ -162,18 +162,17 @@ const runTestsOnBranch = async (branch, baselineOrCompare) => {
}
progressLog.done();

// close server
await server.stop();
};

const runTests = async () => {
Logger.info('Running e2e tests');

try {
// run tests on baseline branch
// Run tests on baseline branch
await runTestsOnBranch(baselineBranch, 'baseline');

// run tests on current branch
// Run tests on current branch
await runTestsOnBranch('-', 'compare');

await compare();
Expand All @@ -182,7 +181,7 @@ const runTests = async () => {
} catch (e) {
Logger.info('\n\nE2E test suite failed due to error:', e, '\nPrinting full logs:\n\n');

// write logcat, meminfo, emulator info to file as well:
// Write logcat, meminfo, emulator info to file as well:
require('node:child_process').execSync(`adb logcat -d > ${OUTPUT_DIR}/logcat.txt`);
require('node:child_process').execSync(`adb shell "cat /proc/meminfo" > ${OUTPUT_DIR}/meminfo.txt`);
require('node:child_process').execSync(`cat ~/.android/avd/${process.env.AVD_NAME || 'test'}.avd/config.ini > ${OUTPUT_DIR}/emulator-config.ini`);
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils/execAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = (command) => {
Logger.log('Output of command:', command);
process = exec(command, {
encoding: 'utf8',
maxBuffer: 1024 * 1024 * 10, // increase max buffer to 10MB, to avoid errors
maxBuffer: 1024 * 1024 * 10, // Increase max buffer to 10MB, to avoid errors
}, (error, stdout) => {
if (error) {
if (error && error.killed) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils/installApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ module.exports = function (platform = 'android') {
throw new Error(`installApp() missing implementation for platform: ${platform}`);
}

// uninstall first, then install
// Uninstall first, then install
return execAsync(`adb uninstall ${APP_PACKAGE}`).finally(() => execAsync(`adb install ${APP_PATH_FROM_ROOT}`));
};
2 changes: 1 addition & 1 deletion e2e/utils/killApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = function (platform = 'android') {
throw new Error(`killApp() missing implementation for platform: ${platform}`);
}

// use adb to kill the app
// Use adb to kill the app
return execAsync(`adb shell am force-stop ${APP_PACKAGE}`);
};
2 changes: 1 addition & 1 deletion e2e/utils/launchApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = function (platform = 'android') {
throw new Error(`launchApp() missing implementation for platform: ${platform}`);
}

// use adb to start the app
// Use adb to start the app
return execAsync(`adb shell monkey -p ${APP_PACKAGE} -c android.intent.category.LAUNCHER 1`);
};
6 changes: 3 additions & 3 deletions e2e/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const setLogLevelVerbose = (value) => {
isVerbose = value;
};

// on CI systems when using .progressInfo, the current line won't reset but a new line gets added
// which can flood the logs. You can increase this rate to mitigate this effect.
// On CI systems when using .progressInfo, the current line won't reset but a new line gets added
// Which can flood the logs. You can increase this rate to mitigate this effect.
const LOGGER_PROGRESS_REFRESH_RATE = process.env.LOGGER_PROGRESS_REFRESH_RATE || 250;
const COLOR_DIM = '\x1b[2m';
const COLOR_RESET = '\x1b[0m';
Expand All @@ -18,7 +18,7 @@ const log = (...args) => {
console.debug(...args);
}

// write to log file
// Write to log file
if (!fs.existsSync(LOG_FILE)) {
fs.writeFileSync(LOG_FILE, '');
}
Expand Down
8 changes: 4 additions & 4 deletions e2e/utils/startRecordingVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const {OUTPUT_DIR} = require('../config');
const Logger = require('../utils/logger');

module.exports = () => {
// the emulator on CI launches with no-window option.
// taking screenshots results in blank shots.
// The emulator on CI launches with no-window option.
// Taking screenshots results in blank shots.
// Recording a video however includes the graphic content.
const cmd = 'adb shell screenrecord /sdcard/video.mp4';
let recordingFailed = false;
const recording = execAsync(cmd);
recording.catch((error) => {
// don't abort on errors
// Don't abort on errors
Logger.warn('Error while recording video', error);
recordingFailed = true;
});
Expand All @@ -33,7 +33,7 @@ module.exports = () => {
} else {
resolve();
}
}, 1000); // give the device some time to finish writing the file
}, 1000); // Give the device some time to finish writing the file
});
};
};

0 comments on commit 4c677ca

Please sign in to comment.