cemerick / clojurescript.test

A maximal port of `clojure.test` to ClojureScript. DEPRECATED
165 stars 32 forks source link

Running tests in a browser environment does not print report fail details #64

Closed symfrog closed 9 years ago

symfrog commented 10 years ago

I was struggling to get the detailed report to print on failure in both a full browser environment as well as a Rhino environment.

For example, invoking (run-all) in the following definition:

(ns cljscript.core-test
  (:require-macros [cemerick.cljs.test
                    :refer (is deftest with-test run-tests testing test-var)])
  (:require [cemerick.cljs.test :as t]))

(deftest dumb-test
     (is (empty? (filter even? (range 20)))))

(defn run-all [] (run-tests))

would only print the summary in the REPL:

{:test 1, :pass 0, :fail 1, :error 0}

In order to see the full report failure printed (enable-console-print!) must be called before running the tests. This will result in the following in the browser console (whereas nothing appears without the call):

Testing cljscript.core-test 

FAIL in (cljscript.core-test/dumb-test) (:)
expected: (empty? (filter even? (range 20))) 
  actual: (not (empty? (0 2 4 6 8 10 12 14 16 18))) 

Ran 1 tests containing 1 assertions.
Testing complete: 1 failures, 0 errors. 

Ran 1 tests containing 1 assertions.
Testing complete: 1 failures, 0 errors. 

So the definition would be:

(ns cljscript.core-test
  (:require-macros [cemerick.cljs.test
                    :refer (is deftest with-test run-tests testing test-var)])
  (:require [cemerick.cljs.test :as t]))

(deftest dumb-test
     (is (empty? (filter even? (range 20)))))

(defn run-all []
  (enable-console-print!)
  (run-tests))

In order to make it work in a Rhino environment use:

(set! *print-fn* (fn [& args] (.println java.lang.System.out (apply str args))))

instead of (enable-console-print!)

Hopefully this will help someone else that might encounter this issue.

cemerick commented 10 years ago

The intention (and current behaviour, at least in the environments I use regularly) is that the full output you quote should appear in the REPL, not in the browser console.

The Rhino test runner script does appear to set up the environment so that the output is complete in that context, e.g. https://travis-ci.org/cemerick/clojurescript.test/jobs/26449513#L266

It sounds like this might be a problem with the browser-REPL you're using, at least w.r.t. Rhino...

symfrog commented 10 years ago

I am using the following to start the server:

(cemerick.piggieback/cljs-repl :repl-env (cljs.repl.browser/repl-env :port 9000))

and

(clojure.browser.repl /connect "http://localhost:9000/repl")

to connect.

cemerick commented 9 years ago

Sorry for the troubles, but I've deprecated this project. Please see the notice at the top of the repo's README. This is a good thing, fundamentally. :-)