Skip to content

Commit

Permalink
fix(local-cli): respect detox build --if-missing for multi-app builds (
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph authored Aug 13, 2024
1 parent 8f7e2d3 commit 4e217e7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
24 changes: 12 additions & 12 deletions detox/local-cli/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ module.exports.builder = {
},
};

function checkAppsExist(appsConfig, commands) {
function checkWhichAppsExist(appsConfig) {
const result = { '*': true };

for (const { appName } of commands) {
if (appName) {
result[appName] = true;
for (const appName of Object.keys(appsConfig)) {
result[appName] = true;

const app = appsConfig[appName] || {};
if (app.binaryPath && !fs.existsSync(app.binaryPath)) {
result[appName] = result['*'] = false;
}
if (app.testBinaryPath && !fs.existsSync(app.testBinaryPath)) {
result[appName] = result['*'] = false;
}
/* istanbul ignore next */
const app = appsConfig[appName] || {};
if (app.binaryPath && !fs.existsSync(app.binaryPath)) {
result[appName] = result['*'] = false;
}

if (app.testBinaryPath && !fs.existsSync(app.testBinaryPath)) {
result[appName] = result['*'] = false;
}
}

Expand All @@ -56,7 +56,7 @@ function checkAppsExist(appsConfig, commands) {

module.exports.handler = async function build(argv) {
const { apps, commands, errorComposer } = await detox.resolveConfig({ argv });
const appsExist = checkAppsExist(apps, commands);
const appsExist = checkWhichAppsExist(apps);

let seenBuildCommands = false;

Expand Down
14 changes: 12 additions & 2 deletions detox/local-cli/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ describe('build', () => {
detox.config.apps.app2 = { binaryPath: __filename };
detox.config.commands = [
{ build: 'yet another command' },
{ appName: 'app1' },
{ appName: 'app2' },
];

await callCli('./build', 'build -i');
Expand All @@ -90,6 +88,18 @@ describe('build', () => {
expect(detox.log.info).toHaveBeenCalledWith('Skipping build...');
});

it('should not skip building the multi-app build command if one app does not exist', async () => {
detox.config.apps.app1 = { binaryPath: __filename };
detox.config.apps.app2 = { binaryPath: __filename + '.doesnotexist' };
detox.config.commands = [
{ build: 'yet another command' },
];

await callCli('./build', 'build --if-missing');
expect(execSync).toHaveBeenCalled();
expect(detox.log.info).not.toHaveBeenCalledWith('Skipping build...');
});

it('fails with an error if a build script has not been found', async () => {
detox.config.apps.default = {};
detox.config.commands = [{ appName: 'default', start: 'a command' }];
Expand Down

0 comments on commit 4e217e7

Please sign in to comment.