Skip to content

Instantly share code, notes, and snippets.

@plexus
Created September 12, 2020 11:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plexus/345077c49cf8c1b56f3a209e63ed5b2b to your computer and use it in GitHub Desktop.
Save plexus/345077c49cf8c1b56f3a209e63ed5b2b to your computer and use it in GitHub Desktop.

2020-09-12 Testing ClojureScript itself

General

There are various test suites under src/test

  • cljs
  • cljs_cli
  • clojure
  • self

Also under src/test are ClojureScript files that are used as compiler inputs for tests:

  • cljs_build
  • cljs_cp
  • externs
  • node

Scripts

There are a handful of `script/test-…` scripts to invoke these different tests. Other helper scripts used are

  • ci/install_jsc.sh – install Webkit jsc executable
  • script/cljc – wrapper script to invoke the clojurescript compiler with specific inputs and compiler options

Test suites

Runtime tests (src/test/cljs)

Found in src/test/cljs, typically run by doing an advanced compilation outputting to builds/out-adv/core-advanced-test.js, and then passing it to some command line JS runner like jsc.

Can be run with script/test, this will use script/cljc to create an advanced build, then run it with any JS runtime it can find. It looks for jsc on the $PATH, for other runtimes it relies on specific environment variables like SPIDERMONKEY_HOME, V8_HOME etc. See the section on JS Runtimes below.

If you want to just compile the tests so you can run them yourself with one or more JS runtimes (jsc, d8, jjs, ch, etc), then use clj -A:runtime.test.build. This uses compiler options found in resources/test.edn, and outputs builds/out-adv/core-advanced-test.js.

CLI test (src/test/cljs_cli)

Tests that invoke cljs.main with various arguments. These are written in Clojure, there’s a minimal test runner that invokes clojure.test in cljs-cli.test-runner.

Can be run with clj -A:cli.test.run or script/test-cli

You can pass the name of a repl-env to script/test-cli, e.g. script/test-cli node.

Compiler tests (src/test/clojure)

clojure.test based tests, found under src/test/clojure, that invoke the analyzer, compiler, etc.

Runner in clj.test-runner, can be invoked with clj -A:compiler.test:compiler.test.run

Self-host tests (src/test/self)

Two separate test suites, really. self-host and self-parity. Can be run with script/test-self-host and script/test-self-parity.

self-host: tests under src/test/self/self_host, see compiler options in resources/self_host_test.edn. After compilation can be run with node.

self-parity: tests under src/test/self/self_parity, see compiler options in resources/self_parity_test.edn. After compilation can be run with node.

CI

In .travis.yml and .github/workflows/test.yml you can see how things are run on CI. The travis one in particular shows how you can fetch Spidermonkey, javascript-core, chakra-core, graalvm to test on multiple js environments.

JS Runtimes

These are the runtimes that `script/test` looks for. Also showing the environment variables that `script/test` looks for to find the executables.

Webkit (Safari / iOS)

Use the jsc command line tool. On ubuntu you can grab libjavascriptcoregtk-4.0-bin, or install from source with ci/install_jsc.sh

Spidermonkey (Firefox)

Use the jsshell command line tool.

wget https://ftp.mozilla.org/pub/firefox/nightly/latest-mozilla-central/jsshell-linux-x86_64.zip
unzip jsshell-linux-x86_64.zip -d spidermoney
export SPIDERMONKEY_HOME="$(pwd)/spidermonkey"

Chakra core (Edge)

wget https://aka.ms/chakracore/cc_linux_x64_1_8_1 -O chakra-core.tar.gz
tar xvzf chakra-core.tar.gz
export CHAKRACORE_HOME="$(pwd)/ChakraCoreFiles/bin"

GraalVM

wget https://github.com/oracle/graal/releases/download/vm-1.0.0-rc12/graalvm-ce-1.0.0-rc12-linux-amd64.tar.gz
tar xzf graalvm-ce-1.0.0-rc12-linux-amd64.tar.gz
export GRAALVM_HOME="$(pwd)/graalvm-ce-1.0.0-rc12"

V8 (Chromium/node)

Requires the d8 executable. I can’t really find ready-made binaries, official instructions show how to build from source.

export V8_HOME="/dir/where/d8/is/found"

Nashorn (JS engine bundled with the JVM)

Probably the least important target to test against at this point.

export NASHORN_HOME="/dir/where/jjs/is/found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment