Skip to content

Commit

Permalink
append instead of clobber SIM_CTL_DYLD_INSERT_LIBRARIES (#999)
Browse files Browse the repository at this point in the history
* append instead of clobber SIM_CTL_DYLD_INSERT_LIBRARIES

* const -> let rebase issue

* add tests
  • Loading branch information
quinlanj authored and LeoNatan committed Oct 29, 2018
1 parent 3ce07f2 commit 45c895a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 7 additions & 2 deletions detox/src/devices/ios/AppleSimUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,15 @@ class AppleSimUtils {
` tail -F ${logsInfo.absJoined}`
};

let dylibs = `${frameworkPath}/Detox`;
if (process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES) {
dylibs = `${process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES}:${dylibs}`;
}

let launchBin = `/bin/cat /dev/null >${logsInfo.absStdout} 2>${logsInfo.absStderr} && ` +
`SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="${frameworkPath}/Detox" ` +
`SIMCTL_CHILD_DYLD_INSERT_LIBRARIES="${dylibs}" ` +
`/usr/bin/xcrun simctl launch --stdout=${logsInfo.simStdout} --stderr=${logsInfo.simStderr} ` +
`${udid} ${bundleId} --args ${args}`;;
`${udid} ${bundleId} --args ${args}`;

if (!!languageAndLocale && !!languageAndLocale.language) {
launchBin += ` -AppleLanguages "(${languageAndLocale.language})"`;
Expand Down
20 changes: 20 additions & 0 deletions detox/src/devices/ios/AppleSimUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,26 @@ describe('AppleSimUtils', () => {
}
});

it('should append framework path to existing dyld path if present', async () => {
const origEnvVar = process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES;
process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES = '/tmp';
environment.getFrameworkPath.mockReturnValueOnce(Promise.resolve('thePathToFrameworks'));
try {
await uut.launch('udid', 'theBundleId');
expect(exec.execWithRetriesAndLogs.mock.calls).toMatchSnapshot();
} catch (e) {
fail(`should throw`);
} finally {
if (origEnvVar){
// set the env var back to what it used to be
process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES = origEnvVar;
} else {
// env var was never set to begin with, delete it
delete process.env.SIMCTL_CHILD_DYLD_INSERT_LIBRARIES;
}
}
});

it('returns the parsed id', async () => {
exec.execWithRetriesAndLogs.mockReturnValueOnce(Promise.resolve({ stdout: 'appId: 12345 \n' }));
const result = await uut.launch('udid', 'theBundleId');
Expand Down
15 changes: 15 additions & 0 deletions detox/src/devices/ios/__snapshots__/AppleSimUtils.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ Array [
]
`;

exports[`AppleSimUtils launch should append framework path to existing dyld path if present 1`] = `
Array [
Array [
"/bin/cat /dev/null >/Users/detox/Library/Developer/CoreSimulator/Devices/udid/data/tmp/detox.last_launch_app_log.out 2>/Users/detox/Library/Developer/CoreSimulator/Devices/udid/data/tmp/detox.last_launch_app_log.err && SIMCTL_CHILD_DYLD_INSERT_LIBRARIES=\\"/tmp:thePathToFrameworks/Detox\\" /usr/bin/xcrun simctl launch --stdout=/tmp/detox.last_launch_app_log.out --stderr=/tmp/detox.last_launch_app_log.err udid theBundleId --args ",
undefined,
Object {
"successful": "theBundleId launched. The stdout and stderr logs were recreated, you can watch them with:
tail -F /Users/detox/Library/Developer/CoreSimulator/Devices/udid/data/tmp/detox.last_launch_app_log.{out,err}",
"trying": "Launching theBundleId...",
},
1,
],
]
`;

exports[`AppleSimUtils openUrl calls xcrun simctl 1`] = `
Array [
Array [
Expand Down

0 comments on commit 45c895a

Please sign in to comment.