@open-rpc/test-coverage
Advanced tools
Comparing version
@@ -6,5 +6,5 @@ import { OpenRPC } from "@open-rpc/meta-schema"; | ||
transport(url: string, method: string, params: any[]): PromiseLike<any>; | ||
reporter(value: any[]): any; | ||
reporter(value: any[], schema: OpenRPC): any; | ||
} | ||
declare const _default: (options: IOptions) => Promise<any>; | ||
declare const _default: (options: IOptions) => Promise<void>; | ||
export default _default; |
@@ -62,34 +62,39 @@ "use strict"; | ||
exports.default = (function (options) { return __awaiter(_this, void 0, void 0, function () { | ||
var results, promises; | ||
var results, promises, callResults; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
results = []; | ||
promises = options.schema.methods.map(function (method) { return __awaiter(_this, void 0, void 0, function () { | ||
var params, urls; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (options.skipMethods.includes(method.name)) { | ||
return [2 /*return*/]; | ||
switch (_a.label) { | ||
case 0: | ||
results = []; | ||
promises = options.schema.methods.map(function (method) { return __awaiter(_this, void 0, void 0, function () { | ||
var params, urls; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (options.skipMethods.includes(method.name)) { | ||
return [2 /*return*/]; | ||
} | ||
return [4 /*yield*/, getParams(method.params)]; | ||
case 1: | ||
params = _a.sent(); | ||
urls = (options.schema.servers || []).map(function (u) { | ||
// TODO: support server variables | ||
return u.url; | ||
}); | ||
return [2 /*return*/, Promise.all(urls.map(function (url) { | ||
return options.transport(url, method.name, params) | ||
.then(function (r) { | ||
results.push(__assign({ method: method.name, params: params }, r)); | ||
}); | ||
}))]; | ||
} | ||
return [4 /*yield*/, getParams(method.params)]; | ||
case 1: | ||
params = _a.sent(); | ||
urls = (options.schema.servers || []).map(function (u) { | ||
// TODO: support server variables | ||
return u.url; | ||
}); | ||
return [2 /*return*/, Promise.all(urls.map(function (url) { | ||
return options.transport(url, method.name, params) | ||
.then(function (r) { | ||
results.push(__assign({ method: method.name, params: params }, r)); | ||
}); | ||
}))]; | ||
} | ||
}); | ||
}); }); | ||
return [2 /*return*/, Promise.all(promises).then(function () { | ||
return results; | ||
}).then(options.reporter)]; | ||
}); | ||
}); }); | ||
return [4 /*yield*/, Promise.all(promises)]; | ||
case 1: | ||
callResults = _a.sent(); | ||
options.reporter(callResults, options.schema); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); |
@@ -8,3 +8,3 @@ import { OpenRPC } from '@open-rpc/meta-schema'; | ||
} | ||
declare const _default: (options: IOptions) => Promise<any>; | ||
declare const _default: (options: IOptions) => Promise<void>; | ||
export default _default; |
@@ -1,2 +0,3 @@ | ||
declare const _default: (callResults: any[]) => void; | ||
import { OpenRPC } from '@open-rpc/meta-schema'; | ||
declare const _default: (callResults: any[], schema: OpenRPC) => void; | ||
export default _default; |
@@ -7,3 +7,5 @@ "use strict"; | ||
var colors_1 = __importDefault(require("colors")); | ||
exports.default = (function (callResults) { | ||
var ajv_1 = __importDefault(require("ajv")); | ||
exports.default = (function (callResults, schema) { | ||
var ajv = new ajv_1.default(); | ||
var metrics = { | ||
@@ -16,3 +18,3 @@ errors: 0, | ||
metrics.errors++; | ||
console.log(colors_1.default.red.underline('Error: '), colors_1.default.cyan(call.method)); | ||
console.log(colors_1.default.red.underline('JSON-RPC Request Error: '), colors_1.default.cyan(call.method)); | ||
console.log(call.error); | ||
@@ -22,4 +24,18 @@ console.log(call.params); | ||
else { | ||
metrics.success++; | ||
console.log(colors_1.default.green('Success: '), call.method); | ||
var methodSchema = schema.methods.find(function (m) { return m.name === call.method; }); | ||
if (!methodSchema) { | ||
return console.log("Error: no result defined for " + call.method); | ||
} | ||
var isValid = ajv.validate(methodSchema.result.schema, call.method + "/results"); | ||
var errors = ajv.errors; | ||
if (isValid) { | ||
metrics.success++; | ||
console.log(colors_1.default.green('Success: '), call.method); | ||
} | ||
else { | ||
console.log(colors_1.default.red.underline('Result Validation Error: '), colors_1.default.cyan(call.method)); | ||
console.log(call); | ||
console.log(errors); | ||
console.log(methodSchema); | ||
} | ||
} | ||
@@ -26,0 +42,0 @@ }); |
@@ -1,2 +0,3 @@ | ||
declare const _default: (callResults: any[]) => void; | ||
import { OpenRPC } from "@open-rpc/meta-schema"; | ||
declare const _default: (callResults: any[], schema: OpenRPC) => void; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = (function (callResults) { | ||
exports.default = (function (callResults, schema) { | ||
console.log(JSON.stringify(callResults, undefined, 4)); | ||
}); |
{ | ||
"name": "@open-rpc/test-coverage", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Test your OpenRPC Document against an API.", | ||
@@ -21,4 +21,5 @@ "scripts": { | ||
"@open-rpc/meta-schema": "^1.3.1", | ||
"@open-rpc/schema-utils-js": "^1.6.3", | ||
"@open-rpc/schema-utils-js": "^1.8.0", | ||
"@types/isomorphic-fetch": "0.0.35", | ||
"ajv": "^6.10.0", | ||
"colors": "^1.3.3", | ||
@@ -25,0 +26,0 @@ "isomorphic-fetch": "^2.2.1", |
17028
8.42%352
6.99%8
14.29%+ Added