First, thanks for the great testing framework!
I have seen @types/detox done for types but could not find anywhere how I can run ts files with Detox config? Tried using ts-jest as test-runner but says it's not supported. Do I have to manually transform typescript files to Javascript file before test? I looked everywhere in the documentation but could not anything.
@jinshin1013, unfortunately, this is not documented, but you could contribute to the knowledge base.
I assume you can examine these examples:
https://github.com/basarat/typescript-book/blob/master/docs/testing/jest.md
https://github.com/facebook/jest/tree/master/examples/typescript
Create a project with detox init -r jest, make sure you can run it, then try installing TypeScript, @types/detox and other required things according to the docs above. It won't work out of the box, of course, but you can see what are the errors and solve them step by step.
I'd appreciate if you summarize your findings as a pull request to the documentation.
I've successfully integrated Detox into a TS + RN + Jest project; for transpiling TS, I used ts-jest, there wasn't much setup otherwise (besides separating the typeRoots for the implementation code and the e2e tests, since I use Jest for my unit tests, and Detox overrides Jest's typedefs). Will document the process in the next few days
I've created https://github.com/solkaz/ts-detox-example as an example of adding TypeScript to your Detox tests
The trickiest part is ensuring that Detox's typings don't trample over Jest's, specifically for your unit tests. I solved this by putting all of my end-to-end tests in an e2e directory at my project's root directory, then configured my main tsconfig to not include the typings in e2e/node_modules/@types.
Briefly, the steps are as follows:
ts-jest and all necessary typings to your projectnpx ts-jest config:init to create jest.config.js (must be a .js file), then copy the setupTestFrameworkScriptFile over from config.json; then make this your runner-config in package.json.The only way is to create a nested project for e2e tests? typescript compiler still outputs TS2451: Cannot redeclare block-scoped variable 'expect'.
This is out of scope for this project. This should come as a community project.
Most helpful comment
I've created https://github.com/solkaz/ts-detox-example as an example of adding TypeScript to your Detox tests
The trickiest part is ensuring that Detox's typings don't trample over Jest's, specifically for your unit tests. I solved this by putting all of my end-to-end tests in an
e2edirectory at my project's root directory, then configured my maintsconfigto not include the typings ine2e/node_modules/@types.Briefly, the steps are as follows:
ts-jestand all necessary typings to your projectnpx ts-jest config:initto createjest.config.js(must be a.jsfile), then copy thesetupTestFrameworkScriptFileover fromconfig.json; then make this yourrunner-configinpackage.json.