mirror of
https://github.com/eclipse/upm.git
synced 2025-07-03 02:11:15 +03:00
add initial jsonlint and mocha test for json files
[ci skip] Signed-off-by: Nicolas Oliver <dario.n.oliver@intel.com> Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:

committed by
Abhishek Malik

parent
f37236fa01
commit
ef681a0ab5
61
tests/node/jsonlint.js
Normal file
61
tests/node/jsonlint.js
Normal file
@ -0,0 +1,61 @@
|
||||
var shell = require('shelljs');
|
||||
var path = require('path');
|
||||
|
||||
var rootPath = path.resolve(__dirname, '../../');
|
||||
var srcPath = path.resolve(rootPath, 'src');
|
||||
|
||||
var jsonlintCmd = path.resolve(__dirname, 'node_modules/.bin/jsonlint');
|
||||
var jsonlintOpts = ' --quiet ';
|
||||
|
||||
var failures = [];
|
||||
|
||||
function getRelativePath(filePath) {
|
||||
return path.relative(rootPath, filePath);
|
||||
}
|
||||
|
||||
function printSummaryAndExit() {
|
||||
var exitCode = 0;
|
||||
|
||||
if (failures.length > 0) {
|
||||
console.error();
|
||||
console.error('Failures:');
|
||||
failures.forEach(function (file) {
|
||||
console.error(' ', getRelativePath(file));
|
||||
});
|
||||
exitCode = 1;
|
||||
}
|
||||
else {
|
||||
console.log();
|
||||
console.log('Success');
|
||||
}
|
||||
|
||||
process.exit(exitCode);
|
||||
}
|
||||
|
||||
var pending = 0;
|
||||
|
||||
shell.find(srcPath)
|
||||
.filter(function (file) {
|
||||
return file.match(/\.json$/);
|
||||
})
|
||||
.forEach(function (jsonFile) {
|
||||
pending++;
|
||||
var relativePath = getRelativePath(jsonFile);
|
||||
shell.exec(jsonlintCmd + jsonlintOpts + jsonFile, {silent: true}, function (code, stdout, stderr) {
|
||||
if (code) {
|
||||
console.error('Failed', relativePath);
|
||||
console.error(stderr);
|
||||
failures.push(jsonFile);
|
||||
}
|
||||
else {
|
||||
console.log('Success', relativePath);
|
||||
}
|
||||
|
||||
pending--;
|
||||
|
||||
if (pending == 0) {
|
||||
printSummaryAndExit();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user