Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Created February 10, 2012 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazywithclass/1790981 to your computer and use it in GitHub Desktop.
Save lazywithclass/1790981 to your computer and use it in GitHub Desktop.
TDD functions revised (added chance to run a single test)
(defun mocha-run(test-file)
"Runs all the tests in the passed file"
(interactive "b")
(let* (command result exit-value)
(setq command (concat "mocha -r should --globals i --timeout 10000 " test-file))
(setq exit-value (shell-command command))
(color-modeline test-file)))
(defun color-modeline(test-file)
"Colors the modeline, green success red failure"
(interactive)
(let (test-result-color)
(if (= exit-value 0)
(progn
(setq test-result-color "Green")
(run-at-time "1 sec" nil 'no-color-modeline))
(setq test-result-color "Red"))
(set-face-background 'modeline test-result-color)))
(defun no-color-modeline()
"No color for the modeline"
(interactive)
(set-face-background 'modeline nil))
(global-set-key (kbd "C-c C-r") 'mocha-run)
(defun mocha-test-region (start end)
"Runs mocha on a region, useful to run tests on single functions and not on an entire file; does this by creating a file running mocha on it and then deleting it, for sure not the best way but it's working and for now I'm fine"
(interactive "r")
(setq filename "mocha-test-region.js")
(write-region start end filename)
(mocha-run (expand-file-name filename))
(delete-file filename)
)
(global-set-key (kbd "C-c C-j") 'mocha-test-region)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment