OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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/src/utils.dart'; |
| 9 |
| 10 import '../utils.dart'; |
| 11 |
| 12 void sharedTests() { |
| 13 test("doesn't notify if the file isn't modified", () { |
| 14 startWatcher(path: "file.txt"); |
| 15 // Give the watcher time to fire events if it's going to. |
| 16 schedule(() => pumpEventQueue()); |
| 17 deleteFile("file.txt"); |
| 18 expectRemoveEvent("file.txt"); |
| 19 }); |
| 20 |
| 21 test("notifies when a file is modified", () { |
| 22 startWatcher(path: "file.txt"); |
| 23 writeFile("file.txt", contents: "modified"); |
| 24 expectModifyEvent("file.txt"); |
| 25 }); |
| 26 |
| 27 test("notifies when a file is removed", () { |
| 28 startWatcher(path: "file.txt"); |
| 29 deleteFile("file.txt"); |
| 30 expectRemoveEvent("file.txt"); |
| 31 }); |
| 32 |
| 33 test("notifies when a file is modified multiple times", () { |
| 34 startWatcher(path: "file.txt"); |
| 35 writeFile("file.txt", contents: "modified"); |
| 36 expectModifyEvent("file.txt"); |
| 37 writeFile("file.txt", contents: "modified again"); |
| 38 expectModifyEvent("file.txt"); |
| 39 }); |
| 40 |
| 41 test("notifies even if the file contents are unchanged", () { |
| 42 startWatcher(path: "file.txt"); |
| 43 writeFile("file.txt"); |
| 44 expectModifyEvent("file.txt"); |
| 45 }); |
| 46 |
| 47 test("emits a remove event when the watched file is moved away", () { |
| 48 startWatcher(path: "file.txt"); |
| 49 renameFile("file.txt", "new.txt"); |
| 50 expectRemoveEvent("file.txt"); |
| 51 }); |
| 52 |
| 53 test("emits a modify event when another file is moved on top of the watched " |
| 54 "file", () { |
| 55 writeFile("old.txt"); |
| 56 startWatcher(path: "file.txt"); |
| 57 renameFile("old.txt", "file.txt"); |
| 58 expectModifyEvent("file.txt"); |
| 59 }); |
| 60 |
| 61 // Regression test for a race condition. |
| 62 test("closes the watcher immediately after deleting the file", () { |
| 63 writeFile("old.txt"); |
| 64 var watcher = createWatcher(path: "file.txt", waitForReady: false); |
| 65 var sub = schedule(() => watcher.events.listen(null)); |
| 66 |
| 67 deleteFile("file.txt"); |
| 68 schedule(() async { |
| 69 // Reproducing the race condition will always be flaky, but this sleep |
| 70 // helped it reproduce more consistently on my machine. |
| 71 await new Future.delayed(new Duration(milliseconds: 10)); |
| 72 (await sub).cancel(); |
| 73 }); |
| 74 }); |
| 75 } |
OLD | NEW |