Fork me on GitHub

Is it possible to check code coverage for a cljs project which is targeting browser env? My current setup is shadow-cljs+deps.edn and karma for running tests but I couldn't find a way to check the code coverage for .cljs files. This is the :test build from shadow-cljs configuration:

{:target :karma
 :output-to "target/karma.js"}
It seems to me it is impossible for karma to check the code coverage because its context is limited to the generated "karma.js" file.


This is probably a really basic and stupid question, but I'm trying to get the ascii value for a character in clojurescript. I have a map, called vm , it has this structure

{:memory {0 65}
 :dp 1
 :input ["A" "B" "C"]}
I want to get the ascii value of the first item in input into :memory with key 1, then remove it from the input collection. I thought I could do this:
(assoc-in vm [:memory (vm :dp)] (.charCodeAt (first (vm :input))))
But I get the error when I run it > repl/invoke error TypeError: is not a function Am I doing the js interop wrong ?


works for me

❯ clj -A:cljs -M -m cljs.main -re node -r
ClojureScript 1.10.773
cljs.user=> (let [vm {:memory {0 65}
          :dp 1
          :input ["A" "B" "C"]}]
  (assoc-in vm [:memory (vm :dp)] (.charCodeAt (first (vm :input)))))
{:memory {0 65, 1 65}, :dp 1, :input ["A" "B" "C"]}


also tried in a browser environment with same success


so maybe I'm somehow calling .charCodeAt on a non string ? Could that be what the error is trying to tell me ?


not clear. But the repro step you’ve pasted does not repro


cljs.user=> (let [vm {:memory {0 65}
          :dp 1
          :input []}]
  (assoc-in vm [:memory (vm :dp)] (.charCodeAt (first (vm :input)))))
Execution error (TypeError) at (<cljs repl>:1).
null is not an object (evaluating ',,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt')



calling on null

cljs.user=> (let [vm {:memory {0 65}
          :dp 1
          :input [2]}]
  (assoc-in vm [:memory (vm :dp)] (.charCodeAt (first (vm :input)))))
Execution error (TypeError) at (<cljs repl>:1).,,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt is not a function. (In ',,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt()', ',,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt' is undefined)

calling on an integer

Vinicius Vieira Tozzi19:07:03

Hi, I am having a really basic issue with sending an image using ajax, this is my code:

(defn post-img [img-file]
  (let [form-data (doto
                    (.append "id" "10")
                    (.append "file" img-file "filename.txt"))]
    (ajax/POST "localhost:8000/ocr"
      {:body form-data
       :format (ajax/text-request-format)
       :response-format (ajax/json-response-format)
       :timeout 5000})))
But nothing happens, it seems for me that the form data object is being created correctly, but the (ajax/POST….) does not really do anything, am I missing something obvious? Thanks in advance!


it's probably not it, but text-request-format feels weird when sending a form data object

Vinicius Vieira Tozzi19:07:46

I also tried raw-request-format as well, but the result is the same

Vinicius Vieira Tozzi06:07:53

Ah, it was something very simple that I completely missed, it does not work with localhost:8000/…, I just needed to change to 😅