-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Improvements in setup of jest runner. Update GettingStarted documentation. #329
Changes from 1 commit
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 |
---|---|---|
|
@@ -19,32 +19,39 @@ You should remove `e2e/mocha.opts`, you no longer need it. | |
### 3. Write a detox setup file | ||
|
||
```js | ||
// ./jest/setup/ | ||
const detox = require('detox'); | ||
const config = require('../package.json').detox; | ||
|
||
// Set the default timeout | ||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000; | ||
|
||
beforeAll(async () => { | ||
await detox.init(config); | ||
}); | ||
// setup detox only when running e2e tests | ||
if (process.argv[2].includes('__e2e__')) { | ||
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. This is not needed when we specify the setup files, which I think is a cleaner approach 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 thought about one file of setup for all environment (including unit tests). But we can run this file specifically for e2e tests as you mention :) |
||
beforeAll(async () => { | ||
await detox.init(config); | ||
}); | ||
|
||
afterAll(async () => { | ||
await detox.cleanup(); | ||
}); | ||
afterAll(async () => { | ||
await detox.cleanup(); | ||
}); | ||
|
||
// optional, you may remove this part | ||
beforeEach(async () => { | ||
await device.reloadReactNative(); | ||
}); | ||
beforeEach(async () => { | ||
await device.reloadReactNative(); | ||
}); | ||
} | ||
``` | ||
|
||
### 4. Run jest | ||
|
||
Add this part to your `package.json`: | ||
```json | ||
"jest": { | ||
"preset": "react-native", | ||
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. You don't need this jest config as we run on the build app 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. As above, I had in my mind to create a unified setup for unit and e2e but You are correct, for e2e test we do not need it :) |
||
"setupTestFrameworkScriptFile": "<rootDir>/jest/setup.js" | ||
}, | ||
"scripts": { | ||
"test:e2e": "jest e2e --setupTestFrameworkScriptFile=./jest/setup-e2e-tests.js --runInBand" | ||
"test:e2e": "detox build && jest __e2e__ --runInBand" | ||
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. The build part is left out because with |
||
} | ||
``` | ||
|
||
|
@@ -59,5 +66,5 @@ There are some things you should notice: | |
|
||
## How to run unit test and E2E tests in the same project | ||
|
||
- If you have a setup file for the unit tests pass it into jest by passing `--setupTestFrameworkScriptFile=./path/to/setup-unit-tests.js` to your jest unit test call. You need to remove this option from your `jest` configuration in the package.json. | ||
- Call your E2E tests like mentioned above | ||
- If you have a setup file for the unit tests pass `./jest/setup` implementation into your unit setup. | ||
- Call your E2E tests like mentioned above |
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 like this part 👍