Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Support runner option in detox config
  • Loading branch information
Kureev committed Oct 15, 2017
commit 14d69659201319199918e6cf14327ded76028459
16 changes: 11 additions & 5 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const program = require('commander');
const path = require('path');
const cp = require('child_process');
program
.option('-r, --runner [runner]', 'Test runner (currently supports mocha)', 'mocha')
.option('-r, --runner [runner]', 'Test runner (currently supports mocha)')
.option('-o, --runner-config [config]', 'Test runner config file', 'mocha.opts')
.option('-l, --loglevel [value]', 'info, debug, verbose, silly, wss')
.option('-c, --configuration [device configuration]', 'Select a device configuration from your defined configurations,'
Expand All @@ -21,6 +21,12 @@ program
const config = require(path.join(process.cwd(), 'package.json')).detox;
const testFolder = config.specs || 'e2e';

let runner = config.runner || 'mocha';

if (program.runner) {
runner = program.runner;
}

let command;
const {
configuration,
Expand All @@ -31,15 +37,15 @@ const {
artifactsLocation,
} = program;

switch (program.runner) {
switch (runner) {
case 'mocha':
command = `node_modules/.bin/${program.runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig}`;
command = `node_modules/.bin/${runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig}`;
break;
case 'jest':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about passing detox command line args? Will those work?

Copy link
Contributor Author

@Kureev Kureev Oct 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can think of a way doing this. Although, in this version I wasn't aiming to provide this. If this is mandatory, we can discuss the approach

Sorry, misread your comment. What do you mean by "detox cli args"? Can you make an example?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is, the feature is not 100% usable without it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detox test --configuration ios.sim.release
detox test --loglevel verbose
detox test --debug-synchronization

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which flags are important?
In the previous version there were no recommendations regarding flags so kept it out of scope. However, I'm fine adding important flags to make jest support even better 💪 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rotemmiz what is the goal?

  • tests can access CLI arguments
    or
  • detox can access CLI arguments

If we talk about the second one, then it already works like this (commander parses arguments before passing them to test runner)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, but we execute a child process and these argument are not being passed into it.
cp.execSync(command, {stdio: 'inherit'});
We probably just need to pass them on...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, now I see. Indeed, we just need to pass arguments to the child process. Then there will be no point in passing all these flags in the command itself

Copy link
Contributor Author

@Kureev Kureev Oct 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like jest doesn't support allow custom CLI parameters. The only approach I see is to use environment vars.

Using ENV vars will imply changes on the mocha part and the way test cases gets parameters overall.

UPD: I can update argparse library and CLI so instead of additional flags it'll create one-time ENV variables. For user it'll be still the same, all mapping will happen under the hood.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea @Kureev, thank you so much for your efforts here 👍

command = `node_modules/.bin/${program.runner} ${testFolder} --runInBand`;
command = `node_modules/.bin/${runner} ${testFolder} --runInBand`;
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`);
throw new Error(`${runner} is not supported in detox cli tools. You can still run your tests with the runner's own cli tool`);
}

console.log(command);
Expand Down
4 changes: 2 additions & 2 deletions detox/test/e2e/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--recursive
--timeout 240000
--bail
--timeout 360000
--bail