From 3ce84eb6cc709cc3bc1d6e21b44f1681e1793659 Mon Sep 17 00:00:00 2001 From: Gage Date: Sat, 30 Mar 2019 15:23:06 -0600 Subject: [PATCH 1/3] Add Create React App Section, clarify tradeoffs Here's my second pass at the documentation for Create React App. Hopefully you like this better. --- README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 41fa6fd..4a767d3 100644 --- a/README.md +++ b/README.md @@ -63,15 +63,68 @@ Then add `__tests__` to `sources` in your `bsconfig.json`: ```js "sources": [ { - "dir": "src" + "dir": "src/app", + "subdirs": true }, { - "dir": "__tests__", - "type": "dev" + "dir": "src/__tests__", + "type": "dev", + "subdirs": true } ] ``` +Then your project structure would look like this: + +``` +src/ +├── app/ +│ ├── MyComponent.re +├── __tests__/ +│   ├── MyComponent_test.re + + +(NOTE: no .re files in the root of src, if you put them there they will not be built) +``` + +### For Create React App + + +> **⚠️ 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 +``` + +NOTE that the following is invalid, because putting extra dots in filenames is not a valid module name in OCaml ([files are modules](https://reasonml.github.io/docs/en/module#every-re-file-is-a-module)) + +``` +NOT VALID! DO NOT DO! + +src/ +├── MyComponent.re +├── MyComponent.test.re 👈🏻 ERROR! +``` + ## Usage Put tests in a `__tests__` directory and use the suffix `*test.ml`/`*test.re` (Make sure to use valid module names. e.g. `_test.re` is valid while `.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/). From e8372fae43febd84764c93cd4c173241dfc0478f Mon Sep 17 00:00:00 2001 From: Gage Date: Mon, 1 Apr 2019 14:01:23 -0600 Subject: [PATCH 2/3] Update README.md --- README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.md b/README.md index 4a767d3..d493f79 100644 --- a/README.md +++ b/README.md @@ -115,16 +115,6 @@ src/ │   ├── MyComponent_test.re ``` -NOTE that the following is invalid, because putting extra dots in filenames is not a valid module name in OCaml ([files are modules](https://reasonml.github.io/docs/en/module#every-re-file-is-a-module)) - -``` -NOT VALID! DO NOT DO! - -src/ -├── MyComponent.re -├── MyComponent.test.re 👈🏻 ERROR! -``` - ## Usage Put tests in a `__tests__` directory and use the suffix `*test.ml`/`*test.re` (Make sure to use valid module names. e.g. `_test.re` is valid while `.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/). From fabecadf8dfeeb947188ae6ebb3bb3c3a39b6b3d Mon Sep 17 00:00:00 2001 From: Gage Date: Mon, 1 Apr 2019 14:03:58 -0600 Subject: [PATCH 3/3] use root __tests__ directory --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d493f79..ba05fa2 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,11 @@ Then add `__tests__` to `sources` in your `bsconfig.json`: ```js "sources": [ { - "dir": "src/app", + "dir": "app", "subdirs": true }, { - "dir": "src/__tests__", + "dir": "__tests__", "type": "dev", "subdirs": true } @@ -78,10 +78,10 @@ Then your project structure would look like this: ``` src/ -├── app/ -│ ├── MyComponent.re -├── __tests__/ -│   ├── MyComponent_test.re +├── 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) @@ -113,6 +113,7 @@ src/ ├── MyComponent.re ├── __tests__ │   ├── MyComponent_test.re +README.md ``` ## Usage