Fork me on GitHub
#clojurescript
<
2024-01-31
>
rafaeldelboni11:01:05

Hey, yet another question about async tests running on node :) I've managed to make this async test work fine, but whenever it throw an error inside a promise it is catch and logged by the p/catch function, but the test suite returns status code 0. https://github.com/rafaeldelboni/helix-jsdom-portfolio-mantine/blob/main/tests/main/mantine_test.cljs I've tried to rethrow the error or even throwing a new error, but nothing seems to change the exit code. Anyone knows how to fix this?

thheller11:01:37

is case of catch you also need to call (done), otherwise it won't know the test finished

thheller11:01:00

and you don't need to rethrow the error, you already know you are in a failed state

thheller11:01:20

so you can add an assertion or so

thheller11:01:30

I forgot if there is something like (cljs.test/fail "should not have reached here")

rafaeldelboni11:01:04

uhmm thanks I will try

rafaeldelboni11:01:56

I changed the catch fn to:

(fn [err]
          (js/console.error err)
          (done)) 
And now the return of the test suit is better, but dont states the failing error:

rafaeldelboni11:01:21

adding an (is (= nil err)) in the catch fn does the trick, maybe I will write an macro to wrap all of this

dnolen18:01:41

right you need to explicitly fail if some error is thrown

dnolen18:01:55

we didn’t do any macro stuff here because maybe you aren’t using core.async etc.

👍 1
Aaron Cooley23:01:15

I’m working my way through Web Development With Clojure, and I’m stuck on the beginning of Chapter 3 when the first ClojureScript example appears. It consists of a simple “Hello World” exercise in cljs, starting on page 74. First, you update project.clj with the dependencies and configuration options:

:dependencies
[...
 [org.clojure/clojurescript "1.10.764" :scope "provided"]]
...
  :resource-paths ["resources" "target/cljsbuild"]
  :target-path "target/%s/"
  :main ^:skip-aot guestbook.core

  :plugins [[lein-cljsbuild "1.1.8"]]
  :cljsbuild
  {:builds
   {:app {:source-paths ["src/cljs"]
          :compiler {:output-to "target/cljsbuild/public/js/app.js"
                     :output-dir "target/cljsbuild/public/js/out"
                     :main "guestbook.core"
                     :asset-path "/js/out"
                     :optimizations :none
                     :source-map true
                     :pretty-print true}}}}
  :clean-targets
  ^{:protect false}
  [:target-path
   [:cljsbuild :builds :app :compiler :output-dir]
   [:cljsbuild :builds :app :compiler :output-to]]
Then you create your Clojurescript in /src/cljs/guestbook/core.cljs
(ns guestbook.core)

(-> (.getElementById js/document "content")
    (.-innerHTML)
    (set! "Hello, World!"))
Then you modify /resources/html/home.html to run the compiled JavaScript
{% extends "base.html" %}
{% block content %}
<input id="token" type="hidden" value="{{csrf-token}}" />
<div id="content"></div>
{% endblock %}
{% block page-scripts %}
   {% script "/js/app.js" %}
{% endblock %}
Then you run the following Leiningen commands:
lein cljsbuild once
lein run
...navigate to localhost:3000 and you're supposed to see your Hello, World! Instead, I get messages that everything compiled and the server started successfully, but the home.html content block is blank. Any hints on what I might be doing wrong? I'm running Clojure 1.10.1 on Windows 10 with Java 17.0.9 (Temurin-17.0.9+9), and everything in the tutorial runs fine right up to this point.

phill00:02:47

Check the browser's "Developer Tools" and especially especially the "Console" and "Network" parts of it.

Aaron Cooley00:02:43

What am I looking for?

Aaron Cooley00:02:20

I'm not new to programming, but I'm new to web development. I've been playing around with Clojure for a while and think I've largely gotten the hang of it. Just trying to figure out why my Luminus app is ignoring my Clojurescript so I can move forward to the next phase.

Aaron Cooley00:02:51

Oh man. I switched my browser from Edge to Chrome and it works on Chrome. Sounds like a Microsoft problem :rolling_on_the_floor_laughing:

p-himik00:02:36

It it might be a Chrome error where it allows something to happen that shouldn't be happening. In DevTools console or network tab, there should be some warnings/errors when nothing is displayed.