Skip to content

Instantly share code, notes, and snippets.

@anmonteiro
Last active October 2, 2016 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anmonteiro/478fc609c297cfd1217ebb9890ceba08 to your computer and use it in GitHub Desktop.
Save anmonteiro/478fc609c297cfd1217ebb9890ceba08 to your computer and use it in GitHub Desktop.

Demo of the new "require outside NS" feature in ClojureScript

Given the following directory structure, where cljs.jar is a ClojureScript uberjar built from source (the feature is currently unreleased, follow these instructions and build the compiler with script/uberjar):

project
├─ src
│  └─ foo.cljs
└─ cljs.jar

and src/foo.cljs:

;; src/foo.cljs
(require '[clojure.test :refer [deftest is run-tests]])

(deftest failing-test
  (is false))

(run-tests)

Running the following will drop you into a ClojureScript Node.js REPL:

$ java -cp src:cljs.jar clojure.main -e "(require 'cljs.repl) (require 'cljs.repl.node) (cljs.repl/repl (cljs.repl.node/repl-env))"

Then simply (load-file "src/foo.cljs") and it'll be evaluated:

ClojureScript Node.js REPL server listening on 53518
To quit, type: :cljs/quit

cljs.user=> (load-file "src/foo.cljs")

Testing cljs.user

FAIL in (failing-test) (at .cljs_node_repl/cljs/test.js:432:14)
expected: false
  actual: false

Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
nil
cljs.user=>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment