3

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

 2 years ago
source link: https://blog.jakubholy.net/2014/05/21/fixing-clojurescript-test-failing-with-referenceerror-cant-find-variable-cemerick/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

May 21, 2014
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

Are you benefitting from my writing? Consider buying me a coffee or supporting my work via GitHub Sponsors. Thank you! You can also book me for a mentoring / pair-programming session via Codementor or (cheaper) email.

Allow me to write to you!

Let's get in touch! I will occasionally send you a short email with a few links to interesting stuff I found and with summaries of my new blog posts. Max 1-2 emails per month. I read and answer to all replies.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK