mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
update package schema, and add tests to validate package objects against the schema (#788)
This commit is contained in:
parent
53d2ed719b
commit
5512af9677
@ -571,18 +571,95 @@ var DOCLET_SCHEMA = exports.DOCLET_SCHEMA = {
|
||||
}
|
||||
};
|
||||
|
||||
var CONTACT_INFO_SCHEMA = exports.CONTACT_INFO_SCHEMA = {
|
||||
type: OBJECT,
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
email: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
},
|
||||
name: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
},
|
||||
url: {
|
||||
type: STRING,
|
||||
optional: true,
|
||||
format: 'uri'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var BUGS_SCHEMA = exports.BUGS_SCHEMA = {
|
||||
type: OBJECT,
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
email: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
},
|
||||
url: {
|
||||
type: STRING,
|
||||
optional: true,
|
||||
format: 'uri'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var PACKAGE_SCHEMA = exports.PACKAGE_SCHEMA = {
|
||||
type: OBJECT,
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
author: {
|
||||
anyOf: [STRING, CONTACT_INFO_SCHEMA],
|
||||
optional: true
|
||||
},
|
||||
bugs: {
|
||||
anyOf: [STRING, BUGS_SCHEMA],
|
||||
optional: true
|
||||
},
|
||||
contributors: {
|
||||
type: ARRAY,
|
||||
optional: true,
|
||||
minItems: 0,
|
||||
items: {
|
||||
anyOf: [STRING, CONTACT_INFO_SCHEMA]
|
||||
}
|
||||
},
|
||||
dependencies: {
|
||||
type: OBJECT,
|
||||
optional: true
|
||||
},
|
||||
description: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
},
|
||||
devDependencies: {
|
||||
type: OBJECT,
|
||||
optional: true
|
||||
},
|
||||
engines: {
|
||||
type: OBJECT,
|
||||
optional: true
|
||||
},
|
||||
files: {
|
||||
type: ARRAY,
|
||||
uniqueItems: true,
|
||||
minItems: 1,
|
||||
minItems: 0,
|
||||
items: {
|
||||
type: STRING
|
||||
}
|
||||
},
|
||||
homepage: {
|
||||
type: STRING,
|
||||
optional: true,
|
||||
format: 'uri'
|
||||
},
|
||||
keywords: {
|
||||
type: ARRAY,
|
||||
optional: true,
|
||||
minItems: 0,
|
||||
items: {
|
||||
type: STRING
|
||||
}
|
||||
@ -616,10 +693,30 @@ var PACKAGE_SCHEMA = exports.PACKAGE_SCHEMA = {
|
||||
optional: true,
|
||||
pattern: PACKAGE_REGEXP
|
||||
},
|
||||
main: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
},
|
||||
name: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
},
|
||||
repository: {
|
||||
type: OBJECT,
|
||||
optional: true,
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
type: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
},
|
||||
// we don't use `format: 'uri'` here because repo URLs are atypical
|
||||
url: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
},
|
||||
version: {
|
||||
type: STRING,
|
||||
optional: true
|
||||
|
||||
@ -24,7 +24,18 @@ var jasmineNode = ( require('./reporter') )(jasmine);
|
||||
|
||||
var reporter = null;
|
||||
|
||||
jasmine.parseResults = [];
|
||||
var parseResults = [];
|
||||
|
||||
jasmine.addParseResults = function(filename, doclets) {
|
||||
parseResults.push({
|
||||
filename: filename,
|
||||
doclets: doclets
|
||||
});
|
||||
};
|
||||
|
||||
jasmine.getParseResults = function() {
|
||||
return parseResults;
|
||||
};
|
||||
|
||||
// use the requested parser, or default to Esprima (on Node.js) or Rhino (on Rhino)
|
||||
jasmine.jsParser = (function() {
|
||||
@ -151,10 +162,7 @@ jasmine.getDocSetFromFile = function(filename, parser, validate) {
|
||||
|
||||
// store the parse results for later validation
|
||||
if (validate !== false) {
|
||||
jasmine.parseResults.push({
|
||||
filename: filename,
|
||||
doclets: doclets
|
||||
});
|
||||
jasmine.addParseResults(filename, doclets);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/*global beforeEach, describe, expect, it, spyOn */
|
||||
/*global beforeEach, describe, expect, it, jasmine, spyOn */
|
||||
'use strict';
|
||||
|
||||
var hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
@ -15,6 +15,9 @@ describe('jsdoc/package', function() {
|
||||
|
||||
obj[name] = value;
|
||||
myPackage = new Package( JSON.stringify(obj) );
|
||||
// add the package object to the cached parse results, so we can validate it against the
|
||||
// doclet schema
|
||||
jasmine.addParseResults('package-property-' + name + '.js', [myPackage]);
|
||||
|
||||
// use toEqual so we can test array/object values
|
||||
expect(myPackage[name]).toEqual(value);
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
/*global describe: true, expect: true, it: true, jasmine: true */
|
||||
/*global describe, expect, it, jasmine */
|
||||
'use strict';
|
||||
|
||||
describe('jsdoc/schema', function() {
|
||||
var schema = require('jsdoc/schema');
|
||||
|
||||
@ -7,6 +9,16 @@ describe('jsdoc/schema', function() {
|
||||
expect(typeof schema).toBe('object');
|
||||
});
|
||||
|
||||
it('should export a "BUGS_SCHEMA" object', function() {
|
||||
expect(schema.BUGS_SCHEMA).toBeDefined();
|
||||
expect(typeof schema.BUGS_SCHEMA).toBe('object');
|
||||
});
|
||||
|
||||
it('should export a "CONTACT_INFO_SCHEMA" object', function() {
|
||||
expect(schema.CONTACT_INFO_SCHEMA).toBeDefined();
|
||||
expect(typeof schema.CONTACT_INFO_SCHEMA).toBe('object');
|
||||
});
|
||||
|
||||
it('should export a "DOCLET_SCHEMA" object', function() {
|
||||
expect(schema.DOCLET_SCHEMA).toBeDefined();
|
||||
expect(typeof schema.DOCLET_SCHEMA).toBe('object');
|
||||
@ -57,7 +69,7 @@ describe('jsdoc/schema', function() {
|
||||
});
|
||||
|
||||
it('should not find any validation errors in the JSDoc parse results', function() {
|
||||
jasmine.parseResults.forEach(function(doclets) {
|
||||
jasmine.getParseResults().forEach(function(doclets) {
|
||||
var validationResult;
|
||||
validationResult = validate(doclets.doclets, schema.DOCLETS_SCHEMA);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user