bhauman / figwheel-main

Figwheel Main provides tooling for developing ClojureScript applications
https://figwheel.org
Eclipse Public License 1.0
640 stars 93 forks source link

[BUG]: Core node modules work in app but not in tests #148

Open jaidetree opened 5 years ago

jaidetree commented 5 years ago

PROBLEM:

I am able to access core node modules in dev build but not in my tests.

REPRODUCTION:

Created https://github.com/eccentric-j/minirepro-fig-test-deps to minimally reproduce the problem

  1. Run git clone git@github.com:eccentric-j/minirepro-fig-test-deps.git
  2. Run cd minirepro-fig-test-deps
  3. Run lein fig:build
  4. Run node target/node/dev/dev-main.js
  5. You should see output similar to:
    Loaded main script
    Running main fn
    #js [".gitignore" "README.md" "dev.cljs.edn" "figwheel-main.edn" "node_modules" "package-lock.json" "package.json" "project.clj" "src" "target" "test" "test.cljs.edn"]
  6. It worked. Now run lein fig:test

EXPECTED:

ACTUAL:

Questions:

Environment:

dev.cljs.edn:

^{:watch-dirs ["test" "src"]
  :auto-testing true}
{:main minirepro-fig-test-deps.core
 :npm-deps     {"ws" "6.1.3"}
 :install-deps true
 :target :nodejs}

test.cljs.edn

^{
  ;; use an alternative landing page for the tests so that we don't
  ;; launch the application
  :open-url "http://[[server-hostname]]:[[server-port]]/test.html"

  ;; uncomment to launch tests in a headless environment
  ;; you will have to figure out the path to chrome on your system
  ;; :launch-js ["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" "--headless" "--disable-gpu" "--repl" :open-url]
  }
{:main minirepro-fig-test-deps.test-runner
 :target :nodejs}
bhauman commented 5 years ago

Yes your test.cljs.edn file is not correct.

You at least need to remove the :open-url param as it makes no sense in this context. I think the :open-url is causing this to run in the Browser and thats why you are getting that error.

nenadalm commented 5 years ago

Hi. I have the same issue with simpler reproduction (ClojureScript script running on nodejs using built-in module).

Project setup

deps.edn

{:paths ["src"]
 :deps {org.clojure/clojurescript {:mvn/version "1.10.520"}
        com.bhauman/figwheel-main {:mvn/version "0.2.3"}}}

dev.cljs.edn

{:main app.core
 :target :nodejs}

src/app/core.cljs

(ns app.core
  (:require
   [path :as path]))

(defn -main [& args]
  (println (.join path "/first" "second")))

(set! *main-cli-fn* -main)

Reproduction

Compiling and then running the script runs just fine:

$ clj -m figwheel.main -bo dev
$ node target/node/dev/dev-main.js 
/first/second

Running script using -m option fails on missing node module:

$ clj -m figwheel.main -co dev.cljs.edn -m app.core
2019-07-29 10:37:52.354:INFO::main: Logging initialized @8217ms to org.eclipse.jetty.util.log.StdErrLog
[Figwheel] Compiling build dev to "target/node/dev/dev-main.js"
[Figwheel] Failed to compile build dev in 1.751 seconds.
[Figwheel:WARNING] Compile Exception   /var/www/html/nenadalm/contrib/figwheel-main-issues/148/src/app/core.cljs   line:3  column:5

  No such namespace: path, could not locate path.cljs, path.cljc, or JavaScript source providing "path" in file /var/www/html/nenadalm/contrib/figwheel-main-issues/148/src/app/core.cljs

  1  (ns app.core
  2    (:require
  3     [path :as path]))
         ^---
  4  
  5  (defn -main [& args]
  6    (println (.join path "/first" "second")))
  7  
  8  (set! *main-cli-fn* -main)
...