Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding validation tests

  • Loading branch information...
commit b001565ee5883d87461abda039b900b48908c79f 1 parent 90fb693
@bollwyvl bollwyvl authored
View
2  .gitignore
@@ -1 +1,3 @@
*.swp
+node_modules
+*~
View
2  .npmignore
@@ -0,0 +1,2 @@
+ajax/
+test/
View
5 .travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+ - 0.7
View
25 package.json
@@ -0,0 +1,25 @@
+{
+ "author": "Ryan Kirkman (http://ryankirkman.com)",
+ "name": "cdnjs",
+ "description": "Our goal is to operate this CDN in a peer reviewed fashion.",
+ "version": "0.0.1",
+ "homepage": "http://www.cdnjs.com/",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/cdnjs/cdnjs.git"
+ },
+ "scripts": {
+ "test": "node test/*-test.js"
+ },
+ "dependencies": {},
+ "devDependencies": {
+ "glob": "3.1.9",
+ "jslint": "0.1.8",
+ "vows": "0.6.2",
+ "JSV": "4.0.1"
+ },
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ }
+}
View
12 test/schemata/README.markdown
@@ -0,0 +1,12 @@
+The schemata against which a cdnjs `package.json` will be validated.
+
+These schemata (may) have been copied from:
+
+ https://github.com/exavolt/onde/tree/master/samples/schemas
+
+They need to be updated to be accurate as per the current specs.
+
+All .json files in this directory will be run against all of the
+`package.json` files in the ajax/libs directory, though only one
+will have to be successful: satisfying multiple schema may not
+be possible!
View
104 test/schemata/commonjs-package-1.0.json
@@ -0,0 +1,104 @@
+{
+ "type": "object",
+ "name": "CommonJS Package Descriptor File 1.0",
+ "description": "Note that this is incomplete. See http://wiki.commonjs.org/wiki/Packages/1.0 for the complete spec.",
+ "summaryProperties": ["name", "version"],
+ "properties": {
+ "name": {
+ "type": "string",
+ "required": true,
+ "description": "The name of the package. This must be a unique, lowercase alpha-numeric name without spaces. It may include \".\" or \"_\" or \"-\" characters. It is otherwise opaque."
+ },
+ "description": {
+ "type": "string",
+ "required": true,
+ "format": "multiline",
+ "description": "A brief description of the package. By convention, the first sentence (up to the first \". \") should be usable as a package title in listings."
+ },
+ "version": {
+ "type": "string",
+ "required": true,
+ "format": "semver",
+ "description": "Version string conforming to the Semantic Versioning requirements (http://semver.org/)."
+ },
+ "keywords": {
+ "type": "array",
+ "required": true,
+ "items": { "type": "string" },
+ "description": "An Array of string keywords to assist users searching for the package in catalogs."
+ },
+ "maintainers": {
+ "type": "array",
+ "required": true,
+ "items": {
+ "type": "object",
+ "name": "person",
+ "properties": {
+ "name": { "type": "string", "required": true },
+ "email": { "type": "string" },
+ "web": { "type": "string" }
+ }
+ },
+ "description": "Array of maintainers of the package. Each maintainer is a hash which must have a \"name\" property and may optionally provide \"email\" and \"web\" properties."
+ },
+ "contributors": {
+ "type": "array",
+ "required": true,
+ "items": [{ "type": "string", "name": "person-name" }, {
+ "type": "object",
+ "name": "person",
+ "properties": {
+ "name": { "type": "string", "required": true },
+ "email": { "type": "string" },
+ "web": { "type": "string" }
+ }
+ }],
+ "description": "An Array of hashes each containing the details of a contributor. Format is the same as for author. By convention, the first contributor is the original author of the package."
+ },
+ "bugs": {
+ "type": "object",
+ "additionalProperties": "string",
+ "required": true,
+ "description": "URL for submitting bugs. Can be mailto or http."
+ },
+ "licenses": {
+ "type": "array",
+ "required": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "type": { "type": "string", "required": true },
+ "url": { "type": "string" }
+ }
+ },
+ "description": "Array of licenses under which the package is provided."
+ },
+ "repositories": {
+ "required": true,
+ "description": "Array of repositories where the package can be located.",
+ "type": "array",
+ "items": {
+ "type": "object",
+ "summaryProperties": ["type", "url"],
+ "properties": {
+ "type": { "type": "string", "required": true },
+ "url": { "type": "string", "required": true },
+ "path": { "type": "string", "description": "Specified to locate the package in the repository if it does not reside at the root." }
+ }
+ }
+ },
+ "dependencies": {
+ "required": true,
+ "description": "Prerequisite packages on which this package depends in order to install and run.",
+ "type": "object",
+ "additionalProperties": [
+ "string",
+ {
+ "type": "object",
+ "name": "depgroups",
+ "additionalProperties": ["string", { "type": "array", "name": "verlist", "items": "string" }]
+ }
+ ]
+ }
+ }
+}
View
81 test/schemata/jquery-package.json
@@ -0,0 +1,81 @@
+{
+ "type": "object",
+ "name": "jQuery Plugins Site package.json",
+ "description": "Package manifest file for jQuery plugins. https://github.com/jquery/plugins.jquery.com/blob/master/docs/package.md",
+ "primaryProperty": "name",
+ "properties": {
+ "name": {
+ "type": "string",
+ "required": true,
+ "description": "The most important things in your package.json are the name and version fields. The name and version together form an identifier that is assumed to be completely unique."
+ },
+ "version": {
+ "type": "string",
+ "required": true,
+ "description": "Version number must be a valid semantic version number per semver.org."
+ },
+ "title": {
+ "type": "string",
+ "required": true,
+ "description": "A nice complete and pretty title of your plugin. This will be used for the page title and top-level heading on your plugin's page. Include jQuery (if you want) and spaces and mixed case, unlike name."
+ },
+ "author": {
+ "required": true,
+ "type": "object",
+ "name": "person",
+ "properties": {
+ "name": { "type": "string", "required": true },
+ "email": { "type": "string" },
+ "url": { "type": "string" }
+ }
+ },
+ "licenses": {
+ "type": "array",
+ "required": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "type": { "type": "string", "required": true },
+ "url": { "type": "string" }
+ }
+ }
+ },
+ "dependencies": {
+ "type": "object",
+ "required": true,
+ "description": "Use package name as the property name and its version as the value. You must list at least one dependency, jquery (note that it's lower-case).",
+ "additionalProperties": "string"
+ },
+ "description": {
+ "type": "string",
+ "format": "multiline"
+ },
+ "keywords": {
+ "type": "array",
+ "items": "string",
+ "description": "This helps people discover your plugin as it's listed on the jQuery Plugins Site."
+ },
+ "homepage": {
+ "type": "string",
+ "format": "url",
+ "description": "The URL to the plugin homepage."
+ },
+ "contributors": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "name": "person",
+ "properties": {
+ "name": { "type": "string", "required": true },
+ "email": { "type": "string" },
+ "url": { "type": "string" }
+ }
+ }
+ },
+ "files": {
+ "description": "List of files that make up your plugin. This should be a file path relative to the root of your plugin folder.",
+ "type": "array",
+ "items": { "type": "string", "format": "url.path" }
+ }
+ }
+ }
View
39 test/schemata/npm-package.json
@@ -0,0 +1,39 @@
+{
+ "type": "object",
+ "name": "NPM package.json",
+ "description": "Package manifest file for Node.JS modules. Note that this is incomplete. http://npmjs.org/doc/json.html",
+ "properties": {
+ "name": {
+ "type": "string",
+ "required": true,
+ "description": "The name and version together form an identifier that is assumed to be completely unique."
+ },
+ "version": {
+ "type": "string",
+ "required": true,
+ "description": "Version must be parseable by node-semver, which is bundled with npm as a dependency."
+ },
+ "description": {
+ "type": "string",
+ "format": "multiline"
+ },
+ "keywords": {
+ "type": "array",
+ "items": "string"
+ },
+ "homepage": {
+ "type": "string",
+ "format": "url"
+ },
+ "bugs": {
+ "type": "string"
+ },
+ "dependencies": {
+ "type": "object",
+ "additionalProperties": "string"
+ },
+ "private": {
+ "type": "boolean"
+ }
+ }
+ }
View
79 test/valid-packages-test.js
@@ -0,0 +1,79 @@
+"use strict";
+
+var assert = require("assert"),
+ path = require("path"),
+ fs = require("fs"),
+ glob = require("glob"),
+ vows = require("vows"),
+ jsv = require("JSV").JSV.createEnvironment();
+
+function parse(json_file, ignore_missing, ignore_parse_fail) {
+ var content;
+
+ try {
+ content = fs.readFileSync(json_file, 'utf8');
+ } catch (err1) {
+ if (!ignore_missing) {
+ assert.ok(0, json_file + " doesn't exist!");
+ }
+ return null;
+ }
+ try {
+ return JSON.parse(content);
+ } catch (err2) {
+ if (!ignore_parse_fail) {
+ assert.ok(0, json_file + " failed to parse");
+ }
+ return null;
+ }
+}
+
+function pkg_name(json_file) {
+ return json_file.split("/")[3];
+}
+
+// load up those files
+var packages = glob.sync("./ajax/libs/*/").map(function (pkg) {
+ return pkg + "package.json";
+ }),
+ schemata = glob.sync("./test/schemata/*.json").map(function (schema) {
+ return jsv.createSchema(parse(schema));
+ }),
+ suite = vows.describe('Package structure');
+
+packages.map(function (pkg) {
+ var package_vows = {"topic": pkg},
+ pname = pkg_name(pkg);
+ package_vows[pname + " has package.json"] = function (pkg) {
+ assert.ok(path.existsSync(pkg), pkg_name(pkg) + " missing!");
+ };
+ package_vows[pname + " package.json is well-formed"] = function (pkg) {
+ assert.ok(parse(pkg, true),
+ pkg_name(pkg) + " malformed!");
+ };
+ package_vows[pname + " package.json is valid"] = function (pkg) {
+ var pkg_obj = parse(pkg, true, true),
+ valid = false,
+ errors;
+ if (pkg_obj === null) {
+ // we already know about the problem
+ return;
+ }
+ errors = schemata.map(function (schema) {
+ var schema_errors = schema.validate(pkg_obj).errors;
+ if (!schema_errors.length) {
+ valid = true;
+ } else {
+ return schema_errors;
+ }
+ return [];
+ });
+ assert.ok(valid,
+ pkg_name(pkg) + " didn't parse as any known format");
+ // + JSON.stringify(errors, null, "\t"));
+ };
+ suite.addBatch({pname: package_vows});
+});
+
+suite.run();
+

0 comments on commit b001565

Please sign in to comment.
Something went wrong with that request. Please try again.