Jest coverage highlighting in emacs not updating after change

Multi tool use
Multi tool use


Jest coverage highlighting in emacs not updating after change



I have emacs minor mode for jest coverage highlighting and when I change coverage (update my tests) and run this function the highlighting is not updating.


(defun jc/mark-buffer ()
(interactive)
(let* ((dir (jc/root-git-repo))
(json-object-type 'hash-table)
(json-array-type 'list)
(json-key-type 'string)
(json (json-read-file (concat dir "/coverage/coverage-final.json")))
(filename (buffer-file-name (current-buffer)))
(coverage (gethash filename json))
(statments (gethash "statementMap" coverage)))
(save-excursion
(let ((coverage-list (gethash "s" coverage))
(covered 0)
(not-covered 0))
(maphash (lambda (key value)
(if (not (and jc/statements (= (gethash key jc/statements) value)))
(let* ((statment (gethash key statments))
(start (gethash "start" statment))
(end (gethash "end" statment))
(start-line-pos (jc/line-pos-at-line (gethash "line" start)))
(start-pos (+ start-line-pos (gethash "column" start)))
(end-line-pos (jc/line-pos-at-line (gethash "line" start)))
(end-pos (+ end-line-pos (gethash "column" end)))
(face (if (= value 0)
'jc/not-covered
'jc/covered)))
(hlt-highlight-region start-pos end-pos face)))
(if (= value 0)
(setq not-covered (+ 1 not-covered))
(setq covered (+ 1 covered))))
coverage-list)
(message "%3.2f%% coverage" (* (/ (float covered) (+ covered not-covered)) 100))
(setq jc/statements coverage-list)))))



I don't know if the problem is in my emacs code or in my assumptions about jest coverage json file.



the file have filenames as keys and have keys statementMap that contain position of the statements:


"statementMap":{"0":{"start":{"line":186,"column":0},"end":{"line":7951,"column":3}},"1":{"start":{"line":187,"column":15},"end":{"line":187,"column":62}},...}



and "s" key which look like this:


"s":{"0":1,"1":1,"2":0,"3":1,"4":1,"5":1472, ....}



I assume that 0 mean not covered and 1 covered but I don't know what other number means, I assume then are covered because message that show coverage status have correct value (the same as from jest output). the key in s is reference to key in statementMap.



If I run the function when buffer is clean it seems that is work as expected line are mark red and green. When I added test that should covered one additional line and then run the function when there already where highlighting nothing was changed but when I cleared the buffer the red line that was previously not covered was mark as green.



That check if coverage was change in code is needed because the function is very slow on big files, and it freezes Emacs.









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

60ZMuuR,h qb 9AneX8R ghY,O BJ,AjT0jhe 3IfBTbbSFqyuh4uhlgPA l6T8FFP6ddmo8Z2lVS0,O1 IkRlRXrWU7R2DBTy
twkS,YtnsNZ4fSu6MbplPBWw,Aqu5

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters