Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added reuse option to CLI #105

Merged
merged 3 commits into from
Apr 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions detox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ You can choose to build your project in any of these ways...
detox test --configuration yourConfiguration
```

### Faster test runs with app reuse
By default the app is rmoved, reinstalled and launched before each run.
Starting fresh is critical in CI but in dev you might be able to save time between test runs and reuse the app that was previously installed in the simulator. To do so use the `reuse` flag and run your tests like this:`detox test --reuse`.
This is especially useful with React Native DEV mode when making Javascript code changes that are getting picked up by the packager (and thus no reinstall is needed). This can save up to 7 seconds per run!
You should not use this option if you made native code changes or if your app relies on local ("disk") storage.


## See it in Action

Expand Down
4 changes: 3 additions & 1 deletion detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ program
.option('-l, --loglevel [value]', 'info, debug, verbose, silly, wss')
.option('-c, --configuration [device configuration]', 'Select a device configuration from your defined configurations,'
+ 'if not supplied, and there\'s only one configuration, detox will default to it')
.option('-r, --reuse', 'Reuse existing installed app (do not delete and re-install) for a faster run.', false)
.option('-u, --cleanup', 'shutdown simulator when test is over, useful for CI scripts, to make sure detox exists cleanly with no residue', false)
.parse(process.argv);

Expand All @@ -18,11 +19,12 @@ const testFolder = config.specs || 'e2e';
const loglevel = program.loglevel ? `--loglevel ${program.loglevel}` : '';
const configuration = program.configuration ? `--configuration ${program.configuration}` : '';
const cleanup = program.cleanup ? `--cleanup` : '';
const reuse = program.reuse ? `--reuse` : '';

let command;
switch (program.runner) {
case 'mocha':
command = `node_modules/.bin/${program.runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig} ${configuration} ${loglevel} ${cleanup}`;
command = `node_modules/.bin/${program.runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig} ${configuration} ${loglevel} ${cleanup} ${reuse}`;
break;
default:
throw new Error(`${program.runner} is not supported in detox cli tools. You can still run your tests with the runner's own cli tool`);
Expand Down
5 changes: 3 additions & 2 deletions detox/src/devices/Simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const _ = require('lodash');
const IosNoneDevice = require('./IosNoneDevice');
const FBsimctl = require('./Fbsimctl');
const configuration = require('../configuration');
const argparse = require('../utils/argparse');

class Simulator extends IosNoneDevice {

Expand Down Expand Up @@ -51,8 +52,8 @@ class Simulator extends IosNoneDevice {
this._simulatorUdid = await this._fbsimctl.list(this._deviceConfig.name);
this._bundleId = await this._getBundleIdFromApp(this._deviceConfig.binaryPath);
await this._fbsimctl.boot(this._simulatorUdid);
await this.relaunchApp({delete: true});
}
await this.relaunchApp({delete: !argparse.getArgValue('reuse')});
}

async relaunchApp(params = {}, bundleId) {
if (params.url && params.userNotification) {
Expand Down
19 changes: 19 additions & 0 deletions detox/src/devices/Simulator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Simulator', () => {
let cpp;
let Simulator;
let simulator;
let argparse;

let Client;
let client;
Expand All @@ -23,6 +24,9 @@ describe('Simulator', () => {
jest.mock('./Fbsimctl');

jest.mock('../client/Client');
jest.mock('../utils/argparse');
argparse = require('../utils/argparse');

Client = require('../client/Client');

Simulator = require('./Simulator');
Expand Down Expand Up @@ -98,6 +102,21 @@ describe('Simulator', () => {
["-detoxServer", "ws://localhost:8099", "-detoxSessionId", "test"]);
});


it(`relaunchApp() without delete when reuse is enabled should not uninstall and install`, async() => {
simulator = validSimulator();
argparse.getArgValue.mockReturnValue(true);
fs.existsSync.mockReturnValue(true);

await simulator.relaunchApp();

expect(simulator._fbsimctl.uninstall).not.toHaveBeenCalled();
expect(simulator._fbsimctl.install).not.toHaveBeenCalled();
expect(simulator._fbsimctl.launch).toHaveBeenCalledWith(simulator._simulatorUdid,
simulator._bundleId,
["-detoxServer", "ws://localhost:8099", "-detoxSessionId", "test"]);
});

it(`relaunchApp() with url should send the url as a param in launchParams`, async() => {
simulator = validSimulator();
await simulator.relaunchApp({url: `scheme://some.url`});
Expand Down