diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-02 00:08:33 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-02 00:08:33 -0400 |
| commit | 821ec1e4d5f5e64ed54972960589ca5c8c41b9f9 (patch) | |
| tree | dad5e9b67a8f059b962d7070f42244f8d095a42f /tests/test-markdown-config-preview-autostart.el | |
| parent | 622a4d8c13a5037e064cf9caa3e917100f7f5cc9 (diff) | |
| download | dotemacs-821ec1e4d5f5e64ed54972960589ca5c8c41b9f9.tar.gz dotemacs-821ec1e4d5f5e64ed54972960589ca5c8c41b9f9.zip | |
feat(markdown): start the preview server from F2 when it's down
cj/markdown-preview now brings up the simple-httpd listener itself instead of signaling a user-error pointing at cj/markdown-preview-server-start. The two-command flow guarded against a surprise network listener, but the preview is the only reason the listener exists, so the guard was just an extra step. I kept the start command for manual use.
Diffstat (limited to 'tests/test-markdown-config-preview-autostart.el')
| -rw-r--r-- | tests/test-markdown-config-preview-autostart.el | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/test-markdown-config-preview-autostart.el b/tests/test-markdown-config-preview-autostart.el new file mode 100644 index 00000000..247c75d7 --- /dev/null +++ b/tests/test-markdown-config-preview-autostart.el @@ -0,0 +1,52 @@ +;;; test-markdown-config-preview-autostart.el --- preview server autostart -*- lexical-binding: t; -*- + +;;; Commentary: +;; Tests for `cj/--markdown-preview-ensure-server': F2 preview starts the +;; simple-httpd listener itself when it isn't running (per the 2026-07-01 +;; cj comment), and leaves a running server alone. simple-httpd isn't +;; installed in batch, so the tests provide a stub feature with the two +;; functions the helper touches. + +;;; Code: + +(require 'ert) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) + +(require 'markdown-config) + +;; Stand in for the elpa package: `require' in the helper becomes a +;; no-op. Tests mock httpd-running-p explicitly (works whether the +;; real simple-httpd or this stub is loaded), so the stub bodies never +;; matter. +(require 'cl-lib) +(unless (featurep 'simple-httpd) + (defun httpd-running-p () nil) + (defun httpd-start () nil) + (provide 'simple-httpd)) + +(ert-deftest test-markdown-config-ensure-server-starts-when-down () + "Normal: a stopped server gets started." + (let ((started nil)) + (cl-letf (((symbol-function 'httpd-running-p) (lambda () nil)) + ((symbol-function 'cj/markdown-preview-server-start) + (lambda () (setq started t)))) + (cj/--markdown-preview-ensure-server) + (should started)))) + +(ert-deftest test-markdown-config-ensure-server-noop-when-running () + "Boundary: a running server is left alone." + (let ((started nil)) + (cl-letf (((symbol-function 'httpd-running-p) (lambda () t)) + ((symbol-function 'cj/markdown-preview-server-start) + (lambda () (setq started t)))) + (cj/--markdown-preview-ensure-server) + (should-not started)))) + +(ert-deftest test-markdown-config-preview-no-longer-signals-user-error () + "Error-path regression: the old user-error on a stopped server is gone." + (should-not (string-match-p "user-error" + (format "%S" (symbol-function 'cj/markdown-preview))))) + +(provide 'test-markdown-config-preview-autostart) +;;; test-markdown-config-preview-autostart.el ends here |
