Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Discover and run your ClojureScript tests

License

NotificationsYou must be signed in to change notification settings

Olical/cljs-test-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Run all of yourClojureScript tests with one simple command.

Inspired by Cognitect'stest-runner forClojure, it isdesigned to be used in conjunction with the Clojure CLI tool and adeps.ednfile.

Under the hood it's building a test runner file, compiling everything and thenexecuting the compiled tests withdoo (usingingesolvoll's fork). Discovery of test namespaces is automatic, sono configuration is required.

Usage

In simple cases, you'll be able to execute your tests with something as succinctas the following line.

$ clojure -Sdeps'{:deps {olical/cljs-test-runner {:mvn/version "3.8.1"}}}' -m cljs-test-runner.main

Note: The generated test code is placed in the directorycljs-test-runner-out by default (configure with--out), you should addthat to your.gitignore file.

It's likely that your tests will require dependencies and configuration thatwould become unwieldy in this format. You will need to add the dependency and--main (-m) parameter to yourdeps.edn file.

I recommend you put this under an alias such astest orcljs-test if that'salready taken by your Clojure tests.

{:deps {org.clojure/clojure {:mvn/version"1.10.1"}        org.clojure/clojurescript {:mvn/version"1.10.520"}}:aliases {:test {:extra-deps {olical/cljs-test-runner {:mvn/version"3.8.1"}}:main-opts ["-m""cljs-test-runner.main"]}}}

The following will then find, compile and execute your tests throughnode.

$ clojure -AtestTesting example.partial-testTesting example.yes-testRan 2 tests containing 2 assertions.0 failures, 0 errors.

Configuration

You can configure the test runner with a few different flags, the most importantone is--env (-x) which allows you to swap from node tophantomor chrome-headless if required. I would recommend sticking to node and usingsomething likejsdom, but this does come down to preference andtechnical requirements.

$ clojure -Atest -x phantom

If you need to useforeign-libs or any cljs compiler flags that are notmirrored in cljs-test-runner's flags, you can put them into an EDN file andpoint to that file using the--compile-opts flag.

You can use--help to see the current flags and their default values.

$ clojure -Atest --help  -d, --dir DIRNAMEtest                  The directory containing yourtest files  -n, --namespace SYMBOL                             Symbol indicating a specific namespace to test.  -r, --namespace-regex REGEX  .*\-test$             Regexfornamespaces to test. Only namespaces endingin'-test' are evaluated by default.  -v, --var SYMBOL                                   Symbol indicating the fully qualified name of a specific test.  -i, --include SYMBOL                               Run only tests that have this metadata keyword.  -e, --exclude SYMBOL                               Exclude tests with this metadata keyword.  -o, --out DIRNAME            cljs-test-runner-out  The output directoryfor compiledtest code  -x, --env ENV                node                  Run your testsin node, phantom, chrome-headless, lumo or planck.  -w, --watch DIRNAME                                Directory to watchfor changes (alongside thetest directory). May be repeated.  -c, --compile-opts PATH                            EDN file containing opts to be passed to the ClojureScript compiler.  -D, --doo-opts PATH                                EDN file containing opts to be passed to doo.  -V, --verbose                                      Flag passed directly to the ClojureScript compiler toenable verbose compiler output.  -H, --help

Advanced compilation

To use Closure Compiler advanced optimisation levels you will need to create anEDN file like this:

{:optimizations:advanced}

Now when you run the following, your tests will be executed with advancedcompilation:

clj -m cljs-test-runner.main -c ./config/advanced-compilation.edn

You can also directly inline the EDN using the-c flag:

clj -m cljs-test-runner.main -c'{:optimizations :advanced}'

There is a known issue with:whitespace, I just haven't invested the time intoworking out what it is. For now, stick to:none,:simple or:advanced, theoriginal issue for optimisation levels breaking things is#16.

Bundle target

The newbundle target requires a 2-step process for compilation. Onefor building anindex.js consumable by bundlers like webpack, and a secondstep for actually running the bundler. This requires you to specify 2 differenttargets.

In essence, this requires you to include the following in yourdoo.edn:

{:output-to "resources/public/js/main.js"}

Your CLJS compiler options should be according to the standard guide.

Gotchas

Paths

Make sure the directory (or directories!) containing your tests are on your Javaclass path. Specify this with a top level:paths key in yourdeps.edn file.

Lumo / Planck

To use Lumo or Planck, add the generated test runner to the:paths in yourdeps.edn:

:paths ["src""test""cljs-test-runner-out/gen"]

and set the environment:

-x lumo

or

-x planck

Unlicenced

Find the fullunlicense in theUNLICENSE file, but here's asnippet.

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distributethis software, either in source code form or as a compiled binary, for anypurpose, commercial or non-commercial, and by any means.

Do what you want. Learn as much as you can. Unlicense more software.


[8]ページ先頭

©2009-2025 Movatter.jp