Skip to content
Browse files

multiple files in the cache test now

  • Loading branch information...
1 parent 169e486 commit 388e7c81e1dc184c1637b90fbfc72c64b96886fb @substack committed Nov 15, 2011
Showing with 24 additions and 3 deletions.
  1. +24 −3 test/cache.js
View
27 test/cache.js
@@ -4,6 +4,8 @@ var fs = require('fs');
var crypto = require('crypto');
test('cache with new file', function (t) {
+ t.plan(4);
+
var ps = []; for (var i = 0; i < 10; i++) {
ps.push(Math.floor(Math.random() * (1<<30)).toString(16));
}
@@ -14,22 +16,41 @@ test('cache with new file', function (t) {
[
'require("a"); require("b")',
{ strings : ['a','b'], expressions : [] }
+ ],
+ [
+ 'require("x"); require(x+1)',
+ { strings : [ 'x' ], expressions : [ 'x+1' ] }
]
];
+
t.deepEqual(detective.find(src[0][0]), src[0][1]);
+ setTimeout(firstFile, 100);
- setTimeout(function () {
+ function compareSources (ix, cb) {
fs.readFile(file, function (err, body) {
t.deepEqual(
- src.reduce(function (acc,s) {
+ src.slice(0,ix).reduce(function (acc,s) {
acc[hash(s[0])] = s[1];
return acc;
}, {}),
JSON.parse(body)
);
+ cb();
+ });
+ }
+
+ function firstFile () {
+ compareSources(1, function () {
+ t.deepEqual(detective.find(src[1][0]), src[1][1]);
+ setTimeout(secondFile, 100);
+ });
+ }
+
+ function secondFile () {
+ compareSources(2, function () {
t.end();
});
- }, 100);
+ }
function hash (src) {
return new crypto.Hash('md5').update(src).digest('hex');

0 comments on commit 388e7c8

Please sign in to comment.
Something went wrong with that request. Please try again.