Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in use with tests #76

Closed
ghost opened this issue May 6, 2016 · 4 comments
Closed

in use with tests #76

ghost opened this issue May 6, 2016 · 4 comments

Comments

@ghost
Copy link

ghost commented May 6, 2016

I'm trying to pinpoint the issue I'm having here, and was wondering if anyone has experience with something similar? I feel like the root of my problems is that boot-reload might be caching something that it ought not to be.

I'm running a cljs.test suite that serves up test.html where my namespaces are loaded via the following:

<script>
function run_tests() {
    load_namespaces() // hack that uses goog.require internals, but it works.
    cljs.core.set_print_fn_BANG_(testPrintLn)
    testing_util.runner.run()
}

function rerun_tests() {
    run_tests()
}

window.addEventListener('load', run_tests);
</script>

And I'm using the boot hook for reloading as follows: (reload :on-jsload 'testing-util.runner/rerun). This simply invokes the following inside of my testing util:

(ns testing-util.runner
  (:require [cljs.test :refer-macros [run-all-tests]]))

(enable-console-print!)

(defn ^:export run []
  (run-all-tests #".*-test\z"))

(defn ^:export rerun
  "Expose this function so boot-reload can invoke it in the context of
  resources/test.html after a file has changed. Ultimately, the test.html
  will simply invoke the run function above."
  []
  (.rerun_tests js/window))

Now, here's the weird part. When I run the boot environment the first time, no tests are run. Even if I save a test file and see the reload message in a console.log, no tests are run. It's not until I save my testing_util/runner.cljs do I actually get any tests to run. Here is the reload message I get when saving the runner:

main.out/adzerk/boot_reload.cljs.cache.edn
main.out/testing_util/runner.js.map
main.out/testing_util/runner.cljs.cache.edn
main.out/testing_util/runner.js

After a safe of the runner, suddenly all my tests namespaced *-test are run. Similarly, if I comment out a complete (deftest ...) block, then save that file- the tests are run as if I didn't comment out the block at all.

The reload looks like:

main.out/some_tests/some_test.js.map
main.out/some_tests/some_test.cljs
main.out/some_tests/some_test.js

What's more confusing, though, is if I change a test to fail, then save the test file, it will fail as expected. So it seems like there are some namespaces being overwritten, but only some of the time, and I can't figure out the secret sauce. Is this aggressive caching that's causing the issue? Is it namespaces not being properly reloaded that need to (something to do with the run-all-tests macro)?

@Deraen
Copy link
Contributor

Deraen commented Jun 13, 2016

The runner namespace doesn't depend on the test namespaces.

When a test namespace is changed, only the dependent namespaces are recompiled and as runner ns is not such, it is not reloaded. This is the way incremental compilation is implemented in ClojureScript compiler. You could check how the compiler works by compiling the same project with cljs.jar and using cljs.compiler.api/watch.

To fix this you should require all the test namespaces in the runner ns.

@Deraen
Copy link
Contributor

Deraen commented Oct 18, 2016

To fix this you should require all the test namespaces in the runner ns.

Please reopen or create another issue if this doesn't fix this.

@Deraen Deraen closed this as completed Oct 18, 2016
@lwhorton
Copy link

Sorry for leaving this dangling. Including the tests specifically in the runner fixes the problem, although in an inconvenient manner. I'll keep thinking and come up with a better solution.

@Deraen
Copy link
Contributor

Deraen commented Oct 18, 2016

Due to how ClojureScript compiler works, and how boot-reload leverages it, this is not easy thing to solve. The compiler depends on static dependency information to select which namespaces and in which order to compile, and boot-reload completely depends on that.

Check https://github.com/crisptrutski/boot-cljs-test. It is not perfect, and doesn't really solve this problem yet but there are two issues related to this: crisptrutski/boot-cljs-test#40 crisptrutski/boot-cljs-test#7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants