-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,95 @@ | ||
/* jshint -W097 */// jshint strict:false | ||
/*jslint node: true */ | ||
var expect = require('chai').expect; | ||
var fs = require('fs'); | ||
/* jshint -W097 */ | ||
/* jshint strict:false */ | ||
/* jslint node: true */ | ||
/* jshint expr: true */ | ||
'use strict'; | ||
|
||
describe('Test package.json and io-package.json', function() { | ||
it('Test package files', function (done) { | ||
var fileContentIOPackage = fs.readFileSync(__dirname + '/../io-package.json'); | ||
var ioPackage = JSON.parse(fileContentIOPackage); | ||
const expect = require('chai').expect; | ||
const fs = require('fs'); | ||
|
||
var fileContentNPMPackage = fs.readFileSync(__dirname + '/../package.json'); | ||
var npmPackage = JSON.parse(fileContentNPMPackage); | ||
describe('Test package.json and io-package.json', () => { | ||
it('Test package files', done => { | ||
console.log(); | ||
|
||
const fileContentIOPackage = fs.readFileSync(__dirname + '/../io-package.json', 'utf8'); | ||
const ioPackage = JSON.parse(fileContentIOPackage); | ||
|
||
const fileContentNPMPackage = fs.readFileSync(__dirname + '/../package.json', 'utf8'); | ||
const npmPackage = JSON.parse(fileContentNPMPackage); | ||
|
||
expect(ioPackage).to.be.an('object'); | ||
expect(npmPackage).to.be.an('object'); | ||
|
||
expect(ioPackage.common.version).to.exist; | ||
expect(npmPackage.version).to.exist; | ||
expect(ioPackage.common.version, 'ERROR: Version number in io-package.json needs to exist').to.exist; | ||
expect(npmPackage.version, 'ERROR: Version number in package.json needs to exist').to.exist; | ||
|
||
if (!expect(ioPackage.common.version).to.be.equal(npmPackage.version)) { | ||
console.log('ERROR: Version numbers in package.json and io-package.json differ!!'); | ||
} | ||
expect(ioPackage.common.version, 'ERROR: Version numbers in package.json and io-package.json needs to match').to.be.equal(npmPackage.version); | ||
|
||
if (!ioPackage.common.news || !ioPackage.common.news[ioPackage.common.version]) { | ||
console.log('WARNING: No news entry for current version exists in io-package.json, no rollback in Admin possible!'); | ||
console.log(); | ||
} | ||
|
||
expect(npmPackage.author, 'ERROR: Author in package.json needs to exist').to.exist; | ||
expect(ioPackage.common.authors, 'ERROR: Authors in io-package.json needs to exist').to.exist; | ||
|
||
expect(ioPackage.common.license, 'ERROR: License missing in io-package in common.license').to.exist; | ||
|
||
if (ioPackage.common.name.indexOf('template') !== 0) { | ||
if (Array.isArray(ioPackage.common.authors)) { | ||
expect(ioPackage.common.authors.length, 'ERROR: Author in io-package.json needs to be set').to.not.be.equal(0); | ||
if (ioPackage.common.authors.length === 1) { | ||
expect(ioPackage.common.authors[0], 'ERROR: Author in io-package.json needs to be a real name').to.not.be.equal('my Name <[email protected]>'); | ||
} | ||
} | ||
else { | ||
expect(ioPackage.common.authors, 'ERROR: Author in io-package.json needs to be a real name').to.not.be.equal('my Name <[email protected]>'); | ||
} | ||
} | ||
else { | ||
console.log('WARNING: Testing for set authors field in io-package skipped because template adapter'); | ||
console.log(); | ||
} | ||
expect(fs.existsSync(__dirname + '/../README.md'), 'ERROR: README.md needs to exist! Please create one with description, detail information and changelog. English is mandatory.').to.be.true; | ||
if (!ioPackage.common.titleLang || typeof ioPackage.common.titleLang !== 'object') { | ||
console.log('WARNING: titleLang is not existing in io-package.json. Please add'); | ||
console.log(); | ||
} | ||
if ( | ||
ioPackage.common.title.indexOf('iobroker') !== -1 || | ||
ioPackage.common.title.indexOf('ioBroker') !== -1 || | ||
ioPackage.common.title.indexOf('adapter') !== -1 || | ||
ioPackage.common.title.indexOf('Adapter') !== -1 | ||
) { | ||
console.log('WARNING: title contains Adapter or ioBroker. It is clear anyway, that it is adapter for ioBroker.'); | ||
console.log(); | ||
} | ||
|
||
if (!ioPackage.common.controller && !ioPackage.common.onlyWWW && !ioPackage.common.noConfig) { | ||
if (!ioPackage.common.materialize || !fs.existsSync(__dirname + '/../admin/index_m.html') || !fs.existsSync(__dirname + '/../gulpfile.js')) { | ||
console.log('WARNING: Admin3 support is missing! Please add it'); | ||
console.log(); | ||
} | ||
if (ioPackage.common.materialize) { | ||
expect(fs.existsSync(__dirname + '/../admin/index_m.html'), 'Admin3 support is enabled in io-package.json, but index_m.html is missing!').to.be.true; | ||
} | ||
} | ||
|
||
const licenseFileExists = fs.existsSync(__dirname + '/../LICENSE'); | ||
const fileContentReadme = fs.readFileSync(__dirname + '/../README.md', 'utf8'); | ||
if (fileContentReadme.indexOf('## Changelog') === -1) { | ||
console.log('Warning: The README.md should have a section ## Changelog'); | ||
console.log(); | ||
} | ||
expect((licenseFileExists || fileContentReadme.indexOf('## License') !== -1), 'A LICENSE must exist as LICENSE file or as part of the README.md').to.be.true; | ||
if (!licenseFileExists) { | ||
console.log('Warning: The License should also exist as LICENSE file'); | ||
console.log(); | ||
} | ||
if (fileContentReadme.indexOf('## License') === -1) { | ||
console.log('Warning: The README.md should also have a section ## License to be shown in Admin3'); | ||
console.log(); | ||
} | ||
done(); | ||
}); | ||
}); |