You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
where component.test.jsx imports react-test-renderer.
Run:
export NODE_ENV=production RAILS_ENV=production
bundle install --deployment --quiet --without test development && yarn install --silent
bundle exec rails assets:precompile --silent
I get a ModuleNotFoundError in component.test.jsx because it cannot find react-test-renderer.
This makes sense to me because react-test-renderer is in my devDependencies and should not have been installed.
However, I have other components and related test files outside of the components directory that do not get this failure.
Removing the test file from components fixes the error. This seems easily resolved if I was able to set an ignore pattern for react-rails to ignore test files.
I have also encountered this problem. To avoid this, I passed in custom regexp torequire.context in application.js, and server_rendering.js. It uses a negative lookahead to skip test files like so:
The regexp is may look overly complicated, but it's based on the default ands needs to be able to match quite a few cases:
Must match for example:
./parentDirectory
./parentDirectory/
./parentDirectory/index
./parentDirectory/index.tsx
./parentDirectory/child
./parentDirectory/child/
./parentDirectory/child/index
./parentDirectory/child/index.ts
Should not match:
./parentDirectory/index.test.tsx
It should match the directories and files without the extension, as react-rails requires all these keys for react_component. Otherwise, a TypeError: Illegal constructor error will occur on page load.
A recommendation of mine would be to either update the readme.md to include this Gotcha, or we update the default in the generator.
I recently added react-rails to an existing project, and production builds are failing if there are Jest test files in the
/components
directory.Steps to reproduce
With the example structure:
where
component.test.jsx
importsreact-test-renderer
.Run:
I get a ModuleNotFoundError in component.test.jsx because it cannot find react-test-renderer.
This makes sense to me because react-test-renderer is in my
devDependencies
and should not have been installed.However, I have other components and related test files outside of the components directory that do not get this failure.
Removing the test file from
components
fixes the error. This seems easily resolved if I was able to set an ignore pattern for react-rails to ignore test files.Happy to provide more detail here.
System configuration
Sprockets or Webpacker version: Webpacker 4.3.0
React-Rails version: 2.6.1
Rect_UJS version: 2.6.0
Rails version: 5.2.1
Ruby version: 2.5.7
The text was updated successfully, but these errors were encountered: