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 3.2.1 to 3.2.2

10

package.json
{
"name": "pactum",
"version": "3.2.1",
"version": "3.2.2",
"description": "REST API Testing Tool for all levels in a Test Pyramid",

@@ -10,10 +10,2 @@ "main": "./src/index.js",

],
"exports": {
".": "./src/index.js",
"./handler": "./src/exports/handler.js",
"./mock": "./src/exports/mock.js",
"./request": "./src/exports/request.js",
"./settings": "./src/exports/settings.js",
"./state": "./src/exports/state.js"
},
"scripts": {

@@ -20,0 +12,0 @@ "test": "npm run test:unit && npm run test:component",

2

src/exports/expect.d.ts

@@ -23,2 +23,4 @@ export interface Have {

jsonLength(path: string, value: number): void;
jsonSnapshot(value?: any): void;
jsonSnapshot(name: string, value?: any): void;
responseTimeLessThan(ms: number): void;

@@ -25,0 +27,0 @@ error(err?: string | object): void;

@@ -89,2 +89,7 @@ const ExpectModel = require('../models/expect');

jsonSnapshot(name, value) {
typeof name === 'string' ? this.expect.jsonSnapshots.push({ name, value }): this.expect.jsonSnapshots.push({ value: name });
this._validate();
}
responseTimeLessThan(ms) {

@@ -91,0 +96,0 @@ this.expect.responseTime = ms;

@@ -34,3 +34,3 @@ const assert = require('assert');

this.jsonMatchStrictQuery = [];
this.jsonSnapshot = [];
this.jsonSnapshots = [];
this.jsonLength = [];

@@ -331,34 +331,33 @@ this.jsonLengthQuery = [];

_validateJsonSnapshot(response) {
if (this.jsonSnapshot.length > 0) {
if (!this.name) {
this.fail('Snapshot name is required');
}
if (this.updateSnapshot) {
log.warn(`Update snapshot is enabled for "${this.name}"`);
file.saveSnapshot(this.name, response.json);
}
this.jsonSnapshot = processor.processData(this.jsonSnapshot);
const expected = file.getSnapshotFile(this.name, response.json);
if (this.jsonSnapshots.length > 0) {
this.jsonSnapshots = processor.processData(this.jsonSnapshots);
let snapshot_name = this.name;
const actual = response.json;
const rules = {};
for (let i = 0; i < this.jsonSnapshot.length; i++) {
const data = this.jsonSnapshot[i];
if (data) {
const current_rules = jmv.getMatchingRules(data, '$.body');
const errors = jmv.validate(actual, jmv.getRawValue(data), current_rules, '$.body');
const all_rules = {};
for (let i = 0; i < this.jsonSnapshots.length; i++) {
const { name, value } = this.jsonSnapshots[i];
snapshot_name = name || snapshot_name;
if (!snapshot_name) {
this.fail('Snapshot name is required');
}
if (this.updateSnapshot) {
log.warn(`Update snapshot is enabled for '${snapshot_name}'`);
file.saveSnapshot(snapshot_name, response.json);
}
if (value) {
const current_rules = jmv.getMatchingRules(value, '$.body');
let errors = jmv.validate(actual, jmv.getRawValue(value), current_rules, '$.body');
if (errors) {
this.fail(errors.replace('$.body', '$'));
}
Object.assign(rules, current_rules);
Object.assign(all_rules, current_rules);
}
}
if (Object.keys(rules).length > 0) {
let errors = jmv.validate(actual, expected, rules, '$.body');
const expected = file.getSnapshotFile(snapshot_name, response.json);
if (Object.keys(all_rules).length > 0) {
const errors = jmv.validate(actual, expected, all_rules, '$.body', true);
if (errors) {
this.fail(errors.replace('$.body', '$'));
} else {
errors = jmv.validate(expected, actual, rules, '$.body');
if (errors) {
this.fail(errors.replace('$.body', '$'));
}
}

@@ -365,0 +364,0 @@ } else {

@@ -339,2 +339,3 @@ import { RequestOptions, IncomingMessage } from 'http';

expectJsonSnapshot(value?: object): Spec;
expectJsonSnapshot(name: string, value?: object): Spec;

@@ -341,0 +342,0 @@ /**

@@ -402,4 +402,4 @@ const fd = require('../plugins/form.data')

expectJsonSnapshot(matchers) {
this._expect.jsonSnapshot.push(matchers);
expectJsonSnapshot(name, value) {
typeof name === 'string' ? this._expect.jsonSnapshots.push({ name, value }): this._expect.jsonSnapshots.push({ value: name });
return this;

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