fix(local-cli): respect detox build --if-missing for multi-app builds (#4549)

This commit is contained in:
Yaroslav Serhieiev
2024-08-13 15:34:26 +03:00
committed by GitHub
parent 664cdf1c6f
commit ea6ae082b8
2 changed files with 49 additions and 2 deletions
+23 -2
View File
@@ -34,8 +34,29 @@ module.exports.builder = {
},
};
function checkAppsExist(appsConfig, commands) {
const result = { '*': true };
for (const { appName } of commands) {
if (appName) {
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;
}
}
}
return result;
}
module.exports.handler = async function build(argv) {
const { apps, commands, errorComposer } = await detox.resolveConfig({ argv });
const appsExist = checkAppsExist(apps, commands);
let seenBuildCommands = false;
@@ -45,8 +66,8 @@ module.exports.handler = async function build(argv) {
if (build) {
seenBuildCommands = true;
if (argv['if-missing'] && app.binaryPath && fs.existsSync(app.binaryPath)) {
detox.log.info(`Skipping build for "${appName}" app...`);
if (argv['if-missing'] && appsExist[appName || '*']) {
detox.log.info(appName ? `Skipping build for "${appName}" app...` : 'Skipping build...');
continue;
}
+26
View File
@@ -64,6 +64,32 @@ describe('build', () => {
expect(detox.log.info).toHaveBeenCalledWith('Skipping build for "default" app...');
});
it('should not skip building the app if the test binary does not exist', async () => {
detox.config.apps.default = { binaryPath: __filename, testBinaryPath: __filename + '.doesnotexist' };
detox.config.commands = [{ appName: 'default', build: 'yet another command' }];
await callCli('./build', 'build --if-missing');
expect(execSync).toHaveBeenCalled();
});
it('skips building the multi-app build command if all apps exist and --if-missing flag is set', async () => {
detox.config.apps.app1 = { binaryPath: __filename };
detox.config.apps.app2 = { binaryPath: __filename };
detox.config.commands = [
{ build: 'yet another command' },
{ appName: 'app1' },
{ appName: 'app2' },
];
await callCli('./build', 'build -i');
expect(execSync).not.toHaveBeenCalled();
await callCli('./build', 'build --if-missing');
expect(execSync).not.toHaveBeenCalled();
expect(detox.log.info).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' }];