Skip to content
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

React-Hot-Loader: Hot Module Replacement is not enabled when running tests in jest #1259

Closed
nryoung opened this issue May 30, 2019 · 3 comments

Comments

@nryoung
Copy link

nryoung commented May 30, 2019

Description

React Hot Loader is reporting the following error when using the react-hot-loader/babel plugin and attempting to run tests with jest.

 PASS  src/App.test.jsx
  App
    ✓ renders (10ms)

  console.error node_modules/react-hot-loader/index.js:9
    React-Hot-Loader: Hot Module Replacement is not enabled

Expected behavior

When using the babel plugin it should not report this error when executing in the test context.

Actual behavior

See error above, it is still attempting to load react-hot-loader when running tests. The reason I know this is the babel plugin is because the error goes away when I remove the plugin from .babelrc.

Environment

React Hot Loader version: 4.8.3

Run these commands in the project folder and fill in their results:

  1. node -v: 10.15.3
  2. yarn -v: `1.15.2

Then, specify:

  1. Operating system: OS X 10.14.4

Reproducible Demo

App.jsx

import React from 'react';
import { hot } from 'react-hot-loader/root';

const App = () => (
 <div>Here is my app</div>
);

export default hot(App);

App.test.jsx

import React from 'react';
import { shallow } from 'enzyme';

import App from './App';

describe('App', () => {
  it('renders', () => {
    const wrapper = shallow(<App />);
    expect(wrapper).toMatchSnapshot();
  });
});

.babelrc

{
    "presets": ["@babel/preset-env", "@babel/preset-react"],
    "plugins": ["react-hot-loader/babel"]
}

package.json

{
  "scripts": {
    "test": "jest --color"
  }
}

jest.config.js

/* eslint-disable max-len */
process.env.BABEL_ENV = 'test'; // Make sure to load the appropriate babel plugins
process.env.NODE_ENV = 'test'; // set the proper node env

module.exports = {
  setupFilesAfterEnv: ['<rootDir>/scripts/setupTests.js'],
  snapshotSerializers: ['enzyme-to-json/serializer'],
  moduleDirectories: ['node_modules', 'src'],
};
@theKashey
Copy link
Collaborator

Duplicate of #1252
Your case was fixed in v4.8.8 - just update RHL

@nryoung
Copy link
Author

nryoung commented May 30, 2019

@theKashey Wow github search really failed me here. I search the closed issues multiple ways and did not find this one.

It works perfectly, thank you so much!

@theKashey
Copy link
Collaborator

Thank you for creating this issue, I've almost forgot to add final fix for #1252 to the upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants