Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pactum-swagger-coverage

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pactum-swagger-coverage - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

5

package.json
{
"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"
}
}

40

src/lib/core.js

@@ -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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc