Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

cljs.test reports using do-report, which adds file and line information computed from javascript stack traces. In chrome at least, these stack traces are not useful:


at http://localhost:3449/js/cljs/test.js:261:69
at cljs$test$do_report (http://localhost:3449/js/cljs/test.js:268:3)
at http://localhost:3449/js/test/test_tests.js:491:21
at test.test_tests.test_has_fails.cljs$lang$test (http://localhost:3449/js/test/test_tests.js:502:4)
at http://localhost:3449/js/cljs/test.js:384:42
at http://localhost:3449/js/cljs/test.js:387:4
at cljs$test$run_block (http://localhost:3449/js/cljs/test.js:320:13)


The file-and-line stack trace parser doesn't parse this correctly, resulting in a message like this:

FAIL in (test-function) (at http:384:42)

Note the lack of a useful file/namespace reference, and that the line number refers to the compiled javascript rather than the source clojurescript.

3 Answers

0 votes
_Comment made by: sfnelson_

Prior to the release of cljs.test my company maintained an internal port of clojure.test that did better reporting than cljs.test's by adding source metadata from {{&form}} to the {{do-report}} calls generated by {{assert-expr}}. This approach was great for internal use but might not be suitable for cljs.test as it could reduce portability of {{assert-expr}} between clojure and clojurescript. Another approach could be dynamically bind source metadata in the body generated by {{try-expr}}. I'd be willing to implement and contribute code if you can provide some indication of your preferred approach.

Our version of {{assert-expr}} also injected a 'reporter function', {{(function(a,b,c){a.apply(b.c)})}}, which we would invoke from report, e.g. {{(reporter (.-debug js/console) js/console args)}}. This causes the clickable link on the right hand side of chrome's console output to link to the source map location of the test expression, rather than the report function.
0 votes

Comment made by: dnolen

The correct thing to do here is to move the browser REPL stacktrace parsing into a shared library i.e. {{.cljc}} that can be loaded into either environment to handle browser difference.

0 votes
Reference: https://clojure.atlassian.net/browse/CLJS-1255 (reported by alex+import)