Promises swallow errors. In order for them to be thrown, the easiest solution is to end the promise chain with .done()
.
var p = Download.download(list, function(){
var pictures = fs.readdirSync("exports/merge/");
console.log('before assert - '+pictures.length);
assert.equal(pictures.length, 3);
console.log('before done - '+pictures.length);
done();
});
p.done();
See for more information bluebird's documentation or Q's documentation on the subject:
When you get to the end of a chain of promises, you should either return the last promise or end the chain. Since handlers catch errors, it’s an unfortunate pattern that the exceptions can go unobserved. So, either return it or end it.