pactum-swagger-coverage
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "pactum-swagger-coverage", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Swagger api coverage report for pactum tests", | ||
@@ -35,3 +35,6 @@ "main": "./src/index.js", | ||
"phin": "^3.5.0" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
} | ||
} |
@@ -7,3 +7,6 @@ const http = require('../helpers/http'); | ||
/** | ||
* Function to Load the Swagger Yaml file | ||
* @returns {Object} Swagger file object | ||
*/ | ||
async function loadSwaggerYaml() { | ||
@@ -24,2 +27,6 @@ // Get swagger yaml document, or throw exception on error | ||
/** | ||
* Function to load the swagger Json file | ||
* @returns {Object} Swagger file object | ||
*/ | ||
async function loadSwaggerJson() { | ||
@@ -40,8 +47,18 @@ let swaggerInfo = {}; | ||
/** | ||
* Fuction to all get api path's from swagger file | ||
* @param {Object} swaggerInfo | ||
* @returns {Array} Array of API paths | ||
*/ | ||
function getApiPaths(swaggerInfo) { | ||
const apiPaths = Object.keys(swaggerInfo.paths); | ||
apiPaths.forEach((apiPath) => { apiPath = `${swaggerInfo.basePath}${apiPath}` }) | ||
return apiPaths | ||
apiPaths.forEach((apiPath, index) => apiPaths[index] = `${swaggerInfo.basePath}${apiPath}`); | ||
return apiPaths; | ||
} | ||
/** | ||
* Function to get swagger coverage stats | ||
* @param {Array} testsCoveredApis | ||
* @returns {object} Swagger coverage stats | ||
*/ | ||
async function getSwaggerCoverage(testsCoveredApis) { | ||
@@ -66,9 +83,14 @@ const swaggerInfo = config.swaggerYamlPath ? await loadSwaggerYaml() : await loadSwaggerJson(); | ||
/** | ||
* Function to RegEx match api paths | ||
* @param {String} apiPath | ||
* @param {String} rPath | ||
* @returns {Boolean} Match result | ||
*/ | ||
function regExMatchOfPath(apiPath, rPath) { | ||
if (apiPath.includes("{")) { | ||
const idx = apiPath.indexOf("{"); | ||
apiPath = apiPath.substring(0, idx); | ||
} | ||
const regex = RegExp(apiPath); | ||
return regex.test(rPath); | ||
const regex = RegExp(apiPath.replace(/{[^\/]+}/g,'.*')); | ||
const extractedApiPath = rPath.match(regex); | ||
const extractedPathSepCount = (extractedApiPath ? extractedApiPath[0].match(/\//g) : []).length; | ||
const apiPathSepCount = (apiPath.match(/\//g) || []).length; | ||
return regex.test(rPath) && (extractedPathSepCount === apiPathSepCount); | ||
} | ||
@@ -75,0 +97,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9820
159