Skip to content

Jest tests not allowed in components directory. #1095

Closed
@radglob

Description

@radglob

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:

app/javascript/components:
  component.jsx
  __tests__:
    component.test.jsx

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.

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions