mirror of
https://github.com/hanzoai/Detox.git
synced 2026-09-24 16:55:12 +00:00
fix(local-cli): respect detox build --if-missing for multi-app builds (#4549)
This commit is contained in:
committed by
GitHub
parent
664cdf1c6f
commit
ea6ae082b8
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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' }];
|
||||
|
||||
Reference in New Issue
Block a user