test: use unlinkSync; validate file exists before unlinking

Sometimes tests fail because the file does not exist (it was possibly not created due to unrelated failure?); Async unlinking might also be causing unnecessary restarts (sometimes test fail with "`done` called twice")
This commit is contained in:
Dominykas Blyžė
2017-12-18 15:16:20 +02:00
committed by Remy Sharp
parent 84ec156ed0
commit 70a2ec7f3d
4 changed files with 30 additions and 12 deletions

View File

@@ -11,7 +11,6 @@ var assert = require('assert'),
path = require('path'),
touch = require('touch'),
crypto = require('crypto'),
noop = function () {},
baseFilename = 'test/fixtures/test' + crypto.randomBytes(16).toString('hex');
describe('nodemon fork child restart', function () {
@@ -20,9 +19,15 @@ describe('nodemon fork child restart', function () {
tmpcoffee = path.resolve(baseFilename + '.coffee');
after(function () {
fs.unlink(tmpjs, noop);
fs.unlink(tmpmd, noop);
fs.unlink(tmpcoffee, noop);
if (fs.existsSync(tmpjs)) {
fs.unlinkSync(tmpjs);
}
if (fs.existsSync(tmpjs)) {
fs.unlinkSync(tmpmd);
}
if (fs.existsSync(tmpjs)) {
fs.unlinkSync(tmpcoffee);
}
});
/* removed test due to CoffeeScript using depreciate customFds - failing tests */

View File

@@ -54,7 +54,9 @@ function ignore(rule, done, file) {
describe('nodemon ignore', function () {
after(function (done) {
files.forEach(function (file) {
fs.unlink(file, function () { });
if (fs.existsSync(file)) {
fs.unlinkSync(file);
}
});
done();
});

View File

@@ -13,9 +13,15 @@ function rnd() {
describe('when nodemon runs (2)', function () {
var tmp = path.resolve('test/fixtures/test' + rnd() + '.js');
var tmp2 = path.resolve('test/fixtures/test' + rnd() + '-added.js');
after(function (done) {
fs.unlink(tmp, function () { });
if (fs.existsSync(tmp)) {
fs.unlinkSync(tmp);
}
if (fs.existsSync(tmp2)) {
fs.unlinkSync(tmp2);
}
// clean up just in case.
nodemon.once('exit', function () {
nodemon.reset();
@@ -29,7 +35,6 @@ describe('when nodemon runs (2)', function () {
it('should restart when new files are added', function (done) {
fs.writeFileSync(tmp, 'setTimeout(function(){}, 10000)');
var tmp2 = path.resolve('test/fixtures/test' + rnd() + '-added.js');
nodemon({
script: tmp,
@@ -38,8 +43,11 @@ describe('when nodemon runs (2)', function () {
fs.writeFileSync(tmp2, 'setTimeout(function(){}, 10000)');
}, 500);
}).on('restart', function () {
assert(true, 'restarted after new file was added');
nodemon.once('exit', done).emit('quit');
assert(fs.existsSync(tmp2), 'restarted after new file was added');
nodemon.once('exit', function () {
nodemon.reset();
done();
}).emit('quit');
});
});

View File

@@ -29,9 +29,12 @@ describe('nodemon monitor child restart', function () {
});
after(function (done) {
fs.unlink(tmpjs);
fs.unlink(tmpmd);
// clean up just in case.
if (fs.existsSync(tmpjs)) {
fs.unlinkSync(tmpjs);
}
if (fs.existsSync(tmpmd)) {
fs.unlinkSync(tmpmd);
}
nodemon.once('exit', function () {
nodemon.reset();
done();