Skip to content
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

Merged
merged 3 commits into from
Oct 11, 2017
Merged
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
33 changes: 20 additions & 13 deletions docs/Guide.Jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,39 @@ You should remove `e2e/mocha.opts`, you no longer need it.
### 3. Write a detox setup file

```js
// ./jest/setup/
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this part 👍

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__')) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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",
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
Copy link
Contributor

Choose a reason for hiding this comment

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

The build part is left out because with detox test it isn't included either, but adding something like test:e2e:build: "detox build" is a pretty neat idea!

}
```

Expand All @@ -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