Fork me on GitHub
#clojurescript
<
2022-07-06
>
tugh13:07:45

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.

Stuart17:07:24

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: cljs.core.nth.call(...).charCodeAt is not a function Am I doing the js interop wrong ?

dpsutton17:07:37

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"]}
cljs.user=>

dpsutton17:07:33

also tried in a browser environment with same success

Stuart17:07:32

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

dpsutton17:07:59

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

dpsutton17:07:31

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 'cljs.core.first.call(null,vm.call(null,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt')

cljs.user=>

dpsutton17:07:21

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).
cljs.core.first.call(null,vm.call(null,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt is not a function. (In 'cljs.core.first.call(null,vm.call(null,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt()', 'cljs.core.first.call(null,vm.call(null,new cljs.core.Keyword(null,"input","input",556931961))).charCodeAt' is undefined)

cljs.user=>
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
                   (js/FormData.)
                    (.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!

rolt19:07:10

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 😅