bensu / doo

doo is a library and lein plugin to run cljs.test on different js environments.
Eclipse Public License 1.0
324 stars 63 forks source link

Tests Fail to Run with Reagent 0.8.0 #178

Closed clartaq closed 6 years ago

clartaq commented 6 years ago

I'm having problems getting reagent/figwheel/doo-based projects to run tests. As near as I can tell, there is an incompatibility with Reagent 0.8.0.

This problem is present in "hand-built" projects or those generated from popular templates like reagent-figwheel or the reagent template. Using the reagent template, version 0.10.1, here is a transcript that shows the issue:

clartaq in ~/projects
$ lein new reagent x +test
Generating fresh 'lein new' Reagent project.
clartaq in ~/projects
$ cd x
clartaq in ~/projects/x
$ lein doo phantom test once

;; ======================================================================
;; Testing with Phantom:

ReferenceError: Can't find variable: Map

  phantomjs://code/phantom14578510775031716068.js:81 in onError
Subprocess failed
clartaq in ~/projects/x
$

Editing project.clj to downgrade to Reagent 0.7.0 and re-running the test produces the expected result:

clartaq in ~/projects/x
$ lein clean
clartaq in ~/projects/x
$ lein doo phantom test once

;; ======================================================================
;; Testing with Phantom:

Testing x.core-test

Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
clartaq in ~/projects/x
$

Even though the problem occurs when swapping the Reagent version, I'm reporting the issue here since doo flags the problem. When running the program with the dev or the production profiles, there are no issues, just when testing.

If you think the issue should be reported to the Reagent folks instead, just say so.

miikka commented 6 years ago

I think this happens because Reagent 0.8 depends on React 16 and Reagent 0.7 depends on React 15. React 16 uses Map and Set and I'm guessing that PhantomJS doesn't support them:

React 16 depends on the collection types Map and Set. If you support older browsers and devices which may not yet provide these natively (e.g. IE < 11), consider including a global polyfill in your bundled application, such as core-js or babel-polyfill.

I'm not immediately sure if there's something that doo can or should do. As a workaround, I'd probably use either babel-polyfill via cljsjs or use e.g. Headless Chrome as the JavaScript environment instead of PhantomJS.

clartaq commented 6 years ago

Well, that's sad. I hate to see a tool as popular as PhantomJS left behind. (Nashorn too apparently.)

I've switched to SlimerJS. That's working fine.

metametadata commented 6 years ago

It looks like Google Closure itself can polyfill Map by using :rewrite-polyfills compiler option. But I couldn't figure out how to make it fix the PhantomJS problem. I added these settings to :compiler:

:language-in       :es6
:language-out      :es3
:rewrite-polyfills true

And cljsjs/babel-polyfill doesn't seem to have Map in externals.

cloojure commented 5 years ago

I just tried this, but get an error since it appears slimerjs has not kept up with Firefox:

> node_modules/slimerjs/src/slimerjs  -v --debug=true
Error: Platform version '61.0.1' is not compatible with
minVersion >= 53.0.0
maxVersion <= 59.*
Gecko error: it seems /Applications/Firefox.app/Contents/MacOS/firefox is not compatible with SlimerJS.
See Gecko version compatibility. If version is correct, launch slimerjs
with --debug=true to see Firefox error message

However, I could get it running with any of the following:

lein doo chrome   test once
lein doo firefox  test once
lein doo safari   test once