mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +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:
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
19
tests/node/package.json
Normal file
19
tests/node/package.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"name": "upm-node-tests",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Node.js tests for UPM",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "npm run jsonlint && npm run mocha",
|
||||||
|
"mocha": "mocha test.js",
|
||||||
|
"jsonlint": "node jsonlint.js"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"devDependencies": {
|
||||||
|
"chai": "^4.1.1",
|
||||||
|
"jsonlint": "^1.6.2",
|
||||||
|
"mocha": "^3.5.0",
|
||||||
|
"shelljs": "^0.7.8"
|
||||||
|
}
|
||||||
|
}
|
57
tests/node/test.js
Normal file
57
tests/node/test.js
Normal 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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user