Created
February 16, 2018 16:36
-
-
Save bspaulding/263a1712057dd27194e456af15d2441e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; jest-mode.el -- test runner / feedback for jest | |
| ;;; Commentary: | |
| ;;; This is alpha, it does only what the author needed it to do. | |
| ;;; Please PR if you want to extend or fix something! | |
| ;;; Based this off of rspec-mode | |
| ;;; Code: | |
| (require 'compile) | |
| (require 'json) | |
| (defvar jest-last-failed-specs nil | |
| "The parsed JSON test results from jest --json output.") | |
| ;; (setq jest-last-failed-specs nil) | |
| ;; (json-encode jest-last-failed-specs) | |
| ;; (plist-get | |
| ;; (first | |
| ;; (plist-get | |
| ;; (first (plist-get jest-last-failed-specs :testResults)) | |
| ;; :assertionResults)) | |
| ;; :title) | |
| (defun jest-store-failures () | |
| "Parse JSON results from compilation buffer and store in jest-last-failed-specs." | |
| (string-match "{.*}" (buffer-string)) | |
| (let ((json-object-type 'plist)) | |
| (setq jest-last-failed-specs | |
| (json-read-from-string | |
| (match-string 0 (buffer-string)))))) | |
| (defvar jest-current-overlays () | |
| "List of the current overlays.") | |
| (defun jest-mark-failures () | |
| "Clear current overlays, redraw from jest-store-failures." | |
| (map delete-overlay jest-current-overlays)) | |
| (defun jest-store-and-mark-failures () | |
| "Store failures from compilation buffer, mark in current editor buffer." | |
| (jest-store-failures) | |
| (jest-mark-failures)) | |
| (define-compilation-mode jest-compilation-mode "Jest" | |
| "Jest compilation mode." | |
| (add-hook 'compilation-finish-functions 'jest-store-and-mark-failures nil t)) | |
| (defun jest-compile-command (target &optional opts) | |
| (concat "./node_modules/.bin/jest --forceExit --silent --json " target)) | |
| (defun jest-compile (target &optional opts) | |
| (compile | |
| (jest-compile-command target opts) | |
| 'jest-compilation-mode)) | |
| (defun jest-run-current-file () | |
| (interactive) | |
| (jest-compile (buffer-file-name))) | |
| (evil-leader/set-key | |
| "rt" 'jest-run-current-file) | |
| ;; (setq testlay | |
| ;; (make-overlay 86 87 (other-buffer))) | |
| ;; (delete-overlay testlay) | |
| ;; (overlay-put testlay 'before-string | |
| ;; (propertize "✗" 'face '(:foreground "red"))) | |
| ;; (overlay-put testlay 'before-string | |
| ;; (propertize "✓" 'face '(:foreground "green"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment