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 'package:scheduled_test/scheduled_test.dart'; | |
6 | |
7 import 'utils.dart'; | |
8 | |
9 main() { | |
10 initConfig(); | |
11 | |
12 setUp(createSandbox); | |
13 | |
14 test('does not notify for files that already exist when started', () { | |
15 // Make some pre-existing files. | |
16 writeFile("a.txt"); | |
17 writeFile("b.txt"); | |
18 | |
19 createWatcher(); | |
20 | |
21 // Change one after the watcher is running. | |
22 writeFile("b.txt", contents: "modified"); | |
23 | |
24 // We should get a modify event for the changed file, but no add events | |
25 // for them before this. | |
26 expectModifyEvent("b.txt"); | |
27 }); | |
28 | |
29 test('notifies when a file is added', () { | |
30 createWatcher(); | |
31 writeFile("file.txt"); | |
32 expectAddEvent("file.txt"); | |
33 }); | |
34 | |
35 test('notifies when a file is modified', () { | |
36 writeFile("file.txt"); | |
37 createWatcher(); | |
38 writeFile("file.txt", contents: "modified"); | |
39 expectModifyEvent("file.txt"); | |
40 }); | |
41 | |
42 test('notifies when a file is removed', () { | |
43 writeFile("file.txt"); | |
44 createWatcher(); | |
45 deleteFile("file.txt"); | |
46 expectRemoveEvent("file.txt"); | |
47 }); | |
48 | |
49 test('notifies when a file is moved', () { | |
50 writeFile("old.txt"); | |
51 createWatcher(); | |
52 renameFile("old.txt", "new.txt"); | |
53 expectAddEvent("new.txt"); | |
54 expectRemoveEvent("old.txt"); | |
55 }); | |
56 | |
57 test('notifies when a file is modified multiple times', () { | |
58 writeFile("file.txt"); | |
59 createWatcher(); | |
60 writeFile("file.txt", contents: "modified"); | |
61 expectModifyEvent("file.txt"); | |
62 writeFile("file.txt", contents: "modified again"); | |
63 expectModifyEvent("file.txt"); | |
64 }); | |
65 | |
66 test('does not notify if the file contents are unchanged', () { | |
67 writeFile("a.txt", contents: "same"); | |
68 writeFile("b.txt", contents: "before"); | |
69 createWatcher(); | |
70 writeFile("a.txt", contents: "same"); | |
71 writeFile("b.txt", contents: "after"); | |
72 expectModifyEvent("b.txt"); | |
73 }); | |
74 | |
75 test('does not notify if the modification time did not change', () { | |
76 writeFile("a.txt", contents: "before"); | |
77 writeFile("b.txt", contents: "before"); | |
78 createWatcher(); | |
79 writeFile("a.txt", contents: "after", updateModified: false); | |
80 writeFile("b.txt", contents: "after"); | |
81 expectModifyEvent("b.txt"); | |
82 }); | |
83 | |
84 test('watches files in subdirectories', () { | |
85 createWatcher(); | |
86 writeFile("a/b/c/d/file.txt"); | |
87 expectAddEvent("a/b/c/d/file.txt"); | |
88 }); | |
89 | |
90 test('watches a directory created after the watcher', () { | |
91 // Watch a subdirectory that doesn't exist yet. | |
92 createWatcher(dir: "a"); | |
93 | |
94 // This implicity creates it. | |
95 writeFile("a/b/c/d/file.txt"); | |
96 expectAddEvent("a/b/c/d/file.txt"); | |
97 }); | |
98 | |
99 test('when the watched directory is deleted, removes all files', () { | |
100 writeFile("dir/a.txt"); | |
101 writeFile("dir/b.txt"); | |
102 | |
103 createWatcher(dir: "dir"); | |
104 | |
105 deleteDir("dir"); | |
106 expectRemoveEvents(["dir/a.txt", "dir/b.txt"]); | |
107 }); | |
108 } | |
OLD | NEW |