-
Notifications
You must be signed in to change notification settings - Fork 61
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,15 +63,59 @@ Then add `__tests__` to `sources` in your `bsconfig.json`: | |
```js | ||
"sources": [ | ||
{ | ||
"dir": "src" | ||
"dir": "app", | ||
"subdirs": true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
|
||
> **⚠️ 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/). | ||
|
There was a problem hiding this comment.
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"