@@ -11,13 +11,13 @@ import 'package:watcher/src/utils.dart';
1111
1212import '../utils.dart' ;
1313
14- void fileTests () {
14+ void fileTests ({ required bool isNative} ) {
1515 for (var i = 0 ; i != runsPerTest; ++ i) {
16- _fileTests ();
16+ _fileTests (isNative : isNative );
1717 }
1818}
1919
20- void _fileTests () {
20+ void _fileTests ({ required bool isNative} ) {
2121 test ('does not notify for files that already exist when started' , () async {
2222 // Make some pre-existing files.
2323 writeFile ('a.txt' );
@@ -297,6 +297,29 @@ void _fileTests() {
297297 })));
298298 });
299299
300+ test (
301+ 'emits events for many nested files moved out then immediately back in' ,
302+ () async {
303+ withPermutations (
304+ (i, j, k) => writeFile ('dir/sub/sub-$i /sub-$j /file-$k .txt' ));
305+
306+ await startWatcher (path: 'dir' );
307+
308+ renameDir ('dir/sub' , 'sub' );
309+ renameDir ('sub' , 'dir/sub' );
310+
311+ if (isNative) {
312+ await inAnyOrder (withPermutations (
313+ (i, j, k) => isRemoveEvent ('dir/sub/sub-$i /sub-$j /file-$k .txt' )));
314+ await inAnyOrder (withPermutations (
315+ (i, j, k) => isAddEvent ('dir/sub/sub-$i /sub-$j /file-$k .txt' )));
316+ } else {
317+ // Polling watchers can't detect this as directory contents mtimes
318+ // aren't updated when the directory is moved.
319+ await expectNoEvents ();
320+ }
321+ });
322+
300323 test (
301324 'emits events for many files added at once in a subdirectory with the '
302325 'same name as a removed file' , () async {
@@ -334,4 +357,32 @@ void _fileTests() {
334357 }
335358 });
336359 });
360+
361+ test (
362+ 'does not notify about the watched directory being deleted and '
363+ 'recreated immediately before watching' , () async {
364+ createDir ('dir' );
365+ writeFile ('dir/old.txt' );
366+ deleteDir ('dir' );
367+ createDir ('dir' );
368+
369+ await startWatcher (path: 'dir' );
370+ writeFile ('dir/newer.txt' );
371+ await expectAddEvent ('dir/newer.txt' );
372+ });
373+
374+ test ('does not suppress files with the same prefix as a directory' , () async {
375+ // Regression test for https://github.com/dart-lang/watcher/issues/83
376+ writeFile ('some_name.txt' );
377+
378+ await startWatcher ();
379+
380+ writeFile ('some_name/some_name.txt' );
381+ deleteFile ('some_name.txt' );
382+
383+ await inAnyOrder ([
384+ isAddEvent ('some_name/some_name.txt' ),
385+ isRemoveEvent ('some_name.txt' )
386+ ]);
387+ });
337388}
0 commit comments