-
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
Integration with jest
#143
Comments
Would love to see some documentation around it and an example, that would be cool 🎉 |
No real Wix-related objections with The only reason I waited with changing the defaults is because we don't have the runner requirements yet for running iOS and Android in parallel. For example, assume you want to mark some tests for iOS and some tests for Android. Maybe even use the RN convention of file extensions when you want to split behavior per platform. Once we have the requirements we'll need to see which runner supports them best and then we'll probably adopt it as the default Awesome stuff though! Blog post will be amazing! |
The main difference between runners like Mocha or AVA to Jest is that they don't an expectation library bundled inside, they are solely test runners. To sanely support Jest, and not confuse users, we would need to provide a way to control the the globals we export, maybe a different init function that doesn't do that, and let users import/require |
Hey there, I was able to setup Jest usage as well although it seemed a bit hacky. https://github.com/rangle/react-native-example/pull/19/files#diff-33b5654ffcc43d384eab9191d8b93768 |
@rotemmiz the way I did it so far is that, inside The benefit is that it's integrated testing environment and less dependencies to please my json |
@grabbou do you have an example? |
@samin I couldn't find the blog mentioned - but I did find a repository: https://github.com/grabbou/react-native-detox-example |
Maybe it would be even better to avoid integrated test runners at all? And instead: |
I am currently integrating detox onto a project right now; and everything worked great. The steps I took were: Updating the package.json file to add two entry points for running jest, for both unit and e2e tests separately: "scripts": {
// Splitting out 'test' for unit tests by default, and 'test-e2e' for detox
"test": "jest __tests__ --setupTestFrameworkScriptFile=./jest/setup-unit-tests.js",
"test-e2e": "jest __e2e__ --setupTestFrameworkScriptFile=./jest/setup-e2e-tests.js --bail",
},
// Nothing additional required here - added only for visibility
"jest": {
"preset": "react-native",
"transformIgnorePatterns": [
"node_modules/(?!react-native|tcomb-form-native|react-navigation)"
]
},
// Adding the detox config
"detox": {
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/example.app",
"build": "xcodebuild -project ios/example.xcodeproj -scheme example -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"name": "iPhone 7"
}
}
} The import detox from 'detox';
import packageFile from '../package.json';
const detoxConfig = packageFile.detox;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;
beforeAll(async () => {
await detox.init(detoxConfig);
});
afterAll(async () => {
await detox.cleanup();
});
beforeEach(async () => {
await device.reloadReactNative();
}); As well as dropping in a basic test within describe('Example', () => {
it('should have welcome screen', async () => {
await expect(element(by.id('welcome'))).toBeVisible();
});
}); That was everything required to get jest + detox working; Just kick it off with |
@AlanFoster yeah, I ended up not writing an article, but made an example in the repository. Also, I think that your example is similar to mine - happy to see we are both following in the right direction! @rotemmiz I would be happy to chat the requirements in order to get such integration working w/o any hacks - hit me up on Slack. |
How can I use the detox test --reuse command with jest? I don't want the app to be reinstalled each time but I don't know how to use this flag with jest |
@AlanFoster how to choose detox configuration? |
@stereodenis |
@isnifer it's for detox cli, but I wanted to know about jest |
@stereodenis I don't know how are you starting your tests with jest. // ...
import { omitBy } from 'lodash'
import pkg from '../../../package.json'
const {
PLATFORM = 'ios',
} = process.env
export default async function runnerDetox() {
const configurations = omitBy(pkg.detox.configurations, (value, key) => (
!key.startsWith(PLATFORM)
)
await detox.init({ configurations })
// ...
} My "detox": {
"configurations": {
"ios.sim.release": { ... },
"android.emu.release": { ... }
}
} Sure, you can create something like this |
Maybe a simple section in the doc to say that there is nothing special to do according to #143 (comment) (except of normal jest usage?) |
I would like to know the solution to the same problem as @IkerArb mentioned. Has anyone found yet? : ) |
@tengrobert @IkerArb the problem is that That line could be replaced by
That's the simplest without changing the code too much. Ideally, a global I don't have time to do a PR now, so feel free to submit one if everyone's happy either approach. |
jest-haste-map: watch error:
SyntaxError: Unexpected string in JSON at position 4089
at JSON.parse (<anonymous>)
at module.exports (app/node_modules/metro-bundler/node_modules/jest-haste-map/build/worker.js:65:29)
at Promise (app/node_modules/metro-bundler/node_modules/jest-haste-map/build/index.js:492:7)
at Promise (<anonymous>)
at _workerPromise.message (app/node_modules/metro-bundler/node_modules/jest-haste-map/build/index.js:491:7)
at HasteMap._processFile (app/node_modules/metro-bundler/node_modules/jest-haste-map/build/index.js:404:42)
at changeQueue.then (app/node_modules/metro-bundler/node_modules/jest-haste-map/build/index.js:705:32)
at <anonymous> anybody got this error? |
Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito
Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito
Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito
Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito
Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito
Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito
Closes #143 Heavily inspired by the solution of @AlanFoster and with the help of @levito
Is there a way to choose configuration when running tests with Jest? |
@sonianin Not yet documented, but you could use environment variables to set the config and choose the right config by filtering the list of configurations by it in the |
Hey,
Thanks for the library! I've managed to set it up with
jest
since that's the default runner in React Native.I was wondering whether:
a) we should use
jest
by default since it's default for React Native (might be tricky to integrate with Wix infrastructure)b) add an example to repo
c) write a blog post
I guess
c
will happen anyway tomorrow :)The text was updated successfully, but these errors were encountered: