Skip to content

Commit 99e5a89

Browse files
committed
Changes to how Detox is injected.
1 parent af50e01 commit 99e5a89

File tree

11 files changed

+128
-158
lines changed

11 files changed

+128
-158
lines changed

INSTALLING.md

+12-19
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
If you have integrated with Detox in the past, you will need to clean your project before integrating with current Detox version.
88

9-
* Under Frameworks, remove "Detox.framework" from your project.
10-
* In your AppDelegate.m, remove any Detox code, such as calls to `detoxConditionalInit()`.
9+
* Use the provided `cleanup_4.0.rb` to remove unneeded changes made with Detox 4.0.x.
10+
* Make sure to add changes performed by running this script to version control.
1111

1212
#### Step 1: Prerequisites
1313

@@ -42,7 +42,7 @@ By default, Xcode uses a randomized hidden path for outputting project build art
4242
"sessionId": "YourProject"
4343
},
4444
"ios-simulator": {
45-
"app": "ios/Build/Products/Debug_Detox-iphonesimulator/YourProject.app",
45+
"app": "ios/Build/Products/Debug-iphonesimulator/YourProject.app",
4646
"device": "iPhone 7, iOS 10.1"
4747
}
4848
}
@@ -51,38 +51,31 @@ By default, Xcode uses a randomized hidden path for outputting project build art
5151
5252
* The resulting `package.json` should look something like [this](demo-react-native/package.json).
5353

54-
#### Step 3: Integrate Detox in Your Project
55-
56-
* Make sure your Project schemes are shared. Open you project in Xcode, select menu `Product``Scheme``Manage Schemes...`, and check the `Shared Scheme` checkbox next to schemes that are part of the project. There is no need to do this for library schemes. Note the scheme you would like to use Detox with.
57-
* In your root folder, run `node_modules/detox/scripts/deploy_detox.rb <Path To>/YourProject.xcodeproj`.
58-
* Notice the new scheme(s) added in your Xcode project. If you had a `YourProject` scheme before, now there is an analogous `YourProject_Detox` scheme.
59-
* Make sure to add the new schema files to your source control (e.g. `git add ios/MyProject.xcodeproj/xcshareddata/xcschemes/Release_Detox.xcscheme`)
60-
61-
#### Step 4: Prepare the E2E Folder for Your Tests
54+
#### Step 3: Prepare the E2E Folder for Your Tests
6255

6356
* Create an `e2e` folder in your project root and open it.
6457
* Create `mocha.opts` file with this [content](demo-react-native/e2e/mocha.opts).
6558
* Create `init.js` file with this [content](demo-react-native/e2e/init.js).
6659
* Create your first test! `myFirstTest.spec.js` with content similar to [this](demo-react-native/e2e/example.spec.js).
6760

68-
#### Step 5: Build Your Project
61+
#### Step 4: Build Your Project
6962

70-
* Build your project with a newly created `_Detox` scheme:
63+
* Build your project with your scheme:
7164
* Building with Xcode.
72-
* Select the desired `_Detox` scheme.
65+
* Select the desired scheme.
7366
* Build your project.
7467
* Building from command-line:
75-
* `xcodebuild -scheme YourProject_Detox -sdk iphonesimulator -derivedDataPath build`
68+
* `xcodebuild -scheme YourProject -sdk iphonesimulator -derivedDataPath build`
7669
* Building using React Native
77-
* `react-native run-ios --scheme YourProject_Detox`
70+
* `react-native run-ios --scheme YourProject`
7871
* If you have build problems, see [troubleshooting](#troubleshooting-build-problems).
7972

80-
> Note: remember to update the path for `app` in your `package.json`.
73+
> Note: remember to update the `app` path in your `package.json`.
8174
82-
#### Step 6: Run Your Tests
75+
#### Step 5: Run Your Tests
8376

8477
* Follow [these instructions](RUNNING.md).
8578

86-
#### Step 7: Adding Additional Schemes
79+
#### Step 6: Adding Additional Schemes
8780

8881
You can add additional schemes to your project normally. After making changes to

demo-native-ios/e2e/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var detox = require('detox');
22
var config = require('../package.json').detox;
33

44
before(function (done) {
5-
this.timeout(40000);
5+
this.timeout(240000);
66
detox.config(config);
77
detox.start(done);
88
});

demo-native-ios/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"devDependencies": {
3-
"detox": "^4.0.9",
4-
"detox-server": "^1.1.0"
3+
"detox": "latest",
4+
"detox-server": "latest"
55
},
66
"scripts": {
77
"e2e": "./node_modules/.bin/mocha e2e --opts ./e2e/mocha.opts"
@@ -13,7 +13,7 @@
1313
},
1414
"ios-simulator": {
1515
"app": "Build/Products/Debug_Detox-iphonesimulator/NativeExample.app",
16-
"device": "iPhone 7, iOS 10.1"
16+
"device": "iPhone 7 Plus"
1717
}
1818
}
1919
}

