When running the tests just using jasmine "node_modules/.bin/jasmine" "spec\test_spec.js"
the fs.remove
is not called - nothing happens (no error, nothing).
When running tests using jasmine-node "node_modules/.bin/jasmine-node" "spec\test_spec.js"
the fs function is correctly called.
But jasmine-node is not maintained anymore and it should be possible to do everything with just jasmine. Any ideas? Should we run these tests differently?
In describe block we have afterEach which works correctly.
afterEach(function () {
sfnc.deleteProjectFolders(projectName);
});
The fs.remove is not called / nothing happens
...
var fs = require('fs-extra');
...
exports.deleteProjectFolders = function (listOfFolders, pathToRootFolder) {
....
console.log("This is called correctly");
// This is not called - nothing happens
fs.remove(fl, function (err) {
if (err) {
exports.debugLog("Failed to delete folder {},\n Error: {} ".format(
fl, err), true)
}else{
exports.debugLog("Folder {} deleted.".format(fl));
}
});
}
The fs.remove()
is async call. The test has to wait for it to finish. We need to add callback to the afterEach function.
Solution with simple callback:
afterEach(function (done) {
sfnc.deleteProjectFolders(projectName, done);
});
And in the function:
...
var fs = require('fs-extra');
...
exports.deleteProjectFolders = function (listOfFolders, callback) {
....
fs.remove(fl, function (err) {
if (err) {
exports.debugLog("Failed to delete folder {},\n Error: {} ".format(fl, err), true)
}else{
exports.debugLog("Folder {} deleted.".format(fl));
}
callback()
});
}
Or it could be written as promise.