2014-07-22 12:55:38 +02:00
|
|
|
/**
|
2017-01-11 16:24:33 +01:00
|
|
|
* Copyright JS Foundation and other contributors, http://js.foundation
|
2014-07-22 12:55:38 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
**/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test simply checks that for every .js file there exists
|
|
|
|
* a *_spec.js file under ./test correspondingly.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Currently we're only checking the core components under ./red
|
|
|
|
* TODO: Increase the scope of this check
|
|
|
|
*/
|
|
|
|
|
2018-01-16 14:15:47 +01:00
|
|
|
var fs = require("fs-extra");
|
2014-07-22 12:55:38 +02:00
|
|
|
var should = require("should");
|
2014-09-10 10:30:16 +02:00
|
|
|
var path = require('path');
|
2014-07-22 12:55:38 +02:00
|
|
|
|
2014-09-10 10:30:16 +02:00
|
|
|
// Directories to check with .js files and _spec.js files respectively
|
2018-01-16 14:15:47 +01:00
|
|
|
var rootdir = path.resolve(__dirname, "..");
|
2014-09-10 10:30:16 +02:00
|
|
|
var jsdir = path.resolve(__dirname, "../red");
|
|
|
|
var testdir = path.resolve(__dirname, "red");
|
2014-07-22 12:55:38 +02:00
|
|
|
|
2018-01-16 14:15:47 +01:00
|
|
|
var walkDirectory = function(dir) {
|
|
|
|
var p = fs.readdir(dir);
|
|
|
|
var errors = [];
|
|
|
|
return p.then(function(list) {
|
|
|
|
var promises = [];
|
|
|
|
list.forEach(function(file) {
|
|
|
|
var filePath = path.join(dir,file);
|
|
|
|
promises.push(fs.stat(filePath).then(function(stat){
|
|
|
|
if (stat.isDirectory()) {
|
|
|
|
return walkDirectory(filePath).then(function(results) {
|
|
|
|
if (results) {
|
|
|
|
errors = errors.concat(results);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (/\.js$/.test(filePath)) {
|
|
|
|
var testFile = filePath.replace(jsdir, testdir).replace(".js", "_spec.js");
|
|
|
|
return fs.exists(testFile).then(function(exists) {
|
|
|
|
if (!exists) {
|
|
|
|
errors.push(testFile.substring(rootdir.length+1));
|
|
|
|
} else {
|
|
|
|
return fs.stat(testFile).then(function(stat) {
|
|
|
|
if (stat.size === 0) {
|
|
|
|
errors.push("[empty] "+testFile.substring(rootdir.length+1));
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
2018-01-16 14:15:47 +01:00
|
|
|
})
|
2014-08-28 01:35:07 +02:00
|
|
|
}
|
2018-01-16 14:15:47 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
return Promise.all(promises).then(function() {
|
|
|
|
return errors;
|
|
|
|
})
|
2014-07-22 12:55:38 +02:00
|
|
|
});
|
2018-01-16 14:15:47 +01:00
|
|
|
}
|
2014-07-22 12:55:38 +02:00
|
|
|
|
|
|
|
describe('_spec.js', function() {
|
|
|
|
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) {
|
2018-01-16 14:15:47 +01:00
|
|
|
walkDirectory(jsdir).then(function(errors) {
|
|
|
|
if (errors.length > 0) {
|
|
|
|
var error = new Error("Missing/empty _spec files:\n\t"+errors.join("\n\t"));
|
|
|
|
done(error);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
2014-07-22 12:55:38 +02:00
|
|
|
});
|
|
|
|
});
|