Over a million developers have joined DZone.

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

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

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

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}