|
7 | 7 | - [Undefined Set](#undefined-set)
|
8 | 8 | - [Using TheRubyRacer](#using-therubyracer)
|
9 | 9 | - [HMR](#hmr)
|
| 10 | +- [Tests in component directory](#tests-in-component-directory) |
10 | 11 |
|
11 | 12 | <!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
12 | 13 |
|
@@ -45,3 +46,20 @@ LibV8 itself is already [beyond version 7](https://github.com/cowboyd/libv8/rele
|
45 | 46 | Check out [Enabling Hot Module Replacement (HMR)](https://github.com/shakacode/shakapacker/blob/master/docs/react.md#enabling-hot-module-replacement-hmr) in Shakapacker documentation.
|
46 | 47 |
|
47 | 48 | One caveat is that currently you [cannot Server-Side Render along with HMR](https://github.com/reactjs/react-rails/issues/925#issuecomment-415469572).
|
| 49 | + |
| 50 | +## Tests in component directory |
| 51 | + |
| 52 | +If your tests for react components reside alongside the component files in the `app/javascript/components` directory, |
| 53 | +you will get `ModuleNotFoundError` in production environment |
| 54 | +since test libraries are devDependencies. |
| 55 | + |
| 56 | +To resolve this issue, |
| 57 | +you need to specify a matching pattern in `appllication.js` and `server_rendering.js`. |
| 58 | +For example, see the below code: |
| 59 | + |
| 60 | +```js |
| 61 | +// app/javascript/packs/application.js |
| 62 | +const componentRequireContext = require.context('react_rails_components', true, /^(?!.*\.test)^\.\/.*$/) |
| 63 | +const ReactRailsUJS = require('react_ujs') |
| 64 | +ReactRailsUJS.useContext(componentRequireContext) |
| 65 | +``` |
0 commit comments