upm/tests/node/test.js
Nicolas Oliver ef681a0ab5 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>
2017-09-14 17:52:17 -07:00

58 lines
1.6 KiB
JavaScript

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);
});
}
});
});
});