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:
Nicolas Oliver
2017-08-16 07:56:02 -07:00
committed by Abhishek Malik
parent f37236fa01
commit ef681a0ab5
3 changed files with 137 additions and 0 deletions

57
tests/node/test.js Normal file
View File

@ -0,0 +1,57 @@
var shell = require('shelljs');
var path = require('path');
var expect = require('chai').expect;
var rootPath = path.resolve(__dirname, '../../');
var srcPath = path.resolve(rootPath, 'src');
var examplePath = path.resolve(rootPath, 'examples');
shell.find(srcPath)
.filter(function (file) {
return file.match(/\.json$/);
})
.forEach(function (jsonFile) {
var relativePath = path.relative(rootPath, jsonFile);
describe(relativePath, function () {
// Check required fields
[
'Library',
'Description',
'Sensor Class'
].forEach(function (fieldName) {
it('should have a ' + fieldName + ' property', function () {
var parsedJsonFile = require(jsonFile);
expect(parsedJsonFile).to.have.property(fieldName);
});
});
// Check Sensor Class required fields
[
'Name',
'Description',
'Aliases',
'Categories',
'Connections',
'Project Type',
'Manufacturers',
'Image',
'Examples',
'Specifications',
'Platforms',
'Urls'
].forEach(function (fieldName) {
var parsedJsonFile = require(jsonFile);
sensorClass = parsedJsonFile['Sensor Class'];
for(var className in sensorClass) {
it(className + ' should have a ' + fieldName + ' property', function () {
var parsedJsonFile = require(jsonFile);
sensorClass = parsedJsonFile['Sensor Class'];
expect(sensorClass[className]).to.have.property(fieldName);
});
}
});
});
});