Skip to content

Commit

Permalink
Changes to how Detox is injected.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoNatan committed Jan 17, 2017
1 parent af50e01 commit 99e5a89
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 158 deletions.
31 changes: 12 additions & 19 deletions INSTALLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

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

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

#### Step 1: Prerequisites

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

#### Step 3: Integrate Detox in Your Project

* 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.
* In your root folder, run `node_modules/detox/scripts/deploy_detox.rb <Path To>/YourProject.xcodeproj`.
* 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.
* Make sure to add the new schema files to your source control (e.g. `git add ios/MyProject.xcodeproj/xcshareddata/xcschemes/Release_Detox.xcscheme`)

#### Step 4: Prepare the E2E Folder for Your Tests
#### Step 3: Prepare the E2E Folder for Your Tests

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

#### Step 5: Build Your Project
#### Step 4: Build Your Project

* Build your project with a newly created `_Detox` scheme:
* Build your project with your scheme:
* Building with Xcode.
* Select the desired `_Detox` scheme.
* Select the desired scheme.
* Build your project.
* Building from command-line:
* `xcodebuild -scheme YourProject_Detox -sdk iphonesimulator -derivedDataPath build`
* `xcodebuild -scheme YourProject -sdk iphonesimulator -derivedDataPath build`
* Building using React Native
* `react-native run-ios --scheme YourProject_Detox`
* `react-native run-ios --scheme YourProject`
* If you have build problems, see [troubleshooting](#troubleshooting-build-problems).

> Note: remember to update the path for `app` in your `package.json`.
> Note: remember to update the `app` path in your `package.json`.
#### Step 6: Run Your Tests
#### Step 5: Run Your Tests

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

#### Step 7: Adding Additional Schemes
#### Step 6: Adding Additional Schemes

You can add additional schemes to your project normally. After making changes to
2 changes: 1 addition & 1 deletion demo-native-ios/e2e/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var detox = require('detox');
var config = require('../package.json').detox;

before(function (done) {
this.timeout(40000);
this.timeout(240000);
detox.config(config);
detox.start(done);
});
Expand Down
6 changes: 3 additions & 3 deletions demo-native-ios/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"detox": "^4.0.9",
"detox-server": "^1.1.0"
"detox": "latest",
"detox-server": "latest"
},
"scripts": {
"e2e": "./node_modules/.bin/mocha e2e --opts ./e2e/mocha.opts"
Expand All @@ -13,7 +13,7 @@
},
"ios-simulator": {
"app": "Build/Products/Debug_Detox-iphonesimulator/NativeExample.app",
"device": "iPhone 7, iOS 10.1"
"device": "iPhone 7 Plus"
}
}
}
1 change: 0 additions & 1 deletion detox/ios/Detox/DetoxManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "DetoxManager.h"
#import <dlfcn.h>

@interface DetoxManager()

Expand Down
2 changes: 1 addition & 1 deletion detox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"publishConfig": {
"registry": "https://registry.npmjs.org/"
},
"version": "4.0.13",
"version": "4.1.0",
"bin": {
"detox": "./scripts/detox.js"
},
Expand Down
51 changes: 51 additions & 0 deletions detox/scripts/cleanup_4.0.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env ruby

require 'pathname'

#Setup require path to include local Xcodeproj and Nanaimo submodules
$LOAD_PATH.unshift(__dir__ + "Xcodeproj/lib")
$LOAD_PATH.unshift(__dir__ + "Nanaimo/lib")

require 'xcodeproj'

def usage()
puts "Usage: cleanup_4.0.rb <path_to.xcodeproj>"
end

if ARGV.count != 1 then
usage
exit
end

project_path_str = ARGV[0].end_with?(".xcodeproj/") ? ARGV[0].chomp('/') : ARGV[0].end_with?(".xcodeproj") ? ARGV[0] : ARGV[0] + ".xcodeproj"
project_path = Pathname.new(project_path_str).expand_path
raise "Cannot find Xcode project" unless project_path.exist?

project_path_dir = project_path.dirname

puts "", "########################################", "Cleaning Project", "########################################", ""

project = Xcodeproj::Project.open(project_path)

configs_to_remove = project.build_configuration_list.build_configurations.select { |config| config.name.end_with?('_Detox') }
project.build_configuration_list.build_configurations.delete(configs_to_remove)

