-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Changes from 15 commits
d5d93cc
ba08fba
8bf5abd
bcb0174
9157bb0
efe3b39
c3c0077
92a1c49
14d6965
256af2b
afcfc0e
8fde423
8c9dc3b
8092625
dc45bc2
63b4519
35e0f65
3803b47
21690b8
5fcfa4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,39 @@ | ||
const _ = require('lodash'); | ||
jest.unmock('process'); | ||
|
||
describe('argparse', () => { | ||
let argparse; | ||
describe('using env variables', () => { | ||
let argparse; | ||
|
||
beforeEach(() => { | ||
jest.mock('minimist'); | ||
const minimist = require('minimist'); | ||
minimist.mockReturnValue({test: 'a value'}); | ||
argparse = require('./argparse'); | ||
}); | ||
beforeEach(() => { | ||
process.env.fooBar = 'a value'; | ||
argparse = require('./argparse'); | ||
}); | ||
|
||
it(`nonexistent key should return undefined result`, () => { | ||
expect(argparse.getArgValue('blah')).not.toBeDefined(); | ||
}); | ||
|
||
it(`nonexistent key should return undefined result`, () => { | ||
expect(argparse.getArgValue('blah')).not.toBeDefined(); | ||
it(`existing key should return a result`, () => { | ||
expect(argparse.getArgValue('foo-bar')).toBe('a value'); | ||
}); | ||
}); | ||
|
||
it(`existing key should return a result`, () => { | ||
expect(argparse.getArgValue('test')).toBe('a value'); | ||
describe('using arguments', () => { | ||
let argparse; | ||
|
||
beforeEach(() => { | ||
jest.mock('minimist'); | ||
const minimist = require('minimist'); | ||
minimist.mockReturnValue({'kebab-case-key': 'a value'}); | ||
argparse = require('./argparse'); | ||
}); | ||
|
||
it(`nonexistent key should return undefined result`, () => { | ||
expect(argparse.getArgValue('blah')).not.toBeDefined(); | ||
}); | ||
|
||
it(`existing key should return a result`, () => { | ||
expect(argparse.getArgValue('kebab-case-key')).toBe('a value'); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was that added in purpose? |
||
|
@@ -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"; | ||
|
@@ -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"; | ||
|
@@ -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"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,9 @@ npm install --save-dev jest | |
|
||
You should remove `e2e/mocha.opts`, you no longer need it. | ||
|
||
### 3. Write a detox setup file | ||
### 3. Replace generated detox setup file (e2e/init.js) | ||
|
||
```js | ||
// ./jest/setup/e2e.js | ||
const detox = require('detox'); | ||
const config = require('../package.json').detox; | ||
|
||
|
@@ -44,15 +43,15 @@ beforeEach(async () => { | |
Add this part to your `package.json`: | ||
```json | ||
"jest": { | ||
"setupTestFrameworkScriptFile": "<rootDir>/jest/setup.js" | ||
"setupTestFrameworkScriptFile": "./e2e/init.js" | ||
}, | ||
"scripts": { | ||
"test:e2e": "jest __e2e__ --setupTestFrameworkScriptFile=./jest/setup/e2e-tests.js --runInBand", | ||
"test:e2e": "detox test", | ||
"test:e2e:build": "detox build" | ||
} | ||
``` | ||
|
||
We need the `--runInBand` as detox doesn't support parallelism yet. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will running without the flag run tests serially? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added the flag here so if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is stopping detox from parallelism? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a few things, mainly controlling multiple simulators. It's in our roadmap, shouldn't be too hard. |
||
In the `detox` part of your `package.json`, add `"runner": "jest"` to tell detox that you want to use jest runner instead of mocha. | ||
|
||
### Writing Tests | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 approachSorry, misread your comment. What do you mean by "detox cli args"? Can you make an example?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 💪 .
There was a problem hiding this comment.
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?
or
If we talk about the second one, then it already works like this (commander parses arguments before passing them to test runner)
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 👍