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.0.7 to 3.0.8

4

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

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

"openapi-fuzzer-core": "^1.0.6",
"pactum-matchers": "^1.0.0",
"pactum-matchers": "^1.0.1",
"parse-graphql": "^1.0.0",

@@ -71,0 +71,0 @@ "phin": "^3.4.1",

@@ -11,2 +11,3 @@ # pactum

- ⏱ Swift
- 🎈 Lightweight

@@ -122,3 +123,2 @@ - 🚀 Simple & Powerful

const { mock } = require('pactum');
const { regex } = require('pactum-matchers');

@@ -128,16 +128,12 @@ mock.addInteraction({

method: 'GET',
path: '/api/projects',
queryParams: {
date: regex('2020-12-12', /^\d{4}-\d{2}-\d{2}$/)
}
path: '/api/projects'
},
response: {
status: 200,
headers: {
'content-type': 'application/json'
},
body: {
id: 1,
name: 'fake'
}
body: [
{
id: 'project-id',
name: 'project-name'
}
]
}

@@ -144,0 +140,0 @@ });

@@ -12,2 +12,4 @@ const { PactumHandlerError } = require('../helpers/errors');

const assertHandlers = {};
const initializeHandlers = {};
const cleanupHandlers = {};

@@ -95,4 +97,22 @@ const handler = {

throw new PactumHandlerError(`Assert Handler Not Found - '${name}'`);
}
},
addInitializeHandler(name, func) {
isValidHandler(name, func);
initializeHandlers[name] = func;
},
getInitializeHandlers() {
return initializeHandlers;
},
addCleanupHandler(name, func) {
isValidHandler(name, func);
cleanupHandlers[name] = func;
},
getCleanupHandlers() {
return cleanupHandlers;
},
};

@@ -99,0 +119,0 @@

const handler = require('../exports/handler');
const log = require('./logger');

@@ -19,2 +20,20 @@ const hr = {

}
},
async initialize() {
const handlers = handler.getInitializeHandlers();
const keys = Object.keys(handlers);
for (let i = 0; i < keys.length; i++) {
log.info(`Running Initializer - ${keys[i]}`);
await handlers[keys[i]]();
}
},
async cleanup() {
const handlers = handler.getCleanupHandlers();
const keys = Object.keys(handlers);
for (let i = 0; i < keys.length; i++) {
log.info(`Running Cleaner - ${keys[i]}`);
await handlers[keys[i]]();
}
}

@@ -21,0 +40,0 @@

@@ -15,6 +15,6 @@ const url = require('url');

setQueryParams(request);
setHeaders(request);
setBody(request);
setMultiPartFormData(request);
setFollowRedirects(request);
setHeaders(request);
request.timeout = request.timeout || config.request.timeout;

@@ -21,0 +21,0 @@ return request;

@@ -5,2 +5,3 @@ const Step = require('./Step');

const rlc = require('../helpers/reporter.lifeCycle');
const hr = require('../helpers/handler.runner');

@@ -21,2 +22,11 @@ class E2E {

async init() {
try {
await hr.initialize();
} catch (error) {
log.error('Failed to initialize');
throw error;
}
}
step(name) {

@@ -55,2 +65,8 @@ reportStep(this.steps);

}
try {
await hr.cleanup();
} catch (error) {
log.error('Failed to cleanup');
throw error;
}
}

@@ -57,0 +73,0 @@

@@ -233,2 +233,16 @@ import { RequestOptions } from 'http';

/**
* appends file to the form-data
* @example
* await pactum.spec()
* .post('url')
* .withFile('./file/path')
*
* await pactum.spec()
* .post('url')
* .withFile('key', './file/path', { contentType: 'text/plain' })
*/
withFile(path: string, options?: FormData.AppendOptions): Spec;
withFile(key: string, path: string, options?: FormData.AppendOptions): Spec;
/**
* attaches form data to the request with header - "application/x-www-form-urlencoded"

@@ -235,0 +249,0 @@ * @example

const FormData = require('form-data');
const fs = require('fs');
const path = require('path');
const Tosser = require('./Tosser');

@@ -207,2 +209,19 @@ const Expect = require('./expect');

withFile(key, filePath, options) {
if (typeof filePath === 'object') {
options = filePath;
filePath = key;
key = 'file';
}
if (!filePath) {
filePath = key;
key = 'file';
}
if (!options) {
options = {};
}
options.filename = options.filename ? options.filename : path.basename(filePath);
return this.withMultiPartFormData(key, fs.readFileSync(filePath), options);
}
withCore(options) {

@@ -209,0 +228,0 @@ this._request.core = options;

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