Skip to content

Commit

Permalink
Supporting async testing, fixes gh-34:
Browse files Browse the repository at this point in the history
* all test-time dynamic bindings eliminated, replaced with reified test environment(s), atoms+maps
* moved fixtures-2 namespace to properly-named file
  • Loading branch information
cemerick committed Mar 17, 2014
1 parent 6e6b50d commit 72328e7
Show file tree
Hide file tree
Showing 12 changed files with 608 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@ pom.xml.asc
.classpath
.project
.settings
.nrepl-port

.externalToolBuilders
bin
Expand Down
51 changes: 30 additions & 21 deletions project.clj
Expand Up @@ -4,20 +4,19 @@
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:min-lein-version "2.0.0"
:test-paths ["target/generated/clj"]
:dependencies [[org.clojure/clojure "1.5.1"]
[org.clojure/clojurescript "0.0-2014"]]
[org.clojure/clojurescript "0.0-2138"]]

:plugins [[lein-cljsbuild "1.0.2"]]

:cljsbuild {:builds [{:source-paths ["src" "test"]
:cljsbuild {:builds [{:source-paths ["src" "test" "target/generated/cljs"]
:compiler {:output-to "target/cljs/whitespace.js"
:optimizations :whitespace
:pretty-print true}}
{:source-paths ["src" "test"]
{:source-paths ["src" "test" "target/generated/cljs"]
:compiler {:output-to "target/cljs/simple.js"
:optimizations :simple
:pretty-print true}}
{:source-paths ["src" "test"]
{:source-paths ["src" "test" "target/generated/cljs"]
:compiler {:output-to "target/cljs/advanced.js"
:optimizations :advanced
:pretty-print true}}]
Expand All @@ -34,13 +33,7 @@
"window.literal_js_was_evaluated=true"
"target/cljs/advanced.js"
"test/cemerick/cljs/test/extra_test_command_file.js"]

; Node.js tests
"node" ["node" :node-runner
"this.literal_js_was_evaluated=true"
"target/cljs/advanced.js"
"test/cemerick/cljs/test/extra_test_command_file.js"]


; Rhino tests
"rhino-whitespace" ["rhino" "-opt" "-1" :rhino-runner
"this.literal_js_was_evaluated=true"
Expand All @@ -55,19 +48,35 @@
"target/cljs/advanced.js"
"test/cemerick/cljs/test/extra_test_command_file.js"]

}}

:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
; node tests
"node-simple" ["node" :node-runner
"this.literal_js_was_evaluated=true"
"target/cljs/simple.js"
"test/cemerick/cljs/test/extra_test_command_file.js"]
"node-advanced" ["node" :node-runner
"this.literal_js_was_evaluated=true"
"target/cljs/advanced.js"
"test/cemerick/cljs/test/extra_test_command_file.js"]}}

:profiles {:latest {:dependencies [[org.clojure/clojure "1.6.0-RC1"]
[org.clojure/clojurescript "0.0-2156"]]
:plugins [[com.cemerick/austin "0.1.3"]]}
:cljx {:builds [{:source-paths ["test"]
:output-path "target/generated/clj"
:rules :clj}
{:source-paths ["test"]
:output-path "target/generated/cljs"
:rules :cljs}]}

:profiles {:latest {:dependencies [[org.clojure/clojure "1.6.0-alpha3"]
[org.clojure/clojurescript "0.0-2138"]]}
:dev {:dependencies [[org.clojure/core.async "0.1.267.0-0d7780-alpha"]]
:plugins [[lein-cljsbuild "1.0.1"]
[com.keminglabs/cljx "0.3.2"]
[com.cemerick/austin "0.1.4-SNAPSHOT"]]}
; self-reference and chained `lein install; lein test` invocation
; needed to use the project as its own plugin. Leiningen :-(
:self-plugin [:default {:plugins [[com.cemerick/clojurescript.test "0.2.3"]]}]}
:self-plugin [:default {:plugins [[com.cemerick/clojurescript.test "0.3.0-SNAPSHOT"]]}]}

:aliases {"cleantest" ["with-profile" "self-plugin:self-plugin,latest"
"do" "clean," "test," "cljsbuild" "test"]
"do" "clean," "cljx" "once," "test," "cljsbuild" "test"]
"release" ["do" "clean," "deploy" "clojars," "deploy" "releases"]}

:deploy-repositories {"releases" {:url "https://oss.sonatype.org/service/local/staging/deploy/maven2/" :creds :gpg}
Expand Down
6 changes: 3 additions & 3 deletions resources/cemerick/cljs/test/node_runner.js
Expand Up @@ -31,7 +31,7 @@ cemerick.cljs.test.set_print_fn_BANG_(function(x) {

var success = (function() {
var results = cemerick.cljs.test.run_all_tests();
return cemerick.cljs.test.successful_QMARK_(results);
cemerick.cljs.test.on_testing_complete(results, function () {
process.exit(cemerick.cljs.test.successful_QMARK_(results) ? 0 : 1);
});
})();

process.exit(success ? 0 : 1);
22 changes: 15 additions & 7 deletions resources/cemerick/cljs/test/runner.js
Expand Up @@ -25,11 +25,19 @@ p.evaluate(function () {
});
});

var success = p.evaluate(function () {
var results = cemerick.cljs.test.run_all_tests();
console.log(results);
return cemerick.cljs.test.successful_QMARK_(results);
});

phantom.exit(success ? 0 : 1);
// p.evaluate is sandboxed, can't ship closures across;
// so, a bit of a hack, better than polling :-P
var exitCodePrefix = "phantom-exit-code:";
p.onAlert = function (msg) {
var exit = msg.replace(exitCodePrefix, "");
if (msg != exit) phantom.exit(parseInt(exit));
};

p.evaluate(function (exitCodePrefix) {
var results = cemerick.cljs.test.run_all_tests();
//console.log(results);
cemerick.cljs.test.on_testing_complete(results, function () {
window.alert(exitCodePrefix +
(cemerick.cljs.test.successful_QMARK_(results) ? 0 : 1));
});
}, exitCodePrefix);

0 comments on commit 72328e7

Please sign in to comment.