Skip to content

Commit

Permalink
chore: apply code review suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
asafkorem committed May 19, 2024
1 parent 86d0dcb commit 7cea0f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
25 changes: 12 additions & 13 deletions detox/local-cli/utils/frameworkUtils.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
const os = require('os');
const path = require('path');

const exec = require('child-process-promise').exec;
const { spawn } = require('child-process-promise');
const fs = require('fs-extra');
const _ = require('lodash');

const detox = require('../../internals');
const { getFrameworkDirPath, getXCUITestRunnerDirPath } = require('../../src/utils/environment');


const frameworkBuildScript = '../../scripts/build_local_framework.ios.sh';
const xcuitestBuildScript = '../../scripts/build_local_xcuitest.ios.sh';

const getFrameworkPath = _.once(() => path.join(os.homedir(), '/Library/Detox/ios/framework'));
const getXcuitestPath = _.once(() => path.join(os.homedir(), '/Library/Detox/ios/xcuitest-runner'));

function shouldSkipExecution() {
if (os.platform() !== 'darwin') {
detox.log.info('The command is supported only on macOS, skipping the execution.');
Expand All @@ -25,12 +23,13 @@ function shouldSkipExecution() {
async function execBuildScript(targetPath, scriptPath, descriptor) {
detox.log.info(`Building ${descriptor} cache at ${targetPath}..`);

const scriptFullPath = path.join(__dirname, scriptPath);

try {
const result = await exec(path.join(__dirname, scriptPath), { capture: ['stdout', 'stderr'] });
detox.log.info(result.stdout);
await spawn(scriptFullPath, [], { stdio: 'inherit' });
} catch (error) {
detox.log.error(`Error while building ${descriptor}: ${error.stderr}`);
throw new Error(`Failed to build ${descriptor}`);
detox.log.error(`Error while building ${descriptor}:\n${error}`);
throw error;
}
}

Expand All @@ -48,11 +47,11 @@ async function build(framework, xcuitest) {
const shouldBuildBoth = !framework && !xcuitest;

if (framework || shouldBuildBoth) {
await execBuildScript(getFrameworkPath(), frameworkBuildScript, 'Detox framework');
await execBuildScript(getFrameworkDirPath, frameworkBuildScript, 'Detox framework');
}

if (xcuitest || shouldBuildBoth) {
await execBuildScript(getXcuitestPath(), xcuitestBuildScript, 'XCUITest runner');
await execBuildScript(getXCUITestRunnerDirPath, xcuitestBuildScript, 'XCUITest runner');
}
}

Expand All @@ -64,11 +63,11 @@ async function clean(framework, xcuitest) {
const shouldCleanBoth = !framework && !xcuitest;

if (framework || shouldCleanBoth) {
await removeTarget(getFrameworkPath(), 'Detox framework');
await removeTarget(getXCUITestRunnerDirPath, 'Detox framework');
}

if (xcuitest || shouldCleanBoth) {
await removeTarget(getXcuitestPath(), 'XCUITest runner');
await removeTarget(getXCUITestRunnerDirPath, 'XCUITest runner');
}
}

Expand Down
10 changes: 8 additions & 2 deletions detox/src/utils/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,18 @@ const getBuildFolderName = _.once(async () => {
.digest('hex');
});

const getFrameworkDirPath = `${DETOX_LIBRARY_ROOT_PATH}/ios/framework`;

const getFrameworkPath = _.once(async () => {
const buildFolder = await getBuildFolderName();
return `${DETOX_LIBRARY_ROOT_PATH}/ios/framework/${buildFolder}/Detox.framework`;
return `${getFrameworkDirPath}/${buildFolder}/Detox.framework`;
});

const getXCUITestRunnerDirPath = `${DETOX_LIBRARY_ROOT_PATH}/ios/xcuitest-runner`;

const getXCUITestRunnerPath = _.once(async () => {
const buildFolder = await getBuildFolderName();
const derivedDataPath = `${DETOX_LIBRARY_ROOT_PATH}/ios/xcuitest-runner/${buildFolder}`;
const derivedDataPath = `${getXCUITestRunnerDirPath}/${buildFolder}`;
const xctestrunPath = await exec(`find ${derivedDataPath} -name "*.xctestrun" -print -quit`)
.then(result => result.stdout.trim());

Expand Down Expand Up @@ -232,7 +236,9 @@ module.exports = {
getAndroidSdkManagerPath,
getGmsaasPath,
getDetoxVersion,
getFrameworkDirPath,
getFrameworkPath,
getXCUITestRunnerDirPath,
getXCUITestRunnerPath,
getAndroidSDKPath,
getAndroidEmulatorPath,
Expand Down

0 comments on commit 7cea0f4

Please sign in to comment.