Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkgs/watcher/lib/src/stat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MockTimeCallback? _mockTimeCallback;
/// The OS file modification time has pretty rough granularity (like a few
/// seconds) which can make for slow tests that rely on modtime. This lets you
/// replace it with something you control.
void mockGetModificationTime(MockTimeCallback callback) {
void mockGetModificationTime(MockTimeCallback? callback) {
_mockTimeCallback = callback;
}

Expand Down
30 changes: 21 additions & 9 deletions pkgs/watcher/test/directory_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,26 @@ void main() {
watcherFactory = (dir) => PollingDirectoryWatcher(dir,
pollingDelay: const Duration(milliseconds: 100));

sharedTests();

test('does not notify if the modification time did not change', () async {
writeFile('a.txt', contents: 'before');
writeFile('b.txt', contents: 'before');
await startWatcher();
writeFile('a.txt', contents: 'after', updateModified: false);
writeFile('b.txt', contents: 'after');
await expectModifyEvent('b.txt');
// Filesystem modification times can be low resolution, mock them.
group('with mock mtime', () {
setUp(enableMockModificationTimes);

sharedTests();

test('does not notify if the modification time did not change', () async {
writeFile('a.txt', contents: 'before');
writeFile('b.txt', contents: 'before');
await startWatcher();
writeFile('a.txt', contents: 'after', updateModified: false);
writeFile('b.txt', contents: 'after');
await expectModifyEvent('b.txt');
});
});

// Also test with delayed writes and real mtimes.
group('with real mtime', () {
setUp(enableWaitingForDifferentModificationTimes);

sharedTests();
});
}
58 changes: 20 additions & 38 deletions pkgs/watcher/test/file_watcher/link_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,25 @@ void linkTests({required bool isNative}) {
test('notifies when a link is overwritten with an identical file', () async {
await startWatcher(path: 'link.txt');
writeFile('link.txt');
await expectModifyEvent('link.txt');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectNoEvents();
} else {
await expectModifyEvent('link.txt');
}
});

test('notifies when a link is overwritten with a different file', () async {
await startWatcher(path: 'link.txt');
writeFile('link.txt', contents: 'modified');
await expectModifyEvent('link.txt');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectNoEvents();
} else {
await expectModifyEvent('link.txt');
}
});

test(
Expand All @@ -35,25 +47,15 @@ void linkTests({required bool isNative}) {
await startWatcher(path: 'link.txt');
writeFile('target.txt');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectModifyEvent('link.txt');
} else {
await expectNoEvents();
}
await expectModifyEvent('link.txt');
},
);

test('notifies when a link target is modified', () async {
await startWatcher(path: 'link.txt');
writeFile('target.txt', contents: 'modified');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectModifyEvent('link.txt');
} else {
await expectNoEvents();
}
await expectModifyEvent('link.txt');
});

test('notifies when a link is removed', () async {
Expand All @@ -79,21 +81,11 @@ void linkTests({required bool isNative}) {

writeFile('target.txt', contents: 'modified');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectModifyEvent('link.txt');
} else {
await expectNoEvents();
}
await expectModifyEvent('link.txt');

writeFile('target.txt', contents: 'modified again');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectModifyEvent('link.txt');
} else {
await expectNoEvents();
}
await expectModifyEvent('link.txt');
});

test('notifies when a link is moved away', () async {
Expand Down Expand Up @@ -145,24 +137,14 @@ void linkTests({required bool isNative}) {
writeFile('old.txt');
renameFile('old.txt', 'target.txt');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectModifyEvent('link.txt');
} else {
await expectNoEvents();
}
await expectModifyEvent('link.txt');
});

test('notifies when a different file is moved over the target', () async {
await startWatcher(path: 'link.txt');
writeFile('old.txt', contents: 'modified');
renameFile('old.txt', 'target.txt');

// TODO(davidmorgan): reconcile differences.
if (isNative) {
await expectModifyEvent('link.txt');
} else {
await expectNoEvents();
}
await expectModifyEvent('link.txt');
});
}
21 changes: 18 additions & 3 deletions pkgs/watcher/test/file_watcher/polling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:test/test.dart';
import 'package:watcher/watcher.dart';

import '../utils.dart';
Expand All @@ -13,7 +14,21 @@ void main() {
watcherFactory = (file) =>
PollingFileWatcher(file, pollingDelay: const Duration(milliseconds: 100));

fileTests(isNative: false);
linkTests(isNative: false);
startupRaceTests(isNative: false);
// Filesystem modification times can be low resolution, mock them.
group('with mock mtime', () {
setUp(enableMockModificationTimes);

fileTests(isNative: false);
linkTests(isNative: false);
startupRaceTests(isNative: false);
});

// Also test with delayed writes and real mtimes.
group('with real mtime', () {
setUp(enableWaitingForDifferentModificationTimes);
fileTests(isNative: false);
linkTests(isNative: false);
// Don't run `startupRaceTests`, polling can't have a race and the test is
// too slow on Windows when waiting for modification times.
});
}
Loading
Loading