From 06ea5cebaeefe7b75f041e4a4f3ae53ee3c5d809 Mon Sep 17 00:00:00 2001 From: David Morgan Date: Fri, 24 Oct 2025 17:04:13 +0200 Subject: [PATCH] Test DirectoryWatcher exception on missing path. --- .../test/directory_watcher/file_tests.dart | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkgs/watcher/test/directory_watcher/file_tests.dart b/pkgs/watcher/test/directory_watcher/file_tests.dart index 77b41d966..d56f921d8 100644 --- a/pkgs/watcher/test/directory_watcher/file_tests.dart +++ b/pkgs/watcher/test/directory_watcher/file_tests.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'dart:io' as io; +import 'dart:io'; import 'dart:isolate'; import 'package:test/test.dart'; @@ -18,6 +19,21 @@ void fileTests({required bool isNative}) { } void _fileTests({required bool isNative}) { + test('error reported if directory does not exist', () async { + await startWatcher(path: 'missing_path'); + + // TODO(davidmorgan): reconcile differences. + if (isNative && !Platform.isMacOS) { + expect(expectNoEvents, throwsA(isA())); + } else { + // The polling watcher and the MacOS watcher do not throw on missing file + // on watch. + await expectNoEvents(); + writeFile('missing_path/file.txt'); + await expectAddEvent('missing_path/file.txt'); + } + }); + test('does not notify for files that already exist when started', () async { // Make some pre-existing files. writeFile('a.txt');