Eric,

There's a couple of things going on here:

 - Without explicit use of cljs.test/async, go blocks don't appear to be
executed within cljs.test/deftest bodies with the version of Clojurescript
you're using (1.7.48).  I don't know anything about this, or whether I'm
mischaracterizing the problem - only that I re-ran your code with 1.7.145,
and it behaves differently.
 - Regardless, cljs.test/async will need to be used to hold up test
completion until you're done inside the go block.  This won't matter much
when looking for print statements in a repl, but eventually you're going to
want to asynchronously fail the test and have it be reported correctly.

Something like this:

(deftest call-convert-with-exec
  (testing "trying to exec a simple cmd command"
    (let [ch (exec "ls -al")]
      (print "so far so good")
      (cljs.test/async
       done
       (go
         (<! ch)
         (print "end of go block")
         (done))))))

(Will work without bumping the Clojurescript version, but upgrading and
using cljs.test/async seems like the right move).

Take care,
Moe


On Sun, Oct 18, 2015 at 9:33 PM, Eric Chaves <[email protected]> wrote:

> Hi folks,
>
> I'm learning cljs targeting nodejs and for that I'm trying to write a
> simple captcha generator code that makes use of imagemagick. This is
> something that I had done before in "pure" nodejs so I figured that would
> be a good starting point.
> My sample code is using doo as test runner
>
> I'd like call node's "child_process" function and wait for it to finish,
> so I wrote the function below after some github surfing:
>
> ;; src/simple-aws-captcha/core.cljs
> (ns simple-aws-captcha.core
>   (:require [cljs-lambda.util :refer [async-lambda-fn]]
>             [cljs.nodejs :as node]
>             [cljs.core.async :as async])
>   (:require-macros [cljs.core.async.macros :refer [go]]))
>
> (defn exec [cmd]
>   (let [ch (async/chan)
>         ps (node/require "child_process")]
>     (.exec ps cmd (fn [err stdout]
>                     (if (nil? err)
>                       (async/put! ch stdout)
>                       (async/put! ch "error")
>                       )))
>     ch))
>
>
> And to test it I wrote the following TDD code:
>
> ;; test/simple-aws-captcha/core_test.cljs
>
> (ns simple-aws-captcha.core-test
>   (:require-macros [cljs.core.async.macros :refer [go alt!]])
>   (:require [cljs.test :refer-macros [deftest is testing async run-tests]]
>             [cljs.core.async :refer [>! <! chan put! take! timeout close!]]
>             [simple-aws-captcha.core :refer [get-code get-image exec]]))
>
> (enable-console-print!)
>
> (deftest call-convert-with-exec
>   (testing "trying to exec a simple cmd command"
>     (let [ch (exec "ls -al")]
>       (print "so far so good")
>       (go
>        (<! ch)
>        (print "end of go block")))))
>
> When I ran the tests the "so far so good" string is printed, but I never
> got the command result not the "end of go block".
>
> What am I doing wrong here?
>
> Thanks in advance,
>
> Eric
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to