Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dart-archive/watcher
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f76997a
Choose a base ref
..
head repository: dart-archive/watcher
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: e00c0ea
Choose a head ref
Showing with 57 additions and 6 deletions.
  1. +4 −1 test/directory_watcher/shared.dart
  2. +1 −3 test/directory_watcher/windows_test.dart
  3. +17 −0 test/no_subscription/windows_test.dart
  4. +6 −2 test/ready/shared.dart
  5. +17 −0 test/ready/windows_test.dart
  6. +12 −0 test/utils.dart
5 changes: 4 additions & 1 deletion test/directory_watcher/shared.dart
Original file line number Diff line number Diff line change
@@ -134,6 +134,8 @@ void sharedTests() {

renameFile('from.txt', 'to.txt');
await inAnyOrder([isRemoveEvent('from.txt'), isModifyEvent('to.txt')]);
}, onPlatform: {
'windows': Skip('https://github.com/dart-lang/watcher/issues/125')
});
});

@@ -276,7 +278,8 @@ void sharedTests() {
isAddEvent('new')
]);
}, onPlatform: {
'mac-os': Skip('https://github.com/dart-lang/watcher/issues/21')
'mac-os': Skip('https://github.com/dart-lang/watcher/issues/21'),
'windows': Skip('https://github.com/dart-lang/watcher/issues/21')
});

test('emits events for many nested files added at once', () async {
4 changes: 1 addition & 3 deletions test/directory_watcher/windows_test.dart
Original file line number Diff line number Diff line change
@@ -14,11 +14,9 @@ import '../utils.dart';
void main() {
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);

// TODO(grouma) - renable when https://github.com/dart-lang/sdk/issues/31760
// is resolved.
group('Shared Tests:', () {
sharedTests();
}, skip: 'SDK issue see - https://github.com/dart-lang/sdk/issues/31760');
});

test('DirectoryWatcher creates a WindowsDirectoryWatcher on Windows', () {
expect(DirectoryWatcher('.'), TypeMatcher<WindowsDirectoryWatcher>());
17 changes: 17 additions & 0 deletions test/no_subscription/windows_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// 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.

@TestOn('windows')

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/windows.dart';

import 'shared.dart';
import '../utils.dart';

void main() {
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);

sharedTests();
}
8 changes: 6 additions & 2 deletions test/ready/shared.dart
Original file line number Diff line number Diff line change
@@ -21,19 +21,21 @@ void sharedTests() {
expect(ready, isFalse);

// Subscribe to the events.
watcher.events.listen((event) {});
var subscription = watcher.events.listen((event) {});

await watcher.ready;

// Should eventually be ready.
expect(watcher.isReady, isTrue);

await subscription.cancel();
});

test('ready completes immediately when already ready', () async {
var watcher = createWatcher();

// Subscribe to the events.
watcher.events.listen((event) {});
var subscription = watcher.events.listen((event) {});

// Allow watcher to become ready
await watcher.ready;
@@ -43,6 +45,8 @@ void sharedTests() {
watcher.ready.timeout(Duration(milliseconds: 0),
onTimeout: () => throw 'Does not complete immedately'),
completes);

await subscription.cancel();
});

test('ready returns a future that does not complete after unsubscribing',
17 changes: 17 additions & 0 deletions test/ready/windows_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// 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.

@TestOn('windows')

import 'package:test/test.dart';
import 'package:watcher/src/directory_watcher/windows.dart';

import 'shared.dart';
import '../utils.dart';

void main() {
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);

sharedTests();
}
12 changes: 12 additions & 0 deletions test/utils.dart
Original file line number Diff line number Diff line change
@@ -48,6 +48,12 @@ Watcher createWatcher({String? path}) {
/// The stream of events from the watcher started with [startWatcher].
late StreamQueue<WatchEvent> _watcherEvents;

/// Whether the event stream has been closed.
///
/// If this is not done by a test (by calling [startClosingEventStream]) it will
/// be done automatically via [addTearDown] in [startWatcher].
var _hasClosedStream = true;

/// Creates a new [Watcher] that watches a temporary file or directory and
/// starts monitoring it for events.
///
@@ -70,6 +76,10 @@ Future<void> startWatcher({String? path}) async {
_watcherEvents = StreamQueue(watcher.events);
// Forces a subscription to the underlying stream.
unawaited(_watcherEvents.hasNext);

_hasClosedStream = false;
addTearDown(startClosingEventStream);

await watcher.ready;
}

@@ -80,6 +90,8 @@ Future<void> startWatcher({String? path}) async {
/// indefinitely because they might in the future and because the watcher is
/// normally only closed after the test completes.
void startClosingEventStream() async {
if (_hasClosedStream) return;
_hasClosedStream = true;
await pumpEventQueue();
await _watcherEvents.cancel(immediate: true);
}