Skip to content

Commit c9b9bb7

Browse files
committed
feat(emacs): add test for Flymake
Our existing Flymake testing is weak. Add a test which covers almost all of the Flymake plugin's code.
1 parent 05a4d14 commit c9b9bb7

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

plugin/emacs/test/quicklintjs-test.el

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
(expand-file-name default-directory)
1010
".melpa-cache/"))
1111

12+
(setq quicklintjs-test-dir (file-name-directory (or load-file-name buffer-file-name)))
13+
1214
(defun quicklintjs-install-deps (deps)
1315
(mapcar (lambda (pkg) (unless (package-installed-p pkg)
1416
(if (> emacs-major-version 24)
@@ -39,6 +41,11 @@
3941

4042
(defun def-flymake-tests ()
4143
(require 'flymake-quicklintjs)
44+
45+
; Disable warning which causes tests to fail when run non-interactively:
46+
; "Disabling backend flymake-proc-legacy-flymake because (error Can’t find a suitable init function)"
47+
(remove-hook 'flymake-diagnostic-functions 'flymake-proc-legacy-flymake)
48+
4249
(ert-deftest quicklintjs-flymake-parse-errors-and-warnings ()
4350
(skip-unless (>= emacs-major-version 26))
4451
(let ((js-buf (generate-new-buffer "*js-buf*")))
@@ -89,7 +96,21 @@ foobar\")((16 . 22) 2 \"E0057\" \"use of undeclared variable: foobar\")(\
8996
(point-min) (point-max)
9097
flymake-quicklintjs-program nil
9198
out-buf nil "--stdin"
92-
"--output-format=emacs-lisp") 0))))))
99+
"--output-format=emacs-lisp") 0)))))
100+
101+
(ert-deftest quicklintjs-flymake-check-errors-js ()
102+
(with-temp-buffer
103+
(javascript-mode)
104+
(insert-file-contents-literally (expand-file-name "error.js" quicklintjs-test-dir) nil nil nil t)
105+
(flymake-mode 1)
106+
(add-hook 'flymake-diagnostic-functions #'flymake-quicklintjs nil t)
107+
(flymake-start)
108+
109+
(with-timeout (5
110+
(ert-fail "Test timed out waiting for diagnostics."))
111+
;; TODO(strager): Assert specific diagnostics
112+
(while (not (flymake-diagnostics))
113+
(accept-process-output nil 0.01))))))
93114

94115
(defun def-eglot-tests ()
95116
(ert-deftest quicklintjs-is-in-eglot-servers ()

0 commit comments

Comments
 (0)