'use strict';


// stdlib
var fs    = require('fs');
var path  = require('path');


// mincer
var mincer  = require('../..');


////////////////////////////////////////////////////////////////////////////////


var ASSETS_ROOT = path.join(__dirname, 'assets');


function report(message, test) {
  console.log('[' + (test ? ' OK ' : 'FAIL') + '] ' + message);
}


function write(file, text) {
  fs.writeFileSync(path.join(ASSETS_ROOT, file), text);
}


////////////////////////////////////////////////////////////////////////////////


var env = new (mincer.Environment)(__dirname);


// append assets path
env.appendPath('assets');


// create assets dir if needed
if (!fs.existsSync(ASSETS_ROOT)) {
  fs.mkdirSync(ASSETS_ROOT);
}


// write dummy asset
write('foo.js', '/*' + Date.now() + '*/\n//= require bar');
write('bar.js', '/*' + Date.now() + '*/');


env.findAsset('foo').compile(function () {
  report('foo should be fresh', env.findAsset('foo').isFresh(env));

  write('bar.js', '/*' + Date.now() + '*/');
  report('foo should be stale', !env.findAsset('foo').isFresh(env));

  env.findAsset('foo').compile(function () {
    report('foo should be fresh', env.findAsset('foo').isFresh(env));

    write('foo.js', '/*' + Date.now() + '*/\n//= require bar');
    report('foo should be stale', !env.findAsset('foo').isFresh(env));
  });
});

@@ -965,16 +965,45 @@
 env));%0A%0A
+  setTimeout(function () %7B%0A  
   write(
@@ -1039,16 +1039,18 @@
  '*/');%0A
+  
   report
@@ -1111,16 +1111,18 @@
 env));%0A%0A
+  
   env.fi
@@ -1158,24 +1158,26 @@
 on () %7B%0A    
+ 
+ 
 report('foo 
@@ -1227,24 +1227,26 @@
 esh(env));%0A%0A
+  
     write('f
@@ -1293,32 +1293,34 @@
 uire bar');%0A    
+  
 report('foo shou
@@ -1372,16 +1372,30 @@
 nv));%0A  
+ 
-%7D
+ %7D);%0A  %7D, 1234
 );%0A%7D);%0A

Fix issue #13 test