Skip to content

Commit e722875

Browse files
committed
Add tests for livereload hidden/temp file filtering
Add test cases for: - Dotfiles (.vim swap, .hidden) not triggering rebuild - Editor backup files (~ suffix) not triggering rebuild - Emacs auto-save files (#file#) not triggering rebuild Refs #2519
1 parent 134ce48 commit e722875

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

mkdocs/tests/livereload_tests.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,46 @@ def test_watches_through_relative_symlinks(self, origin_dir, site_dir):
619619
Path(origin_dir, "README.md").write_text("edited")
620620
self.assertTrue(started_building.wait(timeout=10))
621621

622+
@tempdir({"foo.md": "original"})
623+
def test_ignores_dotfile_changes(self, docs_dir):
624+
"""Hidden files (starting with '.') should not trigger rebuild."""
625+
started_building = threading.Event()
626+
with testing_server(docs_dir, started_building.set) as server:
627+
server.watch(docs_dir)
628+
time.sleep(0.01)
629+
630+
# Vim swap file
631+
Path(docs_dir, ".foo.md.swp").write_text("swap")
632+
self.assertFalse(started_building.wait(timeout=0.5))
633+
634+
# Generic dotfile
635+
Path(docs_dir, ".hidden").write_text("hidden")
636+
self.assertFalse(started_building.wait(timeout=0.5))
637+
638+
@tempdir({"foo.md": "original"})
639+
def test_ignores_tilde_backup_files(self, docs_dir):
640+
"""Editor backup files (ending with '~') should not trigger rebuild."""
641+
started_building = threading.Event()
642+
with testing_server(docs_dir, started_building.set) as server:
643+
server.watch(docs_dir)
644+
time.sleep(0.01)
645+
646+
# Backup file created by editors
647+
Path(docs_dir, "foo.md~").write_text("backup")
648+
self.assertFalse(started_building.wait(timeout=0.5))
649+
650+
@tempdir({"foo.md": "original"})
651+
def test_ignores_emacs_autosave_files(self, docs_dir):
652+
"""Emacs auto-save files (#*#) should not trigger rebuild."""
653+
started_building = threading.Event()
654+
with testing_server(docs_dir, started_building.set) as server:
655+
server.watch(docs_dir)
656+
time.sleep(0.01)
657+
658+
# Emacs auto-save pattern
659+
Path(docs_dir, "#foo.md#").write_text("autosave")
660+
self.assertFalse(started_building.wait(timeout=0.5))
661+
622662
@tempdir()
623663
def test_watch_with_broken_symlinks(self, docs_dir):
624664
Path(docs_dir, "subdir").mkdir()

0 commit comments

Comments
 (0)