1 | var fs = require('fs'),
|
2 | lib = require('./lib'),
|
3 | watch = require('./lib/watch'),
|
4 | wrench = require('wrench');
|
5 |
|
6 | if (!watch.canWatch()) {
|
7 |
|
8 | return;
|
9 | }
|
10 |
|
11 | function runWatchTest(srcdir, config, operations, expectedFiles, expectedDir, done) {
|
12 | var options = {packageConfigFile: 'config/dev.json', expectedDir: expectedDir};
|
13 |
|
14 | watch.runWatchTest.call(this, srcdir, config, operations, expectedFiles, options, done);
|
15 | }
|
16 |
|
17 | describe('watch integration', function() {
|
18 | var mock;
|
19 | beforeEach(function() {
|
20 | mock = watch.mockWatch();
|
21 | });
|
22 | afterEach(function() {
|
23 | mock.cleanup();
|
24 | });
|
25 |
|
26 | it('should watch script files', function(done) {
|
27 | this.timeout(15000);
|
28 |
|
29 | var expectedFiles = [
|
30 | '/android/native-home.js', '/android/native-home.css', '/android/native-home@1.5x.css',
|
31 | '/iphone/native-home.js', '/iphone/native-home.css', '/iphone/native-home@2x.css',
|
32 | '/web/base.js', '/web/base.css', '/web/base@2x.css', '/web/home.js', '/web/home.css', '/web/home@2x.css',
|
33 | '/web/index.html', '/web/web-file.txt',
|
34 | '/iphone/index.html', '/iphone/iphone-file.txt',
|
35 | '/android/index.html', '/android/android-file.txt',
|
36 | '/android/native-home.js', '/android/native-home.css', '/android/native-home@1.5x.css',
|
37 | '/iphone/native-home.js', '/iphone/native-home.css', '/iphone/native-home@2x.css',
|
38 | '/web/base.js', '/web/base.css', '/web/base@2x.css', '/web/home.js', '/web/home.css', '/web/home@2x.css',
|
39 | '/web/index.html', '/web/web-file.txt',
|
40 | '/iphone/index.html', '/iphone/iphone-file.txt',
|
41 | '/android/index.html', '/android/android-file.txt',
|
42 | '/android/native-home.js', '/iphone/native-home.js',
|
43 | '/web/web-file.txt', '/iphone/iphone-file.txt', '/android/android-file.txt',
|
44 | '/android/native-home.js', '/iphone/native-home.js',
|
45 | '/web/web-file.txt', '/iphone/iphone-file.txt', '/android/android-file.txt',
|
46 | '/android/native-home.js', '/iphone/native-home.js', '/web/home.js'
|
47 | ],
|
48 | operations = {
|
49 | 18: function(testdir) {
|
50 |
|
51 | watch.appendSpaceSync(testdir + 'lumbar.json');
|
52 | mock.trigger('change', testdir + 'lumbar.json');
|
53 | },
|
54 | 36: function(testdir) {
|
55 |
|
56 | watch.appendSpaceSync(testdir + 'js/bridge.js');
|
57 | mock.trigger('change', testdir + 'js/bridge.js');
|
58 | },
|
59 | 41: function(testdir) {
|
60 | watch.appendSpaceSync(testdir + 'js/bridge.js');
|
61 | watch.appendSpaceSync(testdir + 'js/bridge-iphone.js');
|
62 | mock.trigger('change', testdir + 'js/bridge-iphone.js');
|
63 | mock.trigger('change', testdir + 'js/bridge.js');
|
64 | },
|
65 | 46: function(testdir) {
|
66 |
|
67 | watch.appendSpaceSync(testdir + 'templates/home/home.handlebars');
|
68 | mock.trigger('change', testdir + 'templates/home/home.handlebars');
|
69 | }
|
70 | };
|
71 |
|
72 | runWatchTest.call(this,
|
73 | 'test/example', 'lumbar.json',
|
74 | operations, expectedFiles, 'test/expected/example',
|
75 | done);
|
76 | });
|
77 |
|
78 | it('should watch style files', function(done) {
|
79 | var expectedFiles = [
|
80 | '/iphone/native.css', '/iphone/base.css', '/iphone/home.css', '/web/base.css', '/web/home.css',
|
81 | '/iphone/native.css', '/iphone/base.css', '/iphone/home.css', '/web/base.css', '/web/home.css',
|
82 | '/iphone/native.css', '/iphone/base.css', '/web/base.css',
|
83 | '/iphone/native.css', '/iphone/base.css', '/web/base.css'
|
84 | ],
|
85 | operations = {
|
86 | 5: function(testdir) {
|
87 | watch.appendSpaceSync(testdir + 'styles.json');
|
88 | mock.trigger('change', testdir + 'styles.json');
|
89 | },
|
90 | 10: function(testdir) {
|
91 | watch.appendSpaceSync(testdir + 'styles/base.css');
|
92 | mock.trigger('change', testdir + 'styles/base.css');
|
93 | },
|
94 | 13: function(testdir) {
|
95 | watch.appendSpaceSync(testdir + 'styles/base.css');
|
96 | watch.appendSpaceSync(testdir + 'styles/iphone.css');
|
97 | mock.trigger('change', testdir + 'styles/base.css');
|
98 | mock.trigger('change', testdir + 'styles/iphone.css');
|
99 | }
|
100 | };
|
101 |
|
102 | runWatchTest.call(this,
|
103 | 'test/artifacts', 'styles.json',
|
104 | operations, expectedFiles, 'test/expected/styles-watch',
|
105 | done);
|
106 | });
|
107 |
|
108 | it('should watch stylus files', function(done) {
|
109 | this.timeout(15000);
|
110 |
|
111 | var expectedFiles = [
|
112 | '/iphone/base.css', '/iphone/base@2x.css', '/web/base.css',
|
113 | '/iphone/base.css', '/iphone/base@2x.css', '/web/base.css',
|
114 | '/iphone/base.css', '/iphone/base@2x.css',
|
115 | '/iphone/base.css', '/iphone/base@2x.css', '/web/base.css'
|
116 | ],
|
117 | operations = {
|
118 | 3: function(testdir) {
|
119 | watch.appendSpaceSync(testdir + 'stylus.json');
|
120 | mock.trigger('change', testdir + 'stylus.json');
|
121 | },
|
122 | 6: function(testdir) {
|
123 | watch.appendSync(testdir + 'styles/iphone.styl', '\nfoo\n bar 1');
|
124 | mock.trigger('change', testdir + 'styles/iphone.styl');
|
125 | },
|
126 | 8: function(testdir) {
|
127 | watch.appendSpaceSync(testdir + 'styles/base.styl');
|
128 | watch.appendSpaceSync(testdir + 'styles/iphone.styl');
|
129 | mock.trigger('change', testdir + 'styles/base.styl');
|
130 | mock.trigger('change', testdir + 'styles/iphone.styl');
|
131 | }
|
132 | };
|
133 |
|
134 | runWatchTest.call(this,
|
135 | 'test/artifacts', 'stylus.json',
|
136 | operations, expectedFiles, 'test/expected/stylus-watch',
|
137 | done);
|
138 | });
|
139 |
|
140 | it('should watch directories', function(done) {
|
141 | var expectedFiles = [
|
142 | '/base.js', '/base.js'
|
143 | ],
|
144 | operations = {
|
145 | 1: function(testdir) {
|
146 | watch.appendSpaceSync(testdir + 'js/iphone.js');
|
147 | mock.trigger('change', testdir + 'js/iphone.js');
|
148 | }
|
149 | };
|
150 |
|
151 | runWatchTest.call(this,
|
152 | 'test/artifacts', 'single-directory.json',
|
153 | operations, expectedFiles, 'test/expected/watch-dir',
|
154 | done);
|
155 | });
|
156 |
|
157 | it('should watch added files', function(done) {
|
158 | var expectedFiles = [
|
159 | '/base.js', '/base.js'
|
160 | ],
|
161 | operations = {
|
162 | 1: function(testdir) {
|
163 | fs.writeFileSync(testdir + 'js/home/home2.js', ' ');
|
164 | mock.trigger('change', testdir + 'js/home');
|
165 | }
|
166 | };
|
167 |
|
168 | runWatchTest.call(this,
|
169 | 'test/artifacts', 'single-directory.json',
|
170 | operations, expectedFiles, 'test/expected/watch-add',
|
171 | done);
|
172 | });
|
173 |
|
174 | it('should watch removed files', function(done) {
|
175 | this.timeout(15000);
|
176 |
|
177 | var expectedFiles = [
|
178 | '/base.js', '/base.js'
|
179 | ],
|
180 | operations = {
|
181 | 1: function(testdir) {
|
182 | fs.unlinkSync(testdir + 'js/home/home.js');
|
183 | mock.trigger('remove', testdir + 'js/home/home.js');
|
184 | }
|
185 | };
|
186 |
|
187 | runWatchTest.call(this,
|
188 | 'test/artifacts', 'single-directory.json',
|
189 | operations, expectedFiles, 'test/expected/watch-remove',
|
190 | done);
|
191 | });
|
192 | });
|