Howto automate tests w/ ClojusreScript?

171 views
Skip to first unread message

Timothy Washington

unread,
Aug 8, 2011, 10:28:14 PM8/8/11
to clo...@googlegroups.com

Hey all, 


I'm digging into ClojureScript at the moment, and am trying to figure out how to automate generated JS code in a shell, like v8. 


In ClojureScript, I have been able to to pull in Google Closure's "goog.testing.jsunit" package. Next step is to take the generated JS code (optimized or not), and be able to automate tests in a JS shell, like v8, SpiderMonkey, rhino, etc. This is where I run into problems. In the directory in which I ran "cljs", I run v8, then load "out/goog/base.js" (analogous to what you'd do in a browser). "bkeeping.js" is generated from "bkeeping.cljs". goog.require breaks at first, until I try it with fubar'd namespace. Then I retry goog.require, and it works. However, I don't see the results of the unit test run. 


Any ideas of what I'm missing?


Thanks for any help 

Tim 



OUTPUT

webkell@ubuntu:~/Projects/bkell/test/cljs$ cljsc bkeeping.cljs > bkeeping.js 

webkell@ubuntu:~/Projects/bkell/test/cljs$ v8

V8 version 3.5.3

> load('out/goog/base.js'); 

> load('bkeeping.js'); 



> goog.require("bkeeping"); 

out/goog/base.js:517: Error: Undefined nameToPath for goog.string

            throw Error('Undefined nameToPath for ' + requireName);

                  ^

Error: Undefined nameToPath for goog.string

    at Error (unknown source)

    at visitNode (out/goog/base.js:517:19)

    at visitNode (out/goog/base.js:512:13)

    at Object.writeScripts_ (out/goog/base.js:530:9)

    at Object.require (out/goog/base.js:280:12)

    at (shell):1:6


… 


> goog.require("xx");

out/goog/base.js:287: Error: goog.require could not find: xx

        throw Error(errorMessage);

              ^

Error: goog.require could not find: xx

    at Error (unknown source)

    at Object.require (out/goog/base.js:287:15)

    at (shell):1:6

>         

> 

> goog.require("bkeeping");



Source "bkeeping.cljs" 

(ns bkeeping

  (:require [goog.testing.jsunit :as testing]))

  


;;(defn ^:export run-tests [] 

(defn run-tests []  

  

  (testing/assertFalse false, "PASSED falsity")

  (testing/assertTrue true, "PASSED truthiness")

)


(run-tests)


Timothy Washington

unread,
Aug 8, 2011, 11:05:16 PM8/8/11
to clo...@googlegroups.com
Sorry, I should have been clearer. 

In a JS shell (v8, for example), after running... load('bkeeping.js'); , I expect to have a bkeeping object. But that's not there. So I tried a goog.require('bkeeping.js'); , and a 'bkeeping' object still wasn't there. 

Basically, I'd like to able to run compiled JS code in a JS shell. But I'm coming up short (with and without compiler optimizations) in v8, rhino and SpiderMonkey. 

Any ideas? 

Tim Washington 

Brenton

unread,
Aug 9, 2011, 12:39:32 AM8/9/11
to Clojure
> load('out/goog/base.js');
> load('bkeeping.js');

This should be:

load('out/goog/base.js');
load('out/goog/deps.js');
load('bkeeping.js');


On Aug 8, 11:05 pm, Timothy Washington <twash...@gmail.com> wrote:
> Sorry, I should have been clearer.
>
> In a JS shell (v8, for example), after running... *load('bkeeping.js');* , I
> expect to have a *bkeeping* object. But that's not there. So I tried a *
> goog.require('bkeeping.js');* , and a '*bkeeping*' object still wasn't
> there.
>
> Basically, I'd like to able to run compiled JS code in a JS shell. But I'm
> coming up short (with and without compiler optimizations) in v8, rhino and
> SpiderMonkey.
>
> Any ideas?
>
> Tim Washington
> twash...@gmail.com
> 416.843.9060
>
> On Mon, Aug 8, 2011 at 10:28 PM, Timothy Washington <twash...@gmail.com>wrote:
>
>
>
>
>
>
>
> > Hey all,
>
> > I'm digging into ClojureScript at the moment, and am trying to figure out
> > how to automate generated JS code in a shell, like v8.
>
> > In ClojureScript, I have been able to to pull in Google Closure's "*
> > goog.testing.jsunit*" package. Next step is to take the generated JS code
> > (optimized or not), and be able to automate tests in a JS shell, like v8,
> > SpiderMonkey, rhino, etc. This is where I run into problems. In the
> > directory in which I ran "cljs", I run v8, then load "*out/goog/base.js*"
> > (analogous to what you'd do in a browser). "*bkeeping.js*" is generated
> > from "*bkeeping.cljs*". goog.require breaks at first, until I try it with
> > fubar'd namespace. Then I retry goog.require, and it works. However, I don't
> > see the results of the unit test run.
>
> > Any ideas of what I'm missing?
>
> > Thanks for any help
>
> > Tim
>
> > *OUTPUT*
>
> > webkell@ubuntu:~/Projects/bkell/test/cljs$ cljsc bkeeping.cljs >
> > bkeeping.js
>
> > webkell@ubuntu:~/Projects/bkell/test/cljs$ v8
>
> > V8 version 3.5.3
>
> > > load('out/goog/base.js');
>
> > > load('bkeeping.js');
>
> > …
>
> > *
> > *
>
> > *> goog.require("bkeeping"); *
>
> > *out/goog/base.js:517: Error: Undefined nameToPath for goog.string*
>
> > *            throw Error('Undefined nameToPath for ' + requireName);*
>
> > *                  ^*
>
> > *Error: Undefined nameToPath for goog.string*
>
> > *    at Error (unknown source)*
>
> > *    at visitNode (out/goog/base.js:517:19)*
>
> > *    at visitNode (out/goog/base.js:512:13)*
>
> > *    at Object.writeScripts_ (out/goog/base.js:530:9)*
>
> > *    at Object.require (out/goog/base.js:280:12)*
>
> > *    at (shell):1:6*
>
> > …
>
> > > goog.require("xx");
>
> > out/goog/base.js:287: Error: goog.require could not find: xx
>
> >         throw Error(errorMessage);
>
> >               ^
>
> > Error: goog.require could not find: xx
>
> >     at Error (unknown source)
>
> >     at Object.require (out/goog/base.js:287:15)
>
> >     at (shell):1:6
>
> > *> goog.require("bkeeping");*
>
> > *Source "bkeeping.cljs" *

Timothy Washington

unread,
Aug 9, 2011, 8:30:38 AM8/9/11
to clo...@googlegroups.com
Hmm, I tried this with a v8 shell, and I still get...

> load('out/goog/base.js');
> load('out/goog/deps.js');
> load('bkeeping.js');
> bkeeping.fubar("thing");

(shell):1: ReferenceError: bkeeping is not defined
bkeeping.fubar("thing");
^


Where "cat bkeeping.cljs" gives...

(ns bkeeping
  (:require [goog.testing.jsunit :as testing]))
  
(defn ^:export fubar [n] 
  (str "ZZzz: " n)
)


Tim 
Reply all
Reply to author
Forward
0 new messages