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

Add Create React App Section, clarify tradeoffs #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,59 @@ Then add `__tests__` to `sources` in your `bsconfig.json`:
```js
"sources": [
{
"dir": "src"
"dir": "app",
Copy link
Owner

Choose a reason for hiding this comment

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

This should be "src", not "app"

"subdirs": true
Copy link
Owner

@glennsl glennsl Apr 3, 2019

Choose a reason for hiding this comment

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

Having this here is a bit opinionated I think, and kind of implies it's necessary for bs-jest to work, when it really isn't.

},
{
"dir": "__tests__",
"type": "dev"
"type": "dev",
"subdirs": true
}
]
```

Then your project structure would look like this:

```
src/
├── MyComponent.re
__tests__/
├── MyComponent_test.re
README.md


(NOTE: no .re files in the root of src, if you put them there they will not be built)
Copy link
Owner

Choose a reason for hiding this comment

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

This also seems unnecessary here as it's unrelated to the workings of bs-jest. It's good advice, but it should be included in the bucklescript docs instead.

```

### For Create React App
Copy link
Owner

Choose a reason for hiding this comment

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

I still don't see the content of this section as good advice. Why not recommend src/app instead, and avoid all the warnings and such?



> **⚠️ WARNING: ⚠️** The following You run the danger of having your test files be included in your production bundle if you (by acident) reference them anywhere in your code. Otherwise they should be shaken out by Webpack or whatever bundler you're using.
>
> **However, we strongly recomend to instead have two distinctly seperate folders for tests and application code** this allows the compiler to enforce that development-only files don't get built with production ones (in this case tests).


Create React App requires your tests to be in the `src` folder and encourages you tests next to their testing files. You _can_ do this with the following: `bsconfig.json`

```js
"sources": [
{
"dir": "src",
"subdirs": true
}
]
```

Then you would write put your tests in a folder like this:

```
src/
├── MyComponent.re
├── __tests__
│   ├── MyComponent_test.re
README.md
```

## Usage

Put tests in a `__tests__` directory and use the suffix `*test.ml`/`*test.re` (Make sure to use valid module names. e.g. `<name>_test.re` is valid while `<name>.test.re` is not). When compiled they will be put in a `__tests__` directory under `lib`, with a `*test.js` suffix, ready to be picked up when you run `jest`. If you're not already familiar with [Jest](https://github.com/facebook/jest), see [the Jest documentation](https://facebook.github.io/jest/).
Expand Down