| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, 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 import 'dart:async'; | |
| 6 | |
| 7 import 'package:scheduled_test/scheduled_test.dart'; | |
| 8 import 'package:watcher/watcher.dart'; | |
| 9 | |
| 10 import '../utils.dart'; | |
| 11 | |
| 12 void sharedTests() { | |
| 13 test('does not notify for changes when there are no subscribers', () { | |
| 14 // Note that this test doesn't rely as heavily on the test functions in | |
| 15 // utils.dart because it needs to be very explicit about when the event | |
| 16 // stream is and is not subscribed. | |
| 17 var watcher = createWatcher(); | |
| 18 | |
| 19 // Subscribe to the events. | |
| 20 var completer = new Completer(); | |
| 21 var subscription = watcher.events.listen(wrapAsync((event) { | |
| 22 expect(event, isWatchEvent(ChangeType.ADD, "file.txt")); | |
| 23 completer.complete(); | |
| 24 })); | |
| 25 | |
| 26 writeFile("file.txt"); | |
| 27 | |
| 28 // Then wait until we get an event for it. | |
| 29 schedule(() => completer.future); | |
| 30 | |
| 31 // Unsubscribe. | |
| 32 schedule(() { | |
| 33 subscription.cancel(); | |
| 34 }); | |
| 35 | |
| 36 // Now write a file while we aren't listening. | |
| 37 writeFile("unwatched.txt"); | |
| 38 | |
| 39 // Then start listening again. | |
| 40 schedule(() { | |
| 41 completer = new Completer(); | |
| 42 subscription = watcher.events.listen(wrapAsync((event) { | |
| 43 // We should get an event for the third file, not the one added while | |
| 44 // we weren't subscribed. | |
| 45 expect(event, isWatchEvent(ChangeType.ADD, "added.txt")); | |
| 46 completer.complete(); | |
| 47 })); | |
| 48 | |
| 49 // Wait until the watcher is ready to dispatch events again. | |
| 50 return watcher.ready; | |
| 51 }); | |
| 52 | |
| 53 // And add a third file. | |
| 54 writeFile("added.txt"); | |
| 55 | |
| 56 // Wait until we get an event for the third file. | |
| 57 schedule(() => completer.future); | |
| 58 | |
| 59 schedule(() { | |
| 60 subscription.cancel(); | |
| 61 }); | |
| 62 }); | |
| 63 } | |
| OLD | NEW |