scottaj / mocha.el

Emacs mode for running mocha tests
MIT License
71 stars 21 forks source link

Window getting killed every iteration #52

Closed jojojames closed 6 years ago

jojojames commented 7 years ago

Wonder why we call kill-buffer here when the tests are ran?

(defun mocha-run (&optional mocha-file test)
  "SNIP"
  (when (get-buffer "*mocha tests*")
    (kill-buffer "*mocha tests*"))
  (let ((test-command-to-run (mocha-generate-command nil mocha-file test))
        (default-directory (mocha-find-project-root))
        (compilation-buffer-name-function (lambda (_) "" "*mocha tests*")))
    (compile test-command-to-run 'mocha-compilation-mode)))

Some downsides I've noticed include a stray window being created sometimes during test runs (guessing kill-buffer doesn't clean up the test window) and it being hard to do some 'automatic test run on file save' type feature since the window kind of pops in and out.

jojojames commented 7 years ago

This advice without the kill-buffer works reasonably well for me with no downsides that I see yet.

  (defun jj*--mocha-run (&optional mocha-file test)
    "Run mocha in a compilation buffer.

If MOCHA-FILE is specified run just that file otherwise run
MOCHA-PROJECT-TEST-DIRECTORY.

IF TEST is specified run mocha with a grep for just that test."
    (let ((test-command-to-run (mocha-generate-command nil mocha-file test))
          (default-directory (mocha-find-project-root))
          (compilation-buffer-name-function (lambda (_) "" "*mocha tests*")))
      (compile test-command-to-run 'mocha-compilation-mode)))
  (advice-add 'mocha-run :override 'jj*--mocha-run)