I'm trying to run a test that waits for a promise to be returned, but jasmine is exiting before completing the test, and I can't seem to figure out why.
My tests is
describe("npm packages",function(){
it("should get npm packages", function(){
//remove node passport directory so we can check it gets added
var flag = false;
exec_child_process('rimraf node_modules/passport', function(err){
if(err!==null){
console.log('problem removing passport directory');
} else {
console.log('passport directory removed');
npmInstallPackagePromise();
}
});
function npmInstallPackagePromise(){
mm.installNodeModules()
.then(function(){
fs.readdir('node_modules/passport',function(err){
if(err!==null){
console.log('error reading node module: '+err);
} else {
flag=true;
}
});
});
}
waitsFor(function(){
return flag;
},'resolved promise',6000);
runs(function(){
expect(flag).toBe(true);
});
});
});
and the code the test is running is
module.exports = function(config){
return {
getInstalledNodeModules: function(){
var defer = q.defer();
exec('npm ls --json', function(err,stdout,stderr){
console.log(err);
if(err) return defer.reject(console.log(err));
console.log(stdout);
defer.resolve(stdout);
});
return defer.promise;
},
installNodeModules: function(){
//go through each node module
this.getInstalledNodeModules().then(function(modules_json){
console.log(modules_json);
for(m in config.node_modules){
//check if the module is a local module already
console.log(modules_json[m]);
};
})
}
I know some people say "just use a mock, don't actually check that the files are written", but because I'm running npm via the exec function, I actually want to check that that is running correctly. So please don't offer that as a solution.