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

Basic support for Jest runner #335

Merged
merged 20 commits into from
Oct 17, 2017
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
68 changes: 33 additions & 35 deletions detox/local-cli/detox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,42 @@ if (program.runner) {
runner = program.runner;
}

let command;
const {
configuration,
loglevel,
cleanup,
reuse,
debugSynchronization,
artifactsLocation
} = program;
function runMocha() {
const loglevel = program.loglevel ? `--loglevel ${program.loglevel}` : '';
const configuration = program.configuration ? `--configuration ${program.configuration}` : '';
const cleanup = program.cleanup ? `--cleanup` : '';
const reuse = program.reuse ? `--reuse` : '';
const artifactsLocation = program.artifactsLocation ? `--artifacts-location ${program.artifactsLocation}` : '';
const command = `node_modules/.bin/${program.runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${artifactsLocation}`;

console.log(command);
cp.execSync(command, {stdio: 'inherit'});
}

function runJest() {
const command = `node_modules/.bin/${runner} ${testFolder} --runInBand`;
console.log(command);
cp.execSync(command, {
stdio: 'inherit',
env: {
...process.env,
configuration: program.configuration,
loglevel: program.loglevel,
cleanup: program.cleanup,
reuse: program.reuse,
debugSynchronization: program.debugSynchronization,
artifactsLocation: program.artifactsLocation
}
});
}

switch (runner) {
case 'mocha':
const loglevel = program.loglevel ? `--loglevel ${program.loglevel}` : ''; +let runner = config.runner || 'mocha';
const configuration = program.configuration ? `--configuration ${program.configuration}` : '';
const cleanup = program.cleanup ? `--cleanup` : '';
const reuse = program.reuse ? `--reuse` : '';
const artifactsLocation = program.artifactsLocation ? `--artifacts-location ${program.artifactsLocation}` : '';
command = `node_modules/.bin/${program.runner} ${testFolder} --opts ${testFolder}/${program.runnerConfig} ${configuration} ${loglevel} ${cleanup} ${reuse} ${debugSynchronization} ${artifactsLocation}`;

console.log(command);
cp.execSync(command, { stdio: 'inherit' });
runMocha();
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 👍

runJest();
break;
case 'jest':
command = `node_modules/.bin/${runner} ${testFolder} --runInBand`;
console.log(command);
cp.execSync(command, {
stdio: 'inherit',
env: {
...process.env,
configuration,
loglevel,
cleanup,
reuse,
debugSynchronization,
artifactsLocation
}
});
break;
default:
default:
throw new Error(`${runner} is not supported in detox cli tools. You can still run your tests with the runner's own cli tool`);
}
8 changes: 4 additions & 4 deletions detox/test/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = J966JLDEF9;
INFOPLIST_FILE = example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Copy link
Contributor

Choose a reason for hiding this comment

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

Was that added in purpose?

Expand All @@ -992,7 +992,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = J966JLDEF9;
INFOPLIST_FILE = example/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -1010,7 +1010,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEAD_CODE_STRIPPING = NO;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = J966JLDEF9;
INFOPLIST_FILE = "$(SRCROOT)/example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -1027,7 +1027,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = J966JLDEF9;
INFOPLIST_FILE = "$(SRCROOT)/example/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down