-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should be able to delete (fs.unlink) a file inside a Mocha test - test passes but file not deleted. why? #1058
Comments
you need to invoke the done callback with async calls like this it('CREATE (temporary) file tests create/write access to FS', function(done){
// setup
var newFile = new Date().getTime() +".txt";
fs.writeFile(newFile, "hello!", function (err) {
if (err) console.log(err);
// console.log("Created file: "+newFile);
fs.readdir(__dirname, function(err, list) {
// console.log(list)
assert.isTrue(list.indexOf(newFile) > -1)
fs.unlinkSync(newFile);
console.log('successfully deleted '+newFile);
// console.log("Deleted: "+newFile)
fs.readdir(__dirname, function(err, list) {
if (err) throw err;
assert.isTrue(list.indexOf(newFile) === -1);
done()
});
});
});
}) |
@travisjeffery, thanks for your prompt reply. |
https://github.com/nelsonic/valens/blob/master/test/test.js#L60 you don't have done as a parameter |
Thanks for replying. |
@nelsonic just glanced at it but __dirname is ./test, you're maybe expecting it to be ./ but __dirname is relative to the script not the CWD |
Changed __dirname to process.cwd() and now tests pass (and temporary file is deleted). |
A simple node filesystem test:
Am I doing something wrong?
It works fine outside of the Mocha test:
I've googled this extensively...
Any insight would be much appreciated.
The text was updated successfully, but these errors were encountered: