1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #331 from hbeeken/issue-326

Proposed fix for Issue #326
This commit is contained in:
Nick O'Leary 2014-08-07 13:33:57 +01:00
commit c6a98da256
2 changed files with 29 additions and 20 deletions

View File

@ -17,39 +17,47 @@
var should = require("should"); var should = require("should");
var path = require('path'); var path = require('path');
var fs = require('fs-extra'); var fs = require('fs-extra');
var mkdirp = require('mkdirp');
var tailNode = require("../../../../nodes/core/storage/28-tail.js"); var tailNode = require("../../../../nodes/core/storage/28-tail.js");
var helper = require("../../helper.js"); var helper = require("../../helper.js");
describe('TailNode', function() { describe('TailNode', function() {
var tempDir = path.join(__dirname, ".tmp/"); var tempDir = path.join(__dirname, ".tmp");
var fileToTail = path.join(tempDir, "tailMe.txt"); var fileToTail = path.join(tempDir, "tailMe.txt");
// function which writes to the file creating all missing directories
function writeFile(path, contents) {
mkdirp(tempDir, function(err) {
if(err) {
return err;
}
try {
fs.writeFileSync(path, contents, 'utf8');
} catch (error) {
console.log("Unexpected error writing file: " +error.message);
return error;
}
});
}
beforeEach(function(done) { beforeEach(function(done) {
fs.exists(fileToTail, function(exists) { writeFile(fileToTail, "Tail message line1\nTail message line2\n");
if(exists) {
fs.unlinkSync(fileToTail);
}
});
fs.exists(tempDir, function(exists) {
if(!exists) {
fs.mkdirSync(tempDir);
}
fs.writeFileSync(fileToTail, "Tail message line1\nTail message line2\n");
helper.startServer(done); helper.startServer(done);
}); });
});
afterEach(function(done) { afterEach(function(done) {
helper.unload(); helper.unload();
fs.exists(fileToTail, function(exists) { fs.remove(tempDir, function(err) {
if(exists) { if (err) {
fs.unlinkSync(fileToTail); console.log("error occurred removing " + tempDir + ": " +err);
return err;
} }
// have to call stop server otherwise tail node litters test output fs.exists(tempDir, function(exists) {
// with warnings when tailed file gets deleted exists.should.be.false;
fs.remove(tempDir, helper.stopServer(done)); helper.stopServer(done);
});
}); });
}); });

View File

@ -62,6 +62,7 @@ module.exports = {
unload: function() { unload: function() {
// TODO: any other state to remove between tests? // TODO: any other state to remove between tests?
redNodes.clearRegistry(); redNodes.clearRegistry();
flows.stopFlows();
}, },
getNode: function(id) { getNode: function(id) {