Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/enable Windows tests #124

Merged
merged 8 commits into from
Jan 19, 2022
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
5 changes: 4 additions & 1 deletion test/directory_watcher/shared.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
});

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 1 addition & 3 deletions test/directory_watcher/windows_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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>());
Expand Down
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
Expand Up @@ -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;
Expand All @@ -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',
Expand Down
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
Expand Up @@ -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.
///
Expand All @@ -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;
}

Expand All @@ -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);
}
Expand Down