Make ClojureScript compiler output multiple, independent .js files for use in Cypress
Asked Answered
P

0

8

I'm trying to set up Cypress tests written in ClojureScript for a project that uses lein-cljsbuild. Using the following configuration, I'm able to compile a single test namespace into a single .js file:

:cljsbuild
  {:builds [{:id "cypress"
             :source-paths ["test/cypress"]
             :compiler     {:optimizations :simple
                            :main          "specs.login-spec"
                            :output-to     "cypress/integration/login_spec.js"
                            :output-dir    "test-resources/cypress/js/build/"}}]}

The above works fine and executes in Cypress correctly.

Now I want to scale it. Here are my requirements:

  • have multiple specs written in ClojureScript: specs.login-spec, specs.shopping-cart-spec, specs.checkout-spec, and so on (I expect to have tens of those).
  • I want Cypress to recognize them as separate test suites (so that, for instance, I can execute them independently). This means each ClojureScript test namespace has to end up in a separate JS file that is standalone, i.e. doesn't depend on any other JS file.
  • I want to be able to compile all specs reasonably fast.
  • I want source watching to be available as it is with a simple setup, i.e. lein cljsbuild auto … should still work, and use incremental building.

How do I accomplish that?

The most naive approach would be to specify one build plan for each spec. But that would mean that for N specs, I'd need to run compilation N times. That would be very slow.

The only other idea that popped to my head was ClojureScript modules, but the following setup emits empty files:

{:id "cypress"
 :source-paths ["test/cypress"]
 :compiler {:optimizations :simple
            :output-dir    "test-resources/cypress/js/build/"
            :modules {:m1 {:output-to "cypress/integration/login_spec.js"
                           :entries #{"specs.login-spec"}}
                      :m2 {:output-to "cypress/integration/checkout_spec.js"
                           :entries #{"specs.checkout-spec"}}}}}

My spec files are very simple right now - and individually, they compile and run in Cypress just fine. Example:

(ns specs.login-spec
  (:require [tools.commands]
            [tools.interop :refer [cy describe it]]))

(describe "Lorem" (fn []
  (describe "Ipsum" (fn []
    (it "Blah!" (fn []
      (-> cy
        (.LogInAndNavigate)
        …)))))))
Parity answered 20/2, 2018 at 9:48 Comment(2)
Did you get the solution for this?Legate
Not fully. I ended up programatically generating the :modules for the Cypress CLJS build based on a hardcoded llist of spec files. This way I get a JS file per one spec file. But I need to remember to change the hardcoded list anytime I add or remove a spec file.Parity

© 2022 - 2024 — McMap. All rights reserved.