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.13 to 3.0.14

2

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

@@ -5,0 +5,0 @@ "main": "./src/index.js",

@@ -1,5 +0,7 @@

<p align="center"><a href="https://pactumjs.github.io"><img src="https://raw.githubusercontent.com/pactumjs/pactum/v3/assets/logo.png" alt="PactumJS Logo" height="100"/></a>
<span align="center">
<p><a href="https://pactumjs.github.io"><img src="https://raw.githubusercontent.com/pactumjs/pactum/v3/assets/logo.png" alt="PactumJS Logo" height="100"/></a>
</p>
<div align="center">
<div>
<h2>REST API Testing Tool for all levels in a Test Pyramid</h2>

@@ -14,7 +16,13 @@ </div>

</span>
<br />
<p><a href="https://pactumjs.github.io"><img src="https://raw.githubusercontent.com/pactumjs/pactum/v3/assets/demo.gif" alt="PactumJS Demo"/></a>
<p align="center"><a href="https://pactumjs.github.io"><img src="https://raw.githubusercontent.com/pactumjs/pactum/v3/assets/demo.gif" alt="PactumJS Demo"/></a>
</p>
<br />
<table>
<tr>
<td>
**PactumJS** is a REST API Testing Tool used to automate e2e, integration, contract & component (*or service level*) tests. It comes with a powerful *mock server* which can control the state of external dependencies.

@@ -31,2 +39,8 @@

</td>
</tr>
</table>
![----------](https://raw.githubusercontent.com/pactumjs/pactum/v3/assets/rainbow.png)
## Documentation

@@ -57,2 +71,4 @@

![----------](https://raw.githubusercontent.com/pactumjs/pactum/v3/assets/rainbow.png)
# Usage

@@ -159,2 +175,4 @@

![----------](https://raw.githubusercontent.com/pactumjs/pactum/v3/assets/rainbow.png)
# Notes

@@ -161,0 +179,0 @@

@@ -56,2 +56,6 @@ const config = {

autoRun: true
},
retry: {
count: 1,
delay: 1000
}

@@ -58,0 +62,0 @@ };

@@ -17,10 +17,2 @@ import { InteractionRequest, InteractionResponse, Interaction } from './mock';

export interface SpecInfo {
id: string;
status: string;
failure: string;
start: string;
end: string;
}
export interface InteractionCall {

@@ -39,3 +31,8 @@ request: InteractionRequest;

id: string;
info: SpecInfo;
flow?: string;
name?: string;
status: string;
failure: string;
start: string;
end: string;
request: SpecRequest;

@@ -42,0 +39,0 @@ response?: SpecResponse;

@@ -20,2 +20,4 @@ export type LogLevel = 'TRACE'|'DEBUG'|'INFO'|'WARN'|'ERROR';

export function setSnapshotDirectoryPath(path: string): void;
export function setReporterAutoRun(auto: boolean): void;
export function setReporterAutoRun(auto: boolean): void;
export function setDefaultRetryCount(count: number): void;
export function setDefaultRetryDelay(delay: number): void;

@@ -32,2 +32,10 @@ const config = require('../config');

config.reporter.autoRun = val;
},
setDefaultRetryCount(count) {
config.retry.count = count;
},
setDefaultRetryDelay(delay) {
config.retry.delay = delay;
}

@@ -34,0 +42,0 @@

@@ -14,4 +14,5 @@ const { parse } = require('parse-graphql');

const result = compare(actualQuery, expectedQuery, {}, '$.graphQL.query', strict).equal;
if (result && (actual.variables || expected.variables)) {
return compare(actual.variables, expected.variables, {}, '$.graphQL.variables', strict).equal;
const actualVariables = typeof actual.variables === 'string' ? JSON.parse(actual.variables) : actual.variables;
if (result && (actualVariables || expected.variables)) {
return compare(actualVariables, expected.variables, {}, '$.graphQL.variables', strict).equal;
}

@@ -18,0 +19,0 @@ return result;

@@ -11,10 +11,7 @@ const reporter = require('../exports/reporter');

data.flow = spec.flow;
data.info = {
id: spec.id,
name: spec._name,
status: spec.status,
failure: spec.failure,
start: spec.start,
end: helper.getCurrentTime(),
};
data.name = spec._name,
data.status = spec.status,
data.failure = spec.failure,
data.start = spec.start,
data.end = helper.getCurrentTime(),
data.request = {

@@ -21,0 +18,0 @@ url: spec._request.url,

@@ -101,3 +101,2 @@ const { compare } = require('pactum-matchers').utils;

if (req.method === 'GET' && request.graphQL) {
if (req.query.variables) req.query.variables = JSON.parse(req.query.variables);
return graphQL.compare(req.query, request.queryParams, strict);

@@ -104,0 +103,0 @@ }

@@ -13,3 +13,3 @@ import { RequestOptions } from 'http';

delay?: number;
strategy?: string|RetryHandlerFunction;
strategy?: string | RetryHandlerFunction;
}

@@ -50,3 +50,3 @@

use(name: string, data?: any): Spec
/**

@@ -74,3 +74,3 @@ * adds a interaction to the server & auto removed after execution

useInteraction(handler: string, data?: any): Spec;
/**

@@ -106,3 +106,3 @@ * The GET method requests a representation of the specified resource.

patch(url: string): Spec;
/**

@@ -121,3 +121,3 @@ * The POST method is used to submit an entity to the specified resource, often causing a change in state or side effects on the server.

post(url: string): Spec;
/**

@@ -137,3 +137,3 @@ * The PUT method replaces all current representations of the target resource with the request payload.

put(url: string): Spec;
/**

@@ -156,28 +156,28 @@ * The DELETE method deletes the specified resource.

*/
options(url: string): Spec;
/**
* The TRACE method echos the contents of an HTTP Request back to the requester
* @example
* await pactum.spec()
* .trace('http://localhost:9393/projects/1')
* .expectStatus(200);
*/
trace(url: string): Spec;
/**
* The `withMethod` method extends the support for the request-methods apart from
* (GET, POST, DELETE, PATCH, PUT, HEAD)
*
* The `withPath` method triggers the request passed through withMethod()
* @example
* await pactum.spec()
* .withMethod('HEAD')
* .withPath('https://jsonplaceholder.typicode.com/posts')
* .expectStatus(200);
*/
withMethod(method: string): Spec;
withPath(url: string): Spec;
options(url: string): Spec;
/**
* The TRACE method echos the contents of an HTTP Request back to the requester
* @example
* await pactum.spec()
* .trace('http://localhost:9393/projects/1')
* .expectStatus(200);
*/
trace(url: string): Spec;
/**
* The `withMethod` method extends the support for the request-methods apart from
* (GET, POST, DELETE, PATCH, PUT, HEAD)
*
* The `withPath` method triggers the request passed through withMethod()
* @example
* await pactum.spec()
* .withMethod('HEAD')
* .withPath('https://jsonplaceholder.typicode.com/posts')
* .expectStatus(200);
*/
withMethod(method: string): Spec;
withPath(url: string): Spec;
/**
* replaces path params in the request url - /api/users/mike

@@ -310,3 +310,3 @@ * @example

withMultiPartFormData(form: FormData): Spec;
/**

@@ -322,3 +322,3 @@ * attaches multi part form data to the request with header - "multipart/form-data"

*/
withMultiPartFormData(key: string, value: string|Buffer|Array|ArrayBuffer, options?: FormData.AppendOptions): Spec;
withMultiPartFormData(key: string, value: string | Buffer | Array | ArrayBuffer, options?: FormData.AppendOptions): Spec;

@@ -347,6 +347,12 @@ /**

/**
* retry request on specific conditions before making assertions
* retry request on specific conditions
* @example
* await pactum.spec()
* .get('/some/url)
* // retry once on failure
* await pactum.spec().get('/some/url').retry().expectStatus(200);
* // retry twice on failure
* await pactum.spec().get('/some/url').retry(2).expectStatus(200);
* // retry once on failure with custom delay of 2 seconds
* await pactum.spec().get('/some/url').retry(1, 2000).expectStatus(200);
* // retry with custom strategy
* await pactum.spec().get('/some/url')
* .retry({

@@ -357,2 +363,3 @@ * strategy: (req, res) => res.statusCode !== 200

*/
retry(count?: number, delay?: number): Spec;
retry(options: RetryOptions): Spec;

@@ -562,3 +569,3 @@

expectJsonSnapshot(value?: object): Spec;
/**

@@ -645,2 +652,2 @@ * updates the reference snapshot file

declare namespace Spec {}
declare namespace Spec { }

@@ -274,15 +274,6 @@ const FormData = require('form-data');

retry(options) {
if (!options) {
throw new PactumRequestError('Invalid retry options');
retry(options, delay) {
if (typeof options === 'undefined' || typeof options === 'number') {
options = { count: options, delay: delay };
}
if (!options.strategy) {
throw new PactumRequestError('Invalid retry strategy');
}
if (!options.count) {
options.count = 3;
}
if (!options.delay) {
options.delay = 1000;
}
this._request.retryOptions = options;

@@ -289,0 +280,0 @@ return this;

@@ -63,16 +63,25 @@ const phin = require('phin');

this.response = await getResponse(this);
const retryOptions = this.request.retryOptions;
if (retryOptions) {
const { count, delay, strategy } = retryOptions;
let retry = true;
const options = this.request.retryOptions;
if (options) {
const count = typeof options.count === 'number' ? options.count : config.retry.count;
const delay = typeof options.delay === 'number' ? options.delay : config.retry.delay;
const strategy = options.strategy;
for (let i = 0; i < count; i++) {
let noRetry = true;
const ctx = { req: this.request, res: this.response };
if (typeof strategy === 'function') {
retry = strategy(ctx);
}
if (typeof strategy === 'string') {
noRetry = strategy(ctx);
} else if (typeof strategy === 'string') {
const handlerFun = handler.getRetryHandler(strategy);
retry = handlerFun(ctx);
noRetry = handlerFun(ctx);
} else {
try {
await this.validateResponse();
} catch (error) {
noRetry = false;
}
}
if (!retry) {
if (!noRetry) {
const scale = delay === 1000 ? 'second' : 'seconds';
log.debug(`Retrying request in ${delay / 1000} ${scale}`);
await helper.sleep(delay);

@@ -79,0 +88,0 @@ this.response = await getResponse(this);

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