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

pactum

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pactum - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

src/exports/loader.js

4

package.json
{
"name": "pactum",
"version": "2.0.1",
"version": "2.0.2",
"description": "REST API endpoint testing tool with a mock server & compatible with pact.io for contract testing",

@@ -59,3 +59,3 @@ "main": "./src/index.js",

"dependencies": {
"colors": "^1.4.0",
"deep-override": "^1.0.1",
"djv": "^2.1.3-alpha.0",

@@ -62,0 +62,0 @@ "form-data": "^3.0.0",

@@ -16,2 +16,8 @@ const config = {

headers: {}
},
data: {
template: {
enabled: false,
processed: false
}
}

@@ -18,0 +24,0 @@ };

const { PactumHandlerError } = require('../helpers/errors');
/**
* @callback RequestResponseHandler
* @param {object} req - request object
* @param {object} res - response object
*/
/**
* @typedef {object} Context
* @property {any} [data] - custom data object passed to handler
* @property {object} [spec] - spec will be available when used by `pactum.setState`
*/
/**
* @callback StateHandler
* @param {Context} ctx - context object
*/
const expectHandlers = {};

@@ -13,3 +30,3 @@ const retryHandlers = {};

* @param {string} name - name of the custom expect handler
* @param {function} func - handler function
* @param {RequestResponseHandler} func - handler function
* @example

@@ -33,3 +50,3 @@ * pactum.handler.addExpectHandler('isUser', (req, res) => {

* @param {string} name - retry handler name
* @param {function} func - retry handler function
* @param {RequestResponseHandler} func - retry handler function
* @example

@@ -51,3 +68,3 @@ * pactum.handler.addRetryHandler('RetryTill200', (req, res) => res.statusCode !== 200);

* @param {string} name - return handler name
* @param {function} func - return handler function
* @param {RequestResponseHandler} func - return handler function
* @example

@@ -68,5 +85,7 @@ * pactum.handler.addReturnHandler('ReturnOrderId', (req, res) => { return res.json.id });

* @param {string} name - state handler name
* @param {function} func - state handler function
* @param {StateHandler} func - state handler function
* @example
* pactum.handler.addStateHandler('there are no users', async () => { await db.clearUsers(); });
* pactum.handler.addStateHandler('there are no users', async (ctx) => { await db.clearUsers(); });
* pactum.handler.addStateHandler('there is an order', async (ctx) => { await db.addOrder(ctx.data); });
* pactum.handler.addStateHandler('there is a user', (ctx) => { ctx.spec.addInteraction({}); });
*/

@@ -73,0 +92,0 @@ addStateHandler(name, func) {

@@ -1,2 +0,2 @@

const Matcher = require('../models/matcher');
module.exports = new Matcher();
const matchers = require('../models/matcher');
module.exports = matchers;

@@ -6,2 +6,3 @@ const phin = require('phin');

const log = require('../helpers/logger');
const { gray, green, red } = require('../helpers/colors');
const { PactumConfigurationError } = require('../helpers/errors');

@@ -154,8 +155,8 @@

this.testPassedCount = this.testPassedCount + 1;
log.info(` ${'√'.green} ${interaction.description.gray}`);
log.info(` ${green('√')} ${gray(interaction.description)}`);
} else {
success = false;
this.testFailedCount = this.testFailedCount + 1;
log.info(` ${'X'.red} ${interaction.description.gray}`);
log.error(` ${isValid.message.red}`);
log.info(` ${red('X')} ${gray(interaction.description)}`);
log.error(` ${red(isValid.message)}`);
}

@@ -311,5 +312,5 @@ }

log.info();
log.info(` ${this.testPassedCount} passing`.green);
log.info(green(` ${this.testPassedCount} passing`));
if (this.testFailedCount > 0) {
log.info(` ${this.testFailedCount} failing`.red);
log.info(red(` ${this.testFailedCount} failing`));
throw 'Provider Verification Failed';

@@ -316,0 +317,0 @@ }

@@ -114,6 +114,11 @@ const log = require('./logger');

const newExpectedPath = expectedPath + `[${i}]`;
const actualPathResp = this.compare(aItem, eItem, newExpectedPath, newExpectedPath);
if (actualPathResp === '') {
seen.add(i);
continue;
let actualPathResp = '';
if (seen.has(i)) {
actualPathResp = `Json doesn't have expected value at '${newExpectedPath}'`;
} else {
actualPathResp = this.compare(aItem, eItem, newExpectedPath, newExpectedPath);
if (actualPathResp === '') {
seen.add(i);
continue;
}
}

@@ -120,0 +125,0 @@ for (let j = i + 1; j < actual.length; j++) {

@@ -1,2 +0,2 @@

const colors = require('colors');
const { options, cyan, magenta, blue, green, yellow, red } = require('./colors');

@@ -39,3 +39,3 @@ const LEVEL_TRACE = 3;

if (process.env.PACTUM_DISABLE_LOG_COLORS === 'true') {
colors.disable();
options.disableColors = true;
}

@@ -55,3 +55,3 @@ }

if (this.levelValue <= LEVEL_TRACE) {
process.stdout.write(`${'PACTUM'.cyan} ${'TRACE'.magenta} `);
process.stdout.write(`${cyan('PACTUM')} ${magenta('TRACE')} `);
this.console.debug(...msg);

@@ -63,3 +63,3 @@ }

if (this.levelValue <= LEVEL_DEBUG) {
process.stdout.write(`${'PACTUM'.cyan} ${'DEBUG'.blue} `);
process.stdout.write(`${cyan('PACTUM')} ${blue('DEBUG')} `);
this.console.debug(...msg);

@@ -71,3 +71,3 @@ }

if (this.levelValue <= LEVEL_INFO) {
process.stdout.write(`${'PACTUM'.cyan} ${'INFO'.green} `);
process.stdout.write(`${cyan('PACTUM')} ${green('INFO')} `);
this.console.info(...msg);

@@ -79,3 +79,3 @@ }

if (this.levelValue <= LEVEL_WARN) {
process.stdout.write(`${'PACTUM'.cyan} ${'WARN'.yellow} `);
process.stdout.write(`${cyan('PACTUM')} ${yellow('WARN')} `);
this.console.warn(...msg);

@@ -87,3 +87,3 @@ }

if (this.levelValue <= LEVEL_ERROR) {
process.stdout.write(`${'PACTUM'.cyan} ${'ERROR'.red} `);
process.stdout.write(`${cyan('PACTUM')} ${red('ERROR')} `);
this.console.error(...msg);

@@ -90,0 +90,0 @@ }

@@ -11,2 +11,3 @@ const Spec = require('./models/Spec');

const state = require('./exports/state');
const loader = require('./exports/loader');

@@ -109,2 +110,3 @@ /**

state,
loader,

@@ -111,0 +113,0 @@ /**

const { PactumMatcherError } = require('../helpers/errors');
class Matcher {
const matcher = {
/**

@@ -10,3 +11,3 @@ * type matching

return like(value);
}
},

@@ -19,3 +20,3 @@ /**

return like(value);
}
},

@@ -30,3 +31,3 @@ /**

return term(options);
}
},

@@ -41,3 +42,3 @@ /**

return term(options);
}
},

@@ -65,3 +66,3 @@ /**

};
}
},

@@ -135,2 +136,2 @@ /**

module.exports = Matcher;
module.exports = matcher;

@@ -332,6 +332,13 @@ const FormData = require('form-data');

* appends query param to the request url - /comments?postId=1
* @deprecated use withQueryParam
* @see withQueryParam
* @param {string} key - query parameter key
* @param {string} value - query parameter value
* @example
* await pactum
* .get('https://jsonplaceholder.typicode.com/comments')
* .withQueryParam('postId', '1')
* .withQueryParam('userId', '2')
* .expectStatus(200);
* @summary generated url will look like - /comments?postId=1&userId=2
*/
withQuery(key, value) {
withQueryParam(key, value) {
if (!helper.isValidString(key)) {

@@ -351,18 +358,2 @@ throw new PactumRequestError(`Invalid key in query parameter for request - ${key}`);

/**
* appends query param to the request url - /comments?postId=1
* @param {string} key - query parameter key
* @param {string} value - query parameter value
* @example
* await pactum
* .get('https://jsonplaceholder.typicode.com/comments')
* .withQueryParam('postId', '1')
* .withQueryParam('userId', '2')
* .expectStatus(200);
* @summary generated url will look like - /comments?postId=1&userId=2
*/
withQueryParam(key, value) {
return this.withQuery(key, value);
}
/**
* adds query params to the request url - /comments?postId=1

@@ -369,0 +360,0 @@ * @param {object} params - query params

@@ -7,2 +7,3 @@ const phin = require('phin');

const handler = require('../exports/handler');
const processor = require('../helpers/dataProcessor');

@@ -46,2 +47,4 @@ class Tosser {

setMultiPartFormData(this.request);
processor.processTemplates();
this.request.data = processor.processData(this.request.data);
}

@@ -144,3 +147,3 @@

function setBaseUrl(request) {
if (config.request.baseUrl) {
if (config.request.baseUrl && !request.url.startsWith('http')) {
request.url = config.request.baseUrl + request.url;

@@ -147,0 +150,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