project.targets.each { |target|
configs_to_remove = target.build_configuration_list.build_configurations.select { |config| config.name.end_with?('_Detox') }
target.build_configuration_list.build_configurations.delete(configs_to_remove)

shell_scripts_to_remove = target.shell_script_build_phases.select { |script| script.name.nil? == false and script.name.eql?("Copy Detox Framework") }
target.shell_script_build_phases.delete(shell_scripts_to_remove)
}

raise "Error: Unable to save Xcode project" unless project.save()

scheme_names = Xcodeproj::Project.schemes(project_path)

scheme_names.each do |scheme_name|
next unless scheme_name.include?('_Detox')

FileUtils.rm_r(Xcodeproj::XCScheme.shared_data_dir(project_path) + "#{scheme_name}.xcscheme")
end

puts "", "########################################", "Done", "########################################", ""
119 changes: 0 additions & 119 deletions detox/scripts/deploy_detox.rb

This file was deleted.

56 changes: 52 additions & 4 deletions detox/src/ios/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,16 @@ function _getBundleIdFromApp(appPath, onComplete) {

// fb simctl commands (we try to use it as much as possible since it supports multiple instances)
function _executeSimulatorCommand(options, onComplete) {
const frameworkPath = __dirname + "/../../Detox.framework/Detox";
if(fs.existsSync(frameworkPath) === false)
{
throw new Error('Detox.framework not found at ' + frameworkPath)
}

const fbsimctlPath = 'fbsimctl'; //By this point, it should already be installed on the system by brew.
const cmd = fbsimctlPath + ' ' + options.args;
const cmd = "export FBSIMCTL_CHILD_DYLD_INSERT_LIBRARIES=\"" + frameworkPath + "\" && " + fbsimctlPath + ' ' + options.args;
// const cmd = "export FBSIMCTL_CHILD_DYLD_INSERT_LIBRARIES=\"" + frameworkPath + "\" && " + fbsimctlPath + ' ' + options.args;
console.log(cmd);
if (_verbose) {
console.log(`DETOX exec: ${cmd}\n`);
}
Expand Down Expand Up @@ -207,15 +215,15 @@ function _launchApp(device, appPath, onComplete) {
});
}

// ./node_modules/detox-tools/fbsimctl/fbsimctl relaunch org.reactjs.native.example.example
function _relaunchApp(device, appPath, onComplete) {
// fbsimctl terminate org.reactjs.native.example.example
function _terminateApp(device, appPath, onComplete) {
const query = _getQueryFromDevice(device);
_getBundleIdFromApp(appPath, function (err, bundleId) {
if (err) {
onComplete(err);
return;
}
const options = {args: `${query} relaunch ${bundleId} ${_defaultLaunchArgs.join(' ')}`};
const options = {args: `${query} terminate ${bundleId}`};
_executeSimulatorCommand(options, function (err2, stdout, stderr) {
if (_verbose) {
// in the future we'll allow expectations on logs and _listenOnAppLogfile will always run (remove if)
Expand All @@ -230,6 +238,46 @@ function _relaunchApp(device, appPath, onComplete) {
});
}

// ./node_modules/detox-tools/fbsimctl/fbsimctl relaunch org.reactjs.native.example.example
function _relaunchApp(device, appPath, onComplete) {
_terminateApp(device, appPath, function (err) {
if (err) {
onComplete(err);
return;
}
_launchApp(device, appPath, function (err3) {
if (err3) {
onComplete(err3);
return;
}
onComplete();
});
});


// Calling `relaunch` is not good as it seems `fbsimctl` does not forward env variables in this mode.

// const query = _getQueryFromDevice(device);
// _getBundleIdFromApp(appPath, function (err, bundleId) {
// if (err) {
// onComplete(err);
// return;
// }
// const options = {args: `${query} relaunch ${bundleId} ${_defaultLaunchArgs.join(' ')}`};
// _executeSimulatorCommand(options, function (err2, stdout, stderr) {
// if (_verbose) {
// // in the future we'll allow expectations on logs and _listenOnAppLogfile will always run (remove if)
// _listenOnAppLogfile(_getAppLogfile(bundleId, stdout));
// }
// if (err2) {
// onComplete(err2);
// return;
// }
// onComplete();
// });
// });
}

function relaunchApp(onComplete) {
if (!_currentScheme.device) {
onComplete(new Error(`scheme.device property is missing, should hold the device type we test on`));
Expand Down
Loading

0 comments on commit 99e5a89

Please sign in to comment.