detox/ios/Detox/DetoxManager.m

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
#import "DetoxManager.h"
10-
#import <dlfcn.h>
1110

1211
@interface DetoxManager()
1312

detox/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"publishConfig": {
55
"registry": "https://registry.npmjs.org/"
66
},
7-
"version": "4.0.13",
7+
"version": "4.1.0",
88
"bin": {
99
"detox": "./scripts/detox.js"
1010
},

detox/scripts/cleanup_4.0.rb

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'pathname'
4+
5+
#Setup require path to include local Xcodeproj and Nanaimo submodules
6+
$LOAD_PATH.unshift(__dir__ + "Xcodeproj/lib")
7+
$LOAD_PATH.unshift(__dir__ + "Nanaimo/lib")
8+
9+
require 'xcodeproj'
10+
11+
def usage()
12+
puts "Usage: cleanup_4.0.rb <path_to.xcodeproj>"
13+
end
14+
15+
if ARGV.count != 1 then
16+
usage
17+
exit
18+
end
19+
20+
project_path_str = ARGV[0].end_with?(".xcodeproj/") ? ARGV[0].chomp('/') : ARGV[0].end_with?(".xcodeproj") ? ARGV[0] : ARGV[0] + ".xcodeproj"
21+
project_path = Pathname.new(project_path_str).expand_path
22+
raise "Cannot find Xcode project" unless project_path.exist?
23+
24+
project_path_dir = project_path.dirname
25+
26+
puts "", "########################################", "Cleaning Project", "########################################", ""
27+
28+
project = Xcodeproj::Project.open(project_path)
29+
30+
configs_to_remove = project.build_configuration_list.build_configurations.select { |config| config.name.end_with?('_Detox') }
31+
project.build_configuration_list.build_configurations.delete(configs_to_remove)
32+
33+
project.targets.each { |target|
34+
configs_to_remove = target.build_configuration_list.build_configurations.select { |config| config.name.end_with?('_Detox') }
35+
target.build_configuration_list.build_configurations.delete(configs_to_remove)
36+
37+
shell_scripts_to_remove = target.shell_script_build_phases.select { |script| script.name.nil? == false and script.name.eql?("Copy Detox Framework") }
38+
target.shell_script_build_phases.delete(shell_scripts_to_remove)
39+
}
40+
41+
raise "Error: Unable to save Xcode project" unless project.save()
42+
43+
scheme_names = Xcodeproj::Project.schemes(project_path)
44+
45+
scheme_names.each do |scheme_name|
46+
next unless scheme_name.include?('_Detox')
47+
48+
FileUtils.rm_r(Xcodeproj::XCScheme.shared_data_dir(project_path) + "#{scheme_name}.xcscheme")
49+
end
50+
51+
puts "", "########################################", "Done", "########################################", ""

detox/scripts/deploy_detox.rb

-119
This file was deleted.

detox/src/ios/simulator.js

+52-4
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,16 @@ function _getBundleIdFromApp(appPath, onComplete) {
5151

5252
// fb simctl commands (we try to use it as much as possible since it supports multiple instances)
5353
function _executeSimulatorCommand(options, onComplete) {
54+
const frameworkPath = __dirname + "/../../Detox.framework/Detox";
55+
if(fs.existsSync(frameworkPath) === false)
56+
{
57+
throw new Error('Detox.framework not found at ' + frameworkPath)
58+
}
59+
5460
const fbsimctlPath = 'fbsimctl'; //By this point, it should already be installed on the system by brew.
55-
const cmd = fbsimctlPath + ' ' + options.args;
61+
const cmd = "export FBSIMCTL_CHILD_DYLD_INSERT_LIBRARIES=\"" + frameworkPath + "\" && " + fbsimctlPath + ' ' + options.args;
62+
// const cmd = "export FBSIMCTL_CHILD_DYLD_INSERT_LIBRARIES=\"" + frameworkPath + "\" && " + fbsimctlPath + ' ' + options.args;
63+
console.log(cmd);
5664
if (_verbose) {
5765
console.log(`DETOX exec: ${cmd}\n`);
5866
}
@@ -207,15 +215,15 @@ function _launchApp(device, appPath, onComplete) {
207215
});
208216
}
209217

210-
// ./node_modules/detox-tools/fbsimctl/fbsimctl relaunch org.reactjs.native.example.example
211-
function _relaunchApp(device, appPath, onComplete) {
218+
// fbsimctl terminate org.reactjs.native.example.example
219+
function _terminateApp(device, appPath, onComplete) {
212220
const query = _getQueryFromDevice(device);
213221
_getBundleIdFromApp(appPath, function (err, bundleId) {
214222
if (err) {
215223
onComplete(err);
216224
return;
217225
}
218-
const options = {args: `${query} relaunch ${bundleId} ${_defaultLaunchArgs.join(' ')}`};
226+
const options = {args: `${query} terminate ${bundleId}`};
219227
_executeSimulatorCommand(options, function (err2, stdout, stderr) {
220228
if (_verbose) {
221229
// in the future we'll allow expectations on logs and _listenOnAppLogfile will always run (remove if)
@@ -230,6 +238,46 @@ function _relaunchApp(device, appPath, onComplete) {
230238
});
231239
}
232240

241+
// ./node_modules/detox-tools/fbsimctl/fbsimctl relaunch org.reactjs.native.example.example
242+
function _relaunchApp(device, appPath, onComplete) {
243+
_terminateApp(device, appPath, function (err) {
244+
if (err) {
245+
onComplete(err);
246+
return;
247+
}
248+
_launchApp(device, appPath, function (err3) {
249+
if (err3) {
250+
onComplete(err3);
251+
return;
252+
}
253+
onComplete();
254+
});
255+
});
256+
257+
258+
// Calling `relaunch` is not good as it seems `fbsimctl` does not forward env variables in this mode.
259+
260+
// const query = _getQueryFromDevice(device);
261+
// _getBundleIdFromApp(appPath, function (err, bundleId) {
262+
// if (err) {
263+
// onComplete(err);
264+
// return;
265+
// }
266+
// const options = {args: `${query} relaunch ${bundleId} ${_defaultLaunchArgs.join(' ')}`};
267+
// _executeSimulatorCommand(options, function (err2, stdout, stderr) {
268+
// if (_verbose) {
269+
// // in the future we'll allow expectations on logs and _listenOnAppLogfile will always run (remove if)
270+
// _listenOnAppLogfile(_getAppLogfile(bundleId, stdout));
271+
// }
272+
// if (err2) {
273+
// onComplete(err2);
274+
// return;
275+
// }
276+
// onComplete();
277+
// });
278+
// });
279+
}
280+
233281
function relaunchApp(onComplete) {
234282
if (!_currentScheme.device) {
235283
onComplete(new Error(`scheme.device property is missing, should hold the device type we test on`));

0 commit comments

Comments
 (0)