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

Merge pull request #398 from anna2130/master

Fixed _spec.js test
This commit is contained in:
Nick O'Leary 2014-09-10 09:53:02 +01:00
commit a3497a5fc7

View File

@ -26,54 +26,68 @@
var fs = require("fs"); var fs = require("fs");
var should = require("should"); var should = require("should");
var path = require('path');
var core = "/../red"; // Directories to check with .js files and _spec.js files respectively
var jsdir = path.resolve(__dirname, "../red");
var testdir = path.resolve(__dirname, "red");
/* var fs = require('fs');
* Walk directory and find all .js files. Then check if a corresponding var walkDirectory = function(dir, topdir, done) {
* ./test/*_spec.js file exists. fs.readdir(dir, function(err, list) {
*/ var error;
function walkDirectory(directory, done) { var errReturned = false;
fs.readdir(directory, function(err, list) {
if (err) { if (err) {
return done(err); return done(err);
} }
var i = 0; var i = 0;
function nextEntry() { (function next() {
var file = list[i++]; var file = list[i++];
// return error if there are no more files to check and error has not been previously returned to avoid multiple calls to done()
if (!file) { if (!file) {
return; if (!errReturned) {
errReturned = true;
return done(error);
}
} }
file = directory + '/' + file;
file = path.resolve(dir, file);
fs.stat(file, function(err, stat) { fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) { if (stat && stat.isDirectory()) {
walkDirectory(file, function(err, res) { walkDirectory(file, false, function(err) {
nextEntry(); if (!error) {
error = err;
}
next();
}); });
} else { } else {
if (/\.js$/.test(file)) { if (path.extname(file) === ".js") {
file = file.replace("/../", "/"); var testFile = file.replace(jsdir, testdir).replace(".js", "_spec.js");
file = file.replace(".js", "_spec.js"); fs.exists(testFile, function (exists) {
fs.exists(file, function(exists) {
try { try {
exists.should.equal(true, file + " does not exist"); exists.should.equal(true, testFile + " does not exist");
} catch (err) { } catch (err) {
done(err); if (!topdir) {
return done(err);
} else {
error = err;
return;
}
} }
}); });
} }
nextEntry(); next();
} }
}); });
} })();
nextEntry();
}); });
} };
describe('_spec.js', function() { describe('_spec.js', function() {
this.timeout(50000); // we might not finish within the Mocha default timeout limit, project will also grow this.timeout(50000); // we might not finish within the Mocha default timeout limit, project will also grow
it('is checking if all .js files have a corresponding _spec.js test file.', function(done) { it('is checking if all .js files have a corresponding _spec.js test file.', function(done) {
walkDirectory(__dirname + core, done); walkDirectory(jsdir, true, done);
done();
}); });
}); });