1 | 'use strict';
|
2 |
|
3 | var Path = require('path');
|
4 | var expect = require('unexpected').clone();
|
5 | var baconize = require('../');
|
6 | var rimraf = require('rimraf');
|
7 | var when = require('when');
|
8 | var nodefn = require('when/node');
|
9 | var fs = nodefn.liftAll(require('fs'));
|
10 |
|
11 | function getPathIn(path) {
|
12 | return Path.join(process.cwd(), 'examples/site', path || '');
|
13 | }
|
14 |
|
15 | function getPathOut(path) {
|
16 | return Path.join(process.cwd(), 'examples/output', path || '');
|
17 | }
|
18 |
|
19 | describe('baconize', function() {
|
20 |
|
21 | var clearDir = function(cb) {
|
22 | rimraf(getPathOut(), cb);
|
23 | };
|
24 |
|
25 | describe('compile', function() {
|
26 |
|
27 | before(clearDir);
|
28 | after(clearDir);
|
29 |
|
30 | it('should compile compilable files and copy all others', function () {
|
31 | var options = {
|
32 | blacklist: ['dont-compile/**'],
|
33 | directoryFilter: ['!dont-copy'],
|
34 | compile: true,
|
35 | sourcemaps: false
|
36 | };
|
37 | var bacon = baconize(getPathIn(), getPathOut(), options);
|
38 |
|
39 | var dirs = [];
|
40 | bacon.events.on('chdir', function(dir) { dirs.push(dir); });
|
41 |
|
42 | var compiledFiles = [];
|
43 | var lastStartedFile;
|
44 | bacon.events.on('compile-start', function(file) {
|
45 | lastStartedFile = file.path;
|
46 | });
|
47 | bacon.events.on('compile-done', function(file) {
|
48 | if (lastStartedFile === file.path) {
|
49 | compiledFiles.push(file.path);
|
50 | } else {
|
51 | expect.fail('Unexpected compile-done event');
|
52 | }
|
53 | });
|
54 |
|
55 | return bacon.then(function(num) {
|
56 | return expect.promise.all([
|
57 | expect(num, 'to be', 9),
|
58 | expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4),
|
59 | expect(compiledFiles, 'to contain',
|
60 | 'index.jade', 'scripts/main.coffee', 'styles/main.styl', 'scripts/log.babel.js'
|
61 | )
|
62 | .and('not to contain', 'about.html', 'styles/typography.css')
|
63 | .and('to have length', 4)
|
64 | ]);
|
65 | });
|
66 | });
|
67 |
|
68 | describe('after compilation', function() {
|
69 |
|
70 | it('should have all compiled files', function() {
|
71 | return when.all([
|
72 | fs.readFile(getPathOut('index.html')),
|
73 | fs.readFile(getPathOut('styles/main.css')),
|
74 | fs.readFile(getPathOut('scripts/main.js')),
|
75 | fs.readFile(getPathOut('scripts/iterate.js')),
|
76 | fs.readFile(getPathOut('about.html')),
|
77 | fs.readFile(getPathOut('dont-compile/foo.coffee')),
|
78 | fs.readFile(getPathOut('styles/typography.css')),
|
79 | fs.readFile(getPathOut('scripts/log.js'))
|
80 | ]).then(function(results) {
|
81 | return expect.promise.all([
|
82 | expect(results[0].toString(), 'to contain', 'saying \'hello\'.\n'),
|
83 | expect(results[1].toString(), 'to contain', 'body {'),
|
84 | expect(results[2].toString(), 'to contain', 'console.log("H'),
|
85 | expect(results[3].toString(), 'to contain', 'for (var i = 0; i < stuff.length; i++) {'),
|
86 | expect(results[4].toString(), 'to contain', ' <head>'),
|
87 | expect(results[5].toString(), 'to contain', 'console.log "T'),
|
88 | expect(results[6].toString(), 'to contain', ' font-family: arial;'),
|
89 | expect(results[7].toString(), 'to contain', 'var foo = function foo() {')
|
90 | ]);
|
91 | });
|
92 | });
|
93 |
|
94 | it('should not copy pre-compiled files', function() {
|
95 | return fs.readFile(getPathOut('index.jade'))
|
96 | .then(function() {
|
97 | return expect.fail('`index.jade` should not be copied');
|
98 | }, function(err) {
|
99 | return expect(err.code, 'to be', 'ENOENT');
|
100 | });
|
101 | });
|
102 |
|
103 | it('should not compile blacklist matches', function() {
|
104 | return fs.readFile(getPathOut('dont-compile/foo.js'))
|
105 | .then(function() {
|
106 | return expect.fail('`dont-compile/foo.js` should not be copied');
|
107 | }, function(err) {
|
108 | return expect(err.code, 'to be', 'ENOENT');
|
109 | });
|
110 | });
|
111 |
|
112 | it('should not copy ignore paths', function() {
|
113 | return fs.stat(getPathOut('dont-copy'))
|
114 | .then(function() {
|
115 | return expect.fail('`dont-copy` directory should not be copied');
|
116 | }, function(err) {
|
117 | return expect(err.code, 'to be', 'ENOENT');
|
118 | });
|
119 | });
|
120 |
|
121 | });
|
122 | });
|
123 |
|
124 | describe('compile with sourcemaps', function() {
|
125 |
|
126 | before(clearDir);
|
127 | after(clearDir);
|
128 |
|
129 | it('should compile compilable files and copy all others', function () {
|
130 | var options = {
|
131 | blacklist: ['dont-compile/**'],
|
132 | directoryFilter: ['!dont-copy'],
|
133 | compile: true,
|
134 | sourcemaps: true
|
135 | };
|
136 | var bacon = baconize(getPathIn(), getPathOut(), options);
|
137 |
|
138 | var dirs = [];
|
139 | bacon.events.on('chdir', function(dir) { dirs.push(dir); });
|
140 |
|
141 | var compiledFiles = [];
|
142 | var lastStartedFile;
|
143 | bacon.events.on('compile-start', function(file) {
|
144 | lastStartedFile = file.path;
|
145 | });
|
146 | bacon.events.on('compile-done', function(file) {
|
147 | if (lastStartedFile === file.path) {
|
148 | compiledFiles.push(file.path);
|
149 | } else {
|
150 | expect.fail('Unexpected compile-done event');
|
151 | }
|
152 | });
|
153 |
|
154 | return bacon.then(function(num) {
|
155 | return expect.promise.all([
|
156 | expect(num, 'to be', 9),
|
157 | expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4),
|
158 | expect(compiledFiles, 'to contain',
|
159 | 'index.jade', 'scripts/main.coffee', 'styles/main.styl', 'scripts/log.babel.js'
|
160 | )
|
161 | .and('not to contain', 'about.html', 'styles/typography.css', 'styles/typography.css')
|
162 | .and('to have length', 4)
|
163 | ]);
|
164 | });
|
165 | });
|
166 |
|
167 | describe('after compilation', function() {
|
168 |
|
169 | it('should have all compiled files', function() {
|
170 | return when.all([
|
171 | fs.readFile(getPathOut('index.html')),
|
172 | fs.readFile(getPathOut('styles/main.css')),
|
173 | fs.readFile(getPathOut('scripts/main.js')),
|
174 | fs.readFile(getPathOut('scripts/iterate.js')),
|
175 | fs.readFile(getPathOut('about.html')),
|
176 | fs.readFile(getPathOut('dont-compile/foo.coffee')),
|
177 | fs.readFile(getPathOut('styles/typography.css'))
|
178 | ]).then(function(results) {
|
179 | return expect.promise.all([
|
180 | expect(results[0].toString(), 'to contain', 'saying \'hello\'.\n'),
|
181 | expect(results[1].toString(), 'to contain', 'body {'),
|
182 | expect(results[2].toString(), 'to contain', 'console.log("H'),
|
183 | expect(results[3].toString(), 'to contain', 'for (var i = 0; i < stuff.length; i++) {'),
|
184 | expect(results[4].toString(), 'to contain', ' <head>'),
|
185 | expect(results[5].toString(), 'to contain', 'console.log "T'),
|
186 | expect(results[6].toString(), 'to contain', ' font-family: arial;')
|
187 | ]);
|
188 | });
|
189 | });
|
190 |
|
191 | it('should URL link to source maps', function() {
|
192 | return when.all([
|
193 | fs.readFile(getPathOut('styles/main.css')),
|
194 | fs.readFile(getPathOut('scripts/main.js')),
|
195 | ]).then(function(results) {
|
196 | return expect.promise.all([
|
197 | expect(results[0].toString(), 'to contain', '/*# sourceMappingURL=main.css.map*/'),
|
198 | expect(results[1].toString(), 'to contain', '//# sourceMappingURL=main.js.map'),
|
199 | ]);
|
200 | });
|
201 | });
|
202 |
|
203 | it('should have source maps', function() {
|
204 | return when.all([
|
205 | fs.readFile(getPathOut('styles/main.css.map')),
|
206 | fs.readFile(getPathOut('scripts/main.js.map')),
|
207 | ]).then(function(results) {
|
208 | return expect.promise.all([
|
209 | expect(results[0].toString(), 'to contain', '"file":"main.css"')
|
210 | .and('to contain', '"sources":["main.styl"]'),
|
211 | expect(results[1].toString(), 'to contain', '"file":"main.js"')
|
212 | .and('to contain', '"sources":["main.coffee"]'),
|
213 | ]);
|
214 | });
|
215 | });
|
216 |
|
217 | it('should copy pre-compiled source files', function() {
|
218 | return fs.readFile(getPathOut('index.jade')).then(function(results) {
|
219 | return expect(results.toString(), 'to contain', 'html(lang="en")');
|
220 | });
|
221 | });
|
222 |
|
223 | it('should not compile blacklist matches', function() {
|
224 | return fs.readFile(getPathOut('dont-compile/foo.js'))
|
225 | .then(function() {
|
226 | return expect.fail('`dont-compile/foo.js` should not be copied');
|
227 | }, function(err) {
|
228 | return expect(err.code, 'to be', 'ENOENT');
|
229 | });
|
230 | });
|
231 |
|
232 | it('should not copy ignore paths', function() {
|
233 | return fs.stat(getPathOut('dont-copy'))
|
234 | .then(function() {
|
235 | return expect.fail('`dont-copy` directory should not be copied');
|
236 | }, function(err) {
|
237 | return expect(err.code, 'to be', 'ENOENT');
|
238 | });
|
239 | });
|
240 |
|
241 | });
|
242 | });
|
243 |
|
244 |
|
245 | describe('compile minified', function() {
|
246 |
|
247 | before(clearDir);
|
248 | after(clearDir);
|
249 |
|
250 | it('should compile compilable files and copy all others', function () {
|
251 | var options = {
|
252 | blacklist: ['dont-compile/**'],
|
253 | directoryFilter: ['!dont-copy'],
|
254 | compile: true,
|
255 | sourcemaps: false,
|
256 | minify: true
|
257 | };
|
258 | var bacon = baconize(getPathIn(), getPathOut(), options);
|
259 |
|
260 | var dirs = [];
|
261 | bacon.events.on('chdir', function(dir) { dirs.push(dir); });
|
262 |
|
263 | var compiledFiles = [];
|
264 | var lastStartedFile;
|
265 | bacon.events.on('compile-start', function(file) {
|
266 | lastStartedFile = file.path;
|
267 | });
|
268 | bacon.events.on('compile-done', function(file) {
|
269 | if (lastStartedFile === file.path) {
|
270 | compiledFiles.push(file.path);
|
271 | } else {
|
272 | expect.fail('Unexpected compile-done event');
|
273 | }
|
274 | });
|
275 |
|
276 |
|
277 | return bacon.then(function(num) {
|
278 | return expect.promise.all([
|
279 | expect(num, 'to be', 9),
|
280 | expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4),
|
281 | expect(compiledFiles, 'to contain',
|
282 | 'about.html', 'index.jade', 'scripts/log.babel.js',
|
283 | 'styles/main.styl', 'styles/typography.css',
|
284 | 'scripts/iterate.js', 'scripts/main.coffee').and('to have length', 7),
|
285 | ]);
|
286 | });
|
287 | });
|
288 |
|
289 | describe('after compilation', function() {
|
290 |
|
291 | it('should have all compiled files', function() {
|
292 | return when.all([
|
293 | fs.readFile(getPathOut('index.html')),
|
294 | fs.readFile(getPathOut('styles/main.css')),
|
295 | fs.readFile(getPathOut('scripts/main.js')),
|
296 | fs.readFile(getPathOut('scripts/iterate.js')),
|
297 | fs.readFile(getPathOut('about.html')),
|
298 | fs.readFile(getPathOut('dont-compile/foo.coffee')),
|
299 | fs.readFile(getPathOut('styles/typography.css'))
|
300 | ]).then(function(results) {
|
301 | return expect.promise.all([
|
302 | expect(results[0].toString(), 'to contain', 'saying \'hello\'.</p>'),
|
303 | expect(results[1].toString(), 'to contain', 'body{'),
|
304 | expect(results[2].toString(), 'to contain', 'console.log("H'),
|
305 | expect(results[3].toString(), 'to contain', 'for(var stuff=[1,2,3,4,5]'),
|
306 | expect(results[4].toString(), 'to contain', '<html><head>'),
|
307 | expect(results[5].toString(), 'to contain', 'console.log "T'),
|
308 | expect(results[6].toString(), 'to contain', 'font-family:arial}')
|
309 | ]);
|
310 | });
|
311 | });
|
312 |
|
313 | it('should not copy pre-compiled files', function() {
|
314 | return fs.readFile(getPathOut('index.jade'))
|
315 | .then(function() {
|
316 | return expect.fail('`index.jade` should not be copied');
|
317 | }, function(err) {
|
318 | return expect(err.code, 'to be', 'ENOENT');
|
319 | });
|
320 | });
|
321 |
|
322 | it('should not compile blacklist matches', function() {
|
323 | return fs.readFile(getPathOut('dont-compile/foo.js'))
|
324 | .then(function() {
|
325 | return expect.fail('`dont-compile/foo.js` should not be copied');
|
326 | }, function(err) {
|
327 | return expect(err.code, 'to be', 'ENOENT');
|
328 | });
|
329 | });
|
330 |
|
331 | it('should not copy ignore paths', function() {
|
332 | return fs.stat(getPathOut('dont-copy'))
|
333 | .then(function() {
|
334 | return expect.fail('`dont-copy` directory should not be copied');
|
335 | }, function(err) {
|
336 | return expect(err.code, 'to be', 'ENOENT');
|
337 | });
|
338 | });
|
339 |
|
340 | });
|
341 | });
|
342 |
|
343 | describe('compile minified with sourcemaps', function() {
|
344 |
|
345 | before(clearDir);
|
346 |
|
347 |
|
348 | it('should compile compilable files and copy all others', function () {
|
349 | var options = {
|
350 | blacklist: ['dont-compile/**'],
|
351 | directoryFilter: ['!dont-copy'],
|
352 | compile: true,
|
353 | minify: true,
|
354 | sourcemaps: true
|
355 | };
|
356 | var bacon = baconize(getPathIn(), getPathOut(), options);
|
357 |
|
358 | var dirs = [];
|
359 | bacon.events.on('chdir', function(dir) { dirs.push(dir); });
|
360 |
|
361 | var compiledFiles = [];
|
362 | var lastStartedFile;
|
363 | bacon.events.on('compile-start', function(file) {
|
364 | lastStartedFile = file.path;
|
365 | });
|
366 | bacon.events.on('compile-done', function(file) {
|
367 | if (lastStartedFile === file.path) {
|
368 | compiledFiles.push(file.path);
|
369 | } else {
|
370 | expect.fail('Unexpected compile-done event');
|
371 | }
|
372 | });
|
373 |
|
374 |
|
375 | return bacon.then(function(num) {
|
376 | return expect.promise.all([
|
377 | expect(num, 'to be', 9),
|
378 | expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4),
|
379 | expect(compiledFiles, 'to contain',
|
380 | 'about.html', 'index.jade', 'scripts/log.babel.js',
|
381 | 'styles/main.styl', 'styles/typography.css',
|
382 | 'scripts/iterate.js', 'scripts/main.coffee').and('to have length', 7),
|
383 | ]);
|
384 | });
|
385 | });
|
386 |
|
387 | describe('after compilation', function() {
|
388 |
|
389 | it('should have all compiled files', function() {
|
390 | return when.all([
|
391 | fs.readFile(getPathOut('index.html')),
|
392 | fs.readFile(getPathOut('styles/main.css')),
|
393 | fs.readFile(getPathOut('scripts/main.js')),
|
394 | fs.readFile(getPathOut('scripts/iterate.js')),
|
395 | fs.readFile(getPathOut('about.html')),
|
396 | fs.readFile(getPathOut('dont-compile/foo.coffee')),
|
397 | fs.readFile(getPathOut('styles/typography.css'))
|
398 | ]).then(function(results) {
|
399 | return expect.promise.all([
|
400 | expect(results[0].toString(), 'to contain', 'saying \'hello\'.</p>'),
|
401 | expect(results[1].toString(), 'to contain', 'body{'),
|
402 | expect(results[2].toString(), 'to contain', 'console.log("H'),
|
403 | expect(results[3].toString(), 'to contain', 'for(var stuff=[1,2,3,4,5]'),
|
404 | expect(results[4].toString(), 'to contain', '<html><head>'),
|
405 | expect(results[5].toString(), 'to contain', 'console.log "T'),
|
406 | expect(results[6].toString(), 'to contain', 'font-family:arial}')
|
407 | ]);
|
408 | });
|
409 | });
|
410 |
|
411 | it('should URL link to source maps', function() {
|
412 | return when.all([
|
413 | fs.readFile(getPathOut('styles/main.css')),
|
414 | fs.readFile(getPathOut('scripts/main.js')),
|
415 | fs.readFile(getPathOut('scripts/iterate.js')),
|
416 | fs.readFile(getPathOut('styles/typography.css'))
|
417 |
|
418 | ]).then(function(results) {
|
419 | return expect.promise.all([
|
420 | expect(results[0].toString(), 'to contain', '/*# sourceMappingURL=main.css.map*/'),
|
421 | expect(results[1].toString(), 'to contain', '//# sourceMappingURL=main.js.map'),
|
422 | expect(results[2].toString(), 'to contain', '//# sourceMappingURL=iterate.js.map'),
|
423 | expect(results[3].toString(), 'to contain', '/*# sourceMappingURL=typography.css.map*/')
|
424 |
|
425 | ]);
|
426 | });
|
427 | });
|
428 |
|
429 | it('should have source maps', function() {
|
430 | return when.all([
|
431 | fs.readFile(getPathOut('styles/main.css.map')),
|
432 | fs.readFile(getPathOut('scripts/main.js.map')),
|
433 | fs.readFile(getPathOut('scripts/iterate.js.map')),
|
434 | fs.readFile(getPathOut('styles/typography.css.map'))
|
435 | ]).then(function(results) {
|
436 | return expect.promise.all([
|
437 | expect(results[0].toString(), 'to contain', '"file":"main.css"')
|
438 | .and('to contain', '"sources":["main.styl"]'),
|
439 | expect(results[1].toString(), 'to contain', '"file":"main.js"')
|
440 | .and('to contain', '"sources":["main.coffee"]'),
|
441 | expect(results[2].toString(), 'to contain', '"file":"iterate.js"')
|
442 | .and('to contain', '"sources":["iterate.src.js"]'),
|
443 | expect(results[3].toString(), 'to contain', '"file":"typography.css"')
|
444 | .and('to contain', '"sources":["typography.src.css"]'),
|
445 | ]);
|
446 | });
|
447 | });
|
448 |
|
449 | it('should copy pre-compiled source files', function() {
|
450 | return when.all([
|
451 | fs.readFile(getPathOut('index.jade')),
|
452 | fs.readFile(getPathOut('about.src.html')),
|
453 | fs.readFile(getPathOut('scripts/iterate.src.js')),
|
454 | fs.readFile(getPathOut('styles/typography.src.css'))
|
455 | ]).then(function(results) {
|
456 | return expect.promise.all([
|
457 | expect(results[0].toString(), 'to contain', 'html(lang="en")'),
|
458 | expect(results[1].toString(), 'to contain', ' <meta charset="utf-8">'),
|
459 | expect(results[2].toString(), 'to contain', 'for (var i = 0; i < stuff.length; i++) {'),
|
460 | expect(results[3].toString(), 'to contain', ' font-family: arial;')
|
461 | ]);
|
462 | });
|
463 | });
|
464 |
|
465 | it('should not compile blacklist matches', function() {
|
466 | return fs.readFile(getPathOut('dont-compile/foo.js'))
|
467 | .then(function() {
|
468 | return expect.fail('`dont-compile/foo.js` should not be copied');
|
469 | }, function(err) {
|
470 | return expect(err.code, 'to be', 'ENOENT');
|
471 | });
|
472 | });
|
473 |
|
474 | it('should not copy ignore paths', function() {
|
475 | return fs.stat(getPathOut('dont-copy'))
|
476 | .then(function() {
|
477 | return expect.fail('`dont-copy` directory should not be copied');
|
478 | }, function(err) {
|
479 | return expect(err.code, 'to be', 'ENOENT');
|
480 | });
|
481 | });
|
482 |
|
483 | });
|
484 | });
|
485 |
|
486 |
|
487 | describe('compile minified with sourcemaps (SHA test)', function() {
|
488 | var originalCoffeeContents;
|
489 | before(() => {
|
490 |
|
491 | var styl = fs.readFile(getPathOut('styles/main.css'), 'utf8').then(content =>
|
492 | fs.writeFile(getPathOut('styles/main.css'), content + ' ')
|
493 | );
|
494 | var html = fs.unlink(getPathOut('index.html'));
|
495 | var randomFile = fs.writeFile(getPathOut('bla.html'), 'SHOULD BE REMOVED');
|
496 |
|
497 |
|
498 | var coffee = fs.readFile(getPathIn('scripts/main.coffee'), 'utf8').then(content => {
|
499 | originalCoffeeContents = content;
|
500 | return fs.writeFile(getPathIn('scripts/main.coffee'), content + ' ');
|
501 | });
|
502 |
|
503 | return when.all([styl, html, randomFile, coffee]);
|
504 | });
|
505 |
|
506 | after(done => {
|
507 | var coffee = fs.writeFile(getPathIn('scripts/main.coffee'), originalCoffeeContents);
|
508 | coffee.then(() => {
|
509 | clearDir(done);
|
510 | });
|
511 | });
|
512 |
|
513 |
|
514 | it('should compile compilable files and copy all others', function () {
|
515 | var options = {
|
516 | blacklist: ['dont-compile/**'],
|
517 | directoryFilter: ['!dont-copy'],
|
518 | compile: true,
|
519 | minify: true,
|
520 | sourcemaps: true
|
521 | };
|
522 | var bacon = baconize(getPathIn(), getPathOut(), options);
|
523 |
|
524 | var dirs = [];
|
525 | bacon.events.on('chdir', function(dir) { dirs.push(dir); });
|
526 |
|
527 | var compiledFiles = [];
|
528 | var compilationReuseFiles = [];
|
529 | var lastStartedFile;
|
530 | bacon.events.on('compile-start', function(file) {
|
531 | lastStartedFile = file.path;
|
532 | });
|
533 | bacon.events.on('compile-done', function(file) {
|
534 | if (lastStartedFile === file.path) {
|
535 | compiledFiles.push(file.path);
|
536 | } else {
|
537 | expect.fail('Unexpected compile-done event');
|
538 | }
|
539 | });
|
540 | bacon.events.on('compile-reuse', function(file) {
|
541 | compilationReuseFiles.push(file.path);
|
542 | });
|
543 |
|
544 |
|
545 | return bacon.then(function(num) {
|
546 | return expect.promise.all([
|
547 | expect(num, 'to be', 9),
|
548 | expect(dirs, 'to contain', '', 'dont-compile', 'scripts', 'styles').and('to have length', 4),
|
549 | expect(compiledFiles, 'to contain',
|
550 | 'index.jade', 'styles/main.styl', 'scripts/main.coffee').and('to have length', 3),
|
551 | expect(compilationReuseFiles, 'to contain',
|
552 | 'about.html', 'scripts/log.babel.js', 'styles/typography.css',
|
553 | 'scripts/iterate.js').and('to have length', 4),
|
554 | ]);
|
555 | });
|
556 | });
|
557 |
|
558 | describe('after compilation', function() {
|
559 |
|
560 | it('should have all compiled files', function() {
|
561 | return when.all([
|
562 | fs.readFile(getPathOut('index.html')),
|
563 | fs.readFile(getPathOut('styles/main.css')),
|
564 | fs.readFile(getPathOut('scripts/main.js')),
|
565 | fs.readFile(getPathOut('scripts/iterate.js')),
|
566 | fs.readFile(getPathOut('about.html')),
|
567 | fs.readFile(getPathOut('dont-compile/foo.coffee')),
|
568 | fs.readFile(getPathOut('styles/typography.css'))
|
569 | ]).then(function(results) {
|
570 | return expect.promise.all([
|
571 | expect(results[0].toString(), 'to contain', 'saying \'hello\'.</p>'),
|
572 | expect(results[1].toString(), 'to contain', 'body{'),
|
573 | expect(results[2].toString(), 'to contain', 'console.log("H'),
|
574 | expect(results[3].toString(), 'to contain', 'for(var stuff=[1,2,3,4,5]'),
|
575 | expect(results[4].toString(), 'to contain', '<html><head>'),
|
576 | expect(results[5].toString(), 'to contain', 'console.log "T'),
|
577 | expect(results[6].toString(), 'to contain', 'font-family:arial}')
|
578 | ]);
|
579 | });
|
580 | });
|
581 |
|
582 | it('should URL link to source maps', function() {
|
583 | return when.all([
|
584 | fs.readFile(getPathOut('styles/main.css')),
|
585 | fs.readFile(getPathOut('scripts/main.js')),
|
586 | fs.readFile(getPathOut('scripts/iterate.js')),
|
587 | fs.readFile(getPathOut('styles/typography.css'))
|
588 |
|
589 | ]).then(function(results) {
|
590 | return expect.promise.all([
|
591 | expect(results[0].toString(), 'to contain', '/*# sourceMappingURL=main.css.map*/'),
|
592 | expect(results[1].toString(), 'to contain', '//# sourceMappingURL=main.js.map'),
|
593 | expect(results[2].toString(), 'to contain', '//# sourceMappingURL=iterate.js.map'),
|
594 | expect(results[3].toString(), 'to contain', '/*# sourceMappingURL=typography.css.map*/')
|
595 |
|
596 | ]);
|
597 | });
|
598 | });
|
599 |
|
600 | it('should have source maps', function() {
|
601 | return when.all([
|
602 | fs.readFile(getPathOut('styles/main.css.map')),
|
603 | fs.readFile(getPathOut('scripts/main.js.map')),
|
604 | fs.readFile(getPathOut('scripts/iterate.js.map')),
|
605 | fs.readFile(getPathOut('styles/typography.css.map'))
|
606 | ]).then(function(results) {
|
607 | return expect.promise.all([
|
608 | expect(results[0].toString(), 'to contain', '"file":"main.css"')
|
609 | .and('to contain', '"sources":["main.styl"]'),
|
610 | expect(results[1].toString(), 'to contain', '"file":"main.js"')
|
611 | .and('to contain', '"sources":["main.coffee"]'),
|
612 | expect(results[2].toString(), 'to contain', '"file":"iterate.js"')
|
613 | .and('to contain', '"sources":["iterate.src.js"]'),
|
614 | expect(results[3].toString(), 'to contain', '"file":"typography.css"')
|
615 | .and('to contain', '"sources":["typography.src.css"]'),
|
616 | ]);
|
617 | });
|
618 | });
|
619 |
|
620 | it('should copy pre-compiled source files', function() {
|
621 | return when.all([
|
622 | fs.readFile(getPathOut('index.jade')),
|
623 | fs.readFile(getPathOut('about.src.html')),
|
624 | fs.readFile(getPathOut('scripts/iterate.src.js')),
|
625 | fs.readFile(getPathOut('styles/typography.src.css'))
|
626 | ]).then(function(results) {
|
627 | return expect.promise.all([
|
628 | expect(results[0].toString(), 'to contain', 'html(lang="en")'),
|
629 | expect(results[1].toString(), 'to contain', ' <meta charset="utf-8">'),
|
630 | expect(results[2].toString(), 'to contain', 'for (var i = 0; i < stuff.length; i++) {'),
|
631 | expect(results[3].toString(), 'to contain', ' font-family: arial;')
|
632 | ]);
|
633 | });
|
634 | });
|
635 |
|
636 | it('should not compile blacklist matches', function() {
|
637 | return fs.readFile(getPathOut('dont-compile/foo.js'))
|
638 | .then(function() {
|
639 | return expect.fail('`dont-compile/foo.js` should not be copied');
|
640 | }, function(err) {
|
641 | return expect(err.code, 'to be', 'ENOENT');
|
642 | });
|
643 | });
|
644 |
|
645 | it('should not copy ignore paths', function() {
|
646 | return fs.stat(getPathOut('dont-copy'))
|
647 | .then(function() {
|
648 | return expect.fail('`dont-copy` directory should not be copied');
|
649 | }, function(err) {
|
650 | return expect(err.code, 'to be', 'ENOENT');
|
651 | });
|
652 | });
|
653 |
|
654 | it('should remove files that weren\'t in src dir', function() {
|
655 | return fs.readFile(getPathOut('bla.html'))
|
656 | .then(function() {
|
657 | return expect.fail(
|
658 | '`bla.html` should *not* be copied because it\'s not in src directory'
|
659 | );
|
660 | }, function(err) {
|
661 | return expect(err.code, 'to be', 'ENOENT');
|
662 | });
|
663 | });
|
664 |
|
665 | });
|
666 | });
|
667 |
|
668 | describe('aborted compile', function() {
|
669 |
|
670 | before(clearDir);
|
671 | after(clearDir);
|
672 |
|
673 | it('should abort during compile process', function () {
|
674 | var options = {
|
675 | blacklist: ['dont-compile/**'],
|
676 | directoryFilter: ['!dont-copy'],
|
677 | compile: true,
|
678 | sourcemaps: false
|
679 | };
|
680 | var bacon = baconize(getPathIn(), getPathOut(), options);
|
681 |
|
682 | setTimeout(function() { bacon.abort(); }, 10);
|
683 |
|
684 | return bacon.then(function() {
|
685 | return expect.fail('Baconize should not have completed, should have been aborted');
|
686 | }, function(err) {
|
687 | return expect(err.code, 'to be', 'ABORT');
|
688 | });
|
689 | });
|
690 |
|
691 | describe('after aborted compilation', function() {
|
692 |
|
693 | it('should have removed all files', function() {
|
694 | return when.all(fs.readdir(getPathOut())).then(function() {
|
695 | return expect.fail('Output dir should not exist after abort');
|
696 | }, function(err) {
|
697 | return expect(err.code, 'to be', 'ENOENT');
|
698 | });
|
699 | });
|
700 |
|
701 | });
|
702 |
|
703 | });
|
704 |
|
705 | });
|