meteor / todos

The example app "Todos", written following the Meteor Guide
Other
535 stars 367 forks source link

React unit test warnings #144

Closed shilman closed 6 years ago

shilman commented 8 years ago

When I run the react branch unit tests, I see the following error repeated three times (on MacOS El Capitan):

Unable to resolve some modules:

  "react/addons" in /Users/shilman/projects/meteor/todos/node_modules/enzyme/build/react-compat.js (os.osx.x86_64)
  "react/lib/ReactContext" in /Users/shilman/projects/meteor/todos/node_modules/enzyme/build/react-compat.js (os.osx.x86_64)
  "react/lib/ExecutionEnvironment" in /Users/shilman/projects/meteor/todos/node_modules/enzyme/build/react-compat.js (os.osx.x86_64)

If you notice problems related to these missing modules, consider running:

  meteor npm install --save react             

I believe they are caused by my pull request #141 but I'm not sure how to go about debugging this, and have already spent a few hours playing around with NPM and package versions.

Anybody have suggestions?

shilman commented 8 years ago

Possibly related: https://github.com/airbnb/enzyme/issues/47

You should be able to get around that error by just adding react/lib/ExecutionEnvironment to the list of externals.

This is a webpack configuration though -- don't know if it relates at all to NPM and/or Meteor...

tmeasday commented 8 years ago

I'd like to dig deeper into this one. As you've pointed out, it is just a warning so I'm not super concerned about it; however it would be good to get a better handle on these kind of warnings as there is often real, important information buried amongst the warnings.

martinhbramwell commented 8 years ago

I am also seeing this error while trying to use practicalmeteor:mocha with mantrajs/mantra-sample-blog-app.git. To replicate the problem, I do :

In Terminal 1 . . .

curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs

mkdir -p ~/projects
cd ~/projects
git clone https://github.com/mantrajs/mantra-sample-blog-app.git
cd mantra-sample-blog-app/
meteor npm install
meteor npm install --save meteor-node-stubs
meteor add practicalmeteor:mocha
meteor

Results in :

=> App running at: http://localhost:3000/

In Terminal 2 . . .

cd ~/projects/mantra-sample-blog-app
meteor test --driver-package practicalmeteor:mocha --port 3003

Results in :

=> App running at: http://localhost:3003/     
I20160605-06:58:57.784(-4)? MochaRunner.runServerTests: Starting server side tests with run id XYSDGsLJoWK37My5F
W20160605-06:58:57.785(-4)? (STDERR) MochaRunner.runServerTests: failures: 0

¡¡ However, since all tests are in directories named tests none are executed. !!

In Terminal 3 . . .

cd ~/projects/mantra-sample-blog-app
npm run testonly

Results in :

  53 passing (338ms)
  1 pending

To make it fail

In Terminal 3 . . .

mv ./client/modules/comments/components/tests ./client/modules/comments/components/mocha

In Terminal 1 . . .

Results in :

Unable to resolve some modules:

  "react/addons" in /home/yourself/projects/mantra-sample-blog-app/node_modules/enzyme/build/react-compat.js (web.browser)
  "react/lib/ReactContext" in /home/yourself/projects/mantra-sample-blog-app/node_modules/enzyme/build/react-compat.js (web.browser)
  "react/lib/ExecutionEnvironment" in /home/yourself/projects/mantra-sample-blog-app/node_modules/enzyme/build/react-compat.js (web.browser)

If you notice problems related to these missing modules, consider running:

  meteor npm install --save react             

Versions

you@yours:~$ npm --version
2.15.5
you@yours:~$ node --version
v4.4.5
you@yours:~$ meteor --version
Meteor 1.3.2.4
you@yours:~$ lsb_release -a
Distributor ID: Ubuntu
Description:  Ubuntu 16.04 LTS
Release:  16.04
Codename: xenial
you@yours:~$ 
tmeasday commented 8 years ago

Ok, reading up on this bug: https://github.com/airbnb/enzyme/issues/47 it seems like this is about Enzyme doing some conditional out of date requires for React < 15.

It's nothing to worry about, but it would be nice to remove the warning. @benjamn, any suggestions about whether there's any way to silence warnings about known missing conditionally require-ed modules?

In webpack-land the accepted solution seems to be externalizing those dependencies in your webpack config.

RobinVanCauter commented 7 years ago

Not sure what changed over the last couple of months, but pulling the react branch from this repo, installing npm dependencies and then running test-watch results in the console log included below(in the browser). The server console also shows the warning discussed in this issue.

The client side tests don't seem to run at all, so client-side testing is completely broken in the current state of the react branch.

When I remove the "import enzyme.. " line and the other enzyme references, the tests run without any issues.

So it seems this error is directly related to enzyme.

modules-runtime.js:459 Uncaught Error: Cannot find module 'crypto'
    at require (modules-runtime.js:119)
    at meteorInstall.node_modules.uuid.rng.js (modules.js:127395)
    at fileEvaluate (modules-runtime.js:191)
    at require (modules-runtime.js:116)
    at meteorInstall.node_modules.uuid.uuid.js (modules.js:127209)
    at fileEvaluate (modules-runtime.js:191)
    at require (modules-runtime.js:116)
    at meteorInstall.node_modules.enzyme.build.Utils.js (modules.js:84252)
    at fileEvaluate (modules-runtime.js:191)
    at require (modules-runtime.js:116)
RobinVanCauter commented 7 years ago

In case anyone is looking for a temporary solution, it seems a recent update of enzyme is what breaks the unit tests.

Version 2.4.1 works, version 2.7.1 breaks.

So setting the package.json entry to "=2.4.1" instead of "^2.4.1" fixes the unit tests.

jaqua commented 7 years ago

For me version 2.4.1 gives the same error...

hwillson commented 6 years ago

React todos has been updated to use the latest and greatest from both react and enzyme, so this is no longer an issue. Thanks!