rescript-jest icon indicating copy to clipboard operation
rescript-jest copied to clipboard

Add Create React App Section, clarify tradeoffs

Open justgage opened this issue 6 years ago • 3 comments

Here's my second pass at the documentation for Create React App. A better version of #49 hopefully 😅

justgage avatar Mar 30 '19 21:03 justgage

Coverage Status

Coverage remained the same at 97.978% when pulling fabecadf8dfeeb947188ae6ebb3bb3c3a39b6b3d on justgage:patch-2 into ad64578e005358382e4aa7957f0679e3293b2850 on glennsl:master.

coveralls avatar Mar 30 '19 21:03 coveralls

:wave: hey, I'm in the process of using create-react-app with bs-jest and i'd like to revisit/hash out issues i've personally faced.

i do agree with @glennsl's feedback - we include just the bare minimum required to get create-react-app working in this scenario.

Here are some of my high level questions:

Top level tests vs. src//tests**

To make sure we're on the same page, I have this in my bsconfig.json

{
  "dir": "__tests__",
  "type": "dev",
  "subdris": true
}
  • If I don't include a top level __tests__ folder, bs yells at me
  • If I don't put my tests in the top level __tests__ folder, open Jest can't be found.

Opinions aside, is this supposed to be the case? Do all my tests need to be in a top level test folder?

peterpme avatar Oct 11 '19 16:10 peterpme

Hi @peterpme :)

If I don't include a top level tests folder, bs yells at me

This seems like reasonable behaviour from bsb. It indicates there is a problem with your setup.

If I don't put my tests in the top level tests folder, open Jest can't be found.

I assume that's because you have bs-jest as a bs-dev-dependency, as you should, and the places you put your tests aren't in a source directory that has "type": "dev".

Do all my tests need to be in a top level test folder?

No, but they need to be in a folder marked as "type": "dev" in bsconfig.json. But from what I understand of CRA, they can't be in a top level folder because CRA runs jest in the src folder, not in the root folder. So I think you need something like this:

"sources": [{
  "dir": "src/app",
  "subdirs": true
}, {
  "dir": "src/__tests__",
  "type": "dev",
  "subdirs": true
}]

And then you have to put all the tests in src/__tests__.

It's also possible to have separate __tests__ folders alongside your app code, but then you ahve to turn off subdirs and list every folder explicitly in bsconfig.json, which is most likely not what you want.

glennsl avatar Oct 12 '19 16:10 glennsl