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

Commit e00c0ea

Browse files
authored
Add/enable Windows tests (#124)
1 parent f76997a commit e00c0ea

File tree

6 files changed

+57
-6
lines changed

6 files changed

+57
-6
lines changed

test/directory_watcher/shared.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ void sharedTests() {
134134

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

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

282285
test('emits events for many nested files added at once', () async {

test/directory_watcher/windows_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ import '../utils.dart';
1414
void main() {
1515
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);
1616

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

2321
test('DirectoryWatcher creates a WindowsDirectoryWatcher on Windows', () {
2422
expect(DirectoryWatcher('.'), TypeMatcher<WindowsDirectoryWatcher>());
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
@TestOn('windows')
6+
7+
import 'package:test/test.dart';
8+
import 'package:watcher/src/directory_watcher/windows.dart';
9+
10+
import 'shared.dart';
11+
import '../utils.dart';
12+
13+
void main() {
14+
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);
15+
16+
sharedTests();
17+
}

test/ready/shared.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,21 @@ void sharedTests() {
2121
expect(ready, isFalse);
2222

2323
// Subscribe to the events.
24-
watcher.events.listen((event) {});
24+
var subscription = watcher.events.listen((event) {});
2525

2626
await watcher.ready;
2727

2828
// Should eventually be ready.
2929
expect(watcher.isReady, isTrue);
30+
31+
await subscription.cancel();
3032
});
3133

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

3537
// Subscribe to the events.
36-
watcher.events.listen((event) {});
38+
var subscription = watcher.events.listen((event) {});
3739

3840
// Allow watcher to become ready
3941
await watcher.ready;
@@ -43,6 +45,8 @@ void sharedTests() {
4345
watcher.ready.timeout(Duration(milliseconds: 0),
4446
onTimeout: () => throw 'Does not complete immedately'),
4547
completes);
48+
49+
await subscription.cancel();
4650
});
4751

4852
test('ready returns a future that does not complete after unsubscribing',

test/ready/windows_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
@TestOn('windows')
6+
7+
import 'package:test/test.dart';
8+
import 'package:watcher/src/directory_watcher/windows.dart';
9+
10+
import 'shared.dart';
11+
import '../utils.dart';
12+
13+
void main() {
14+
watcherFactory = (dir) => WindowsDirectoryWatcher(dir);
15+
16+
sharedTests();
17+
}

test/utils.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ Watcher createWatcher({String? path}) {
4848
/// The stream of events from the watcher started with [startWatcher].
4949
late StreamQueue<WatchEvent> _watcherEvents;
5050

51+
/// Whether the event stream has been closed.
52+
///
53+
/// If this is not done by a test (by calling [startClosingEventStream]) it will
54+
/// be done automatically via [addTearDown] in [startWatcher].
55+
var _hasClosedStream = true;
56+
5157
/// Creates a new [Watcher] that watches a temporary file or directory and
5258
/// starts monitoring it for events.
5359
///
@@ -70,6 +76,10 @@ Future<void> startWatcher({String? path}) async {
7076
_watcherEvents = StreamQueue(watcher.events);
7177
// Forces a subscription to the underlying stream.
7278
unawaited(_watcherEvents.hasNext);
79+
80+
_hasClosedStream = false;
81+
addTearDown(startClosingEventStream);
82+
7383
await watcher.ready;
7484
}
7585

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

0 commit comments

Comments
 (0)