Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Fixing clojurescript.test Failing with "ReferenceError: Can't find variable: cemerick"

DZone's Guide to

Fixing clojurescript.test Failing with "ReferenceError: Can't find variable: cemerick"

· Java Zone
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

ClojureScript.test (0.3.0; cemerick.cljs.test) may fail with this confusing exception:

ReferenceError: Can't find variable: cemerick

due to couple of reasons:

  1. Your test namespaces do not require cemerick.cljs.test (and thus it is missing from the compiled .js; requiring macros is not enough)
  2. cljsbuild has not included any of your test files (due to wrong setup etc.; this is essentially another form of #1)
  3. You are trying to test with the node runner but have built with :optimizations :none or :whitespace (for node you need to concatenate everything into a single file, which only happens if you use :simple or :advanced optimizations)

There is a pull request to provide a better error message but until then you have to be aware of these problems.

Example failures from all the runners:

Successfully compiled "target/cljs/testable.js" in 18.207 seconds.
Running ClojureScript test: rhino
js: "/var/folders/k0/2842tm752zv1dh4q77_gmgdr0000gn/T/rhino-runner8958189739208289289.js", line 50: uncaught JavaScript runtime exception: ReferenceError: "cemerick" is not defined.
at /var/folders/k0/2842tm752zv1dh4q77_gmgdr0000gn/T/rhino-runner8958189739208289289.js:50
Running ClojureScript test: node
/private/var/folders/k0/2842tm752zv1dh4q77_gmgdr0000gn/T/node-runner9185102801545573161.js:26
cemerick.cljs.test.set_print_fn_BANG_(function(x) {
^
ReferenceError: cemerick is not defined
at Object.<anonymous> (/private/var/folders/k0/2842tm752zv1dh4q77_gmgdr0000gn/T/node-runner9185102801545573161.js:26:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
Subprocess failed
Running ClojureScript test: phantom
ReferenceError: Can't find variable: cemerick
phantomjs://webpage.evaluate():2
phantomjs://webpage.evaluate():5
phantomjs://webpage.evaluate():5
ReferenceError: Can't find variable: cemerick
phantomjs://webpage.evaluate():2
phantomjs://webpage.evaluate():8
phantomjs://webpage.evaluate():8
# phantomjs freezes here

Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Published at DZone with permission of Jakub Holý, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}