edmundmiller / emacs-jest

A package to run jest inside emacs
GNU General Public License v3.0
81 stars 18 forks source link

Jest buffer holds on to previous test info #13

Closed bolivier closed 2 years ago

bolivier commented 4 years ago

Is there a way to make the jest output buffer clear its contents before running the tests again?

KhalfaniW commented 2 years ago

Yes!! I found a script modified from here: https://emacs.stackexchange.com/questions/58960/re-fill-compilation-mode-buffer-from-shell-script and modified it!

Before each new thing the compilation buffer logs it will clear the buffer if it has this string "Ran all test" which I think is at the end of every test

(setq test-separator "Ran all test")
(defun my/hook-only-allow-1-jest-test (inserted-string)
  (when (and (s-contains? "*jest*" (buffer-name))
             (s-contains? test-separator (buffer-string)))
    (comint-clear-buffer))
  inserted-string )

(add-hook 'comint-preoutput-filter-functions #'my/hook-only-allow-1-jest-test)
edmundmiller commented 2 years ago

Could I get a little more context for this? I'm not able to reproduce. I've tried using this repo as an example and ran jest on 02 Plain Vanilla and the buffer appears to clear every time I call jest

KhalfaniW commented 2 years ago

@Emiller88 In a regular terminal jest will clear it's output when you edit a file and the tests run again

The problem here is the jest output buffer in emacs doesn't clear when you update a file and the jest reruns in the same instance.

edmundmiller commented 2 years ago

Ah, I see the issue now, I was just using jest, without --watch. I was able to reproduce it now!