Comparing version 3.7.0 to 3.7.1
{ | ||
"name": "pactum", | ||
"version": "3.7.0", | ||
"version": "3.7.1", | ||
"description": "REST API Testing Tool for all levels in a Test Pyramid", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -8,2 +8,7 @@ import { EventEmitter } from 'node:events'; | ||
export const events: EventEmitter; | ||
export const pactumEvents: EventEmitter; | ||
/** | ||
* @deprecated | ||
*/ | ||
export const events: EventEmitter; |
const { EventEmitter } = require('events'); | ||
/** | ||
* @deprecated | ||
*/ | ||
const events = new EventEmitter(); | ||
const pactumEvents = new EventEmitter(); | ||
const EVENT_TYPES = { | ||
@@ -12,3 +17,4 @@ BEFORE_REQUEST: "BEFORE_REQUEST", | ||
events, | ||
pactumEvents, | ||
EVENT_TYPES | ||
} |
const ExpectModel = require('../models/expect'); | ||
const utils = require('../helpers/utils'); | ||
const http = require('http'); | ||
@@ -146,5 +147,9 @@ class Have { | ||
function expect(response, spec) { | ||
return new Expect(response, spec); | ||
if (response instanceof http.IncomingMessage) { | ||
return new Expect(response, spec); | ||
} | ||
const res = { json: response }; | ||
return new Expect(res, spec); | ||
} | ||
module.exports = expect; |
@@ -29,14 +29,9 @@ /** | ||
/** | ||
* removes default header | ||
* removes all or selective default headers | ||
*/ | ||
export function removeDefaultHeader(key: string): void; | ||
export function removeDefaultHeaders(key?: string): void; | ||
/** | ||
* removes all default headers | ||
*/ | ||
export function removeDefaultHeaders(): void; | ||
/** | ||
* records data that will be available in reports | ||
*/ | ||
export function setDefaultRecorders(name: string, path: string): void; |
@@ -49,13 +49,10 @@ const config = require('../config'); | ||
removeDefaultHeader(key) { | ||
if (!key) { | ||
throw new PactumRequestError(`Invalid header key provided - ${key}`); | ||
} | ||
delete config.request.headers[key]; | ||
removeDefaultHeaders(key) { | ||
if(key) { | ||
delete config.request.headers[key]; | ||
} else { | ||
config.request.headers = {}; | ||
} | ||
}, | ||
removeDefaultHeaders() { | ||
config.request.headers = {}; | ||
}, | ||
setDefaultRecorders(name, path) { | ||
@@ -62,0 +59,0 @@ records.push({ name, path }); |
const override = require('deep-override'); | ||
const jq = require('json-query'); | ||
const { klona } = require("klona"); | ||
const { clone } = require('../exports/utils'); | ||
const stash = require('../exports/stash'); | ||
@@ -20,3 +20,3 @@ const handler = require('../exports/handler'); | ||
const orgMap = stash.getDataMap(); | ||
this.map = klona(orgMap); | ||
this.map = clone(orgMap); | ||
this.map = this.processDataRefs(this.map); | ||
@@ -33,3 +33,3 @@ config.data.ref.map.processed = true; | ||
const orgTemplate = stash.getDataTemplate(); | ||
this.template = klona(orgTemplate); | ||
this.template = clone(orgTemplate); | ||
this.template = this.processDataTemplates(this.template); | ||
@@ -63,3 +63,3 @@ config.data.template.processed = true; | ||
if (templateValue) { | ||
data = klona(templateValue); | ||
data = clone(templateValue); | ||
data = this.processDataTemplates(data); | ||
@@ -140,3 +140,3 @@ if (overrides) { | ||
if (config.data.template.direct_override) { | ||
const cloned_data = klona(data); | ||
const cloned_data = clone(data); | ||
delete cloned_data['@DATA:TEMPLATE@']; | ||
@@ -143,0 +143,0 @@ delete cloned_data['@REMOVES@']; |
@@ -31,15 +31,4 @@ const fs = require('fs'); | ||
/** | ||
* | ||
* @param {string} name | ||
*/ | ||
function findFile(name, dir = config.data.dir) { | ||
const result = _findFile(name, dir); | ||
if (result) { | ||
return result; | ||
} | ||
throw new Error(`File Not Found - '${name}'`); | ||
} | ||
function _findFile(name, dir = config.data.dir) { | ||
function findFileRecursively(name, dir = config.data.dir) { | ||
if (fs.existsSync(name)) { | ||
@@ -59,3 +48,3 @@ return fs.readFileSync(name); | ||
if (stats.isDirectory()) { | ||
const result = _findFile(name, dirPath); | ||
const result = findFileRecursively(name, dirPath); | ||
if (result) { | ||
@@ -72,3 +61,3 @@ return result; | ||
saveSnapshot, | ||
findFile | ||
findFileRecursively | ||
}; |
@@ -17,2 +17,3 @@ import * as E2E from './models/E2E'; | ||
export * as state from './exports/state'; | ||
export * as utils from './exports/utils'; | ||
@@ -19,0 +20,0 @@ export interface SpecOptions { |
@@ -7,4 +7,2 @@ require('./plugins/logger').setAdapter(require('./adapters/logger')); | ||
const { klona } = require('klona') | ||
const Spec = require('./models/Spec'); | ||
@@ -26,2 +24,3 @@ const Fuzz = require('./models/Fuzz'); | ||
const events = require('./exports/events'); | ||
const utils = require('./exports/utils'); | ||
@@ -48,2 +47,3 @@ const processor = require('./helpers/dataProcessor'); | ||
events, | ||
utils, | ||
@@ -74,3 +74,3 @@ spec(name, data, opts) { | ||
clone(value) { | ||
return klona(value); | ||
return utils.clone(value); | ||
}, | ||
@@ -77,0 +77,0 @@ |
const assert = require('assert'); | ||
const jqy = require('json-query'); | ||
const lc = require('lightcookie'); | ||
const { klona: clone } = require('klona'); | ||
@@ -13,2 +12,3 @@ const config = require('../config'); | ||
const handler = require('../exports/handler'); | ||
const { clone } = require('../exports/utils'); | ||
const jsv = require('../plugins/json.schema'); | ||
@@ -352,3 +352,3 @@ const jmv = require('../plugins/json.match'); | ||
const current_rules = jmv.getMatchingRules(value, '$.body'); | ||
let errors = jmv.validate(actual, jmv.getRawValue(value), current_rules, '$.body'); | ||
let errors = jmv.validate(actual, jmv.getRawValue(value), current_rules, '$.body'); | ||
if (errors) { | ||
@@ -355,0 +355,0 @@ this.fail(errors.replace('$.body', '$')); |
@@ -6,3 +6,3 @@ const lc = require('lightcookie'); | ||
const { PactumInteractionError } = require('../helpers/errors'); | ||
const { klona: clone } = require('klona'); | ||
const { clone } = require('../exports/utils'); | ||
const ALLOWED_REQUEST_METHODS = new Set([ | ||
@@ -126,3 +126,3 @@ 'GET', | ||
const cookie = lc.serialize(request.cookies); | ||
if(!this.headers) { | ||
if (!this.headers) { | ||
this.headers = {}; | ||
@@ -174,5 +174,5 @@ } | ||
this.body = getValue(response.body); | ||
if(response.cookies) { | ||
if (response.cookies) { | ||
const cookie = lc.serialize(response.cookies); | ||
if(!this.headers) { | ||
if (!this.headers) { | ||
this.headers = {}; | ||
@@ -179,0 +179,0 @@ } |
@@ -17,3 +17,3 @@ const fs = require('fs'); | ||
const config = require('../config'); | ||
const { findFile } = require('../helpers/file.utils'); | ||
const { findFile } = require('../exports/utils'); | ||
const stash = require('../exports/stash'); | ||
@@ -49,3 +49,3 @@ const { memorize_spec, is_spec_memoized } = require('../helpers/memo'); | ||
} | ||
sleep(ms) { | ||
@@ -214,3 +214,3 @@ this._sleep = ms; | ||
if (typeof json === 'string') { | ||
json = get_json_from_template_or_file(json); | ||
json = getJsonFromTemplateOrFile(json); | ||
} else if (typeof json !== 'object') { | ||
@@ -406,3 +406,3 @@ throw new PactumRequestError(`Invalid json in request - ${json}`); | ||
expectJson(path, value) { | ||
typeof value === 'undefined' ? this._expect.json.push(get_json_from_template_or_file(path)) : this._expect.jsonQuery.push({ path, value }); | ||
typeof value === 'undefined' ? this._expect.json.push(getJsonFromTemplateOrFile(path)) : this._expect.jsonQuery.push({ path, value }); | ||
return this; | ||
@@ -413,3 +413,3 @@ } | ||
expectJsonLike(path, value) { | ||
typeof value === 'undefined' ? this._expect.jsonLike.push(get_json_from_template_or_file(path)) : this._expect.jsonQueryLike.push({ path, value }); | ||
typeof value === 'undefined' ? this._expect.jsonLike.push(getJsonFromTemplateOrFile(path)) : this._expect.jsonQueryLike.push({ path, value }); | ||
return this; | ||
@@ -424,3 +424,3 @@ } | ||
if (typeof value === 'undefined') { | ||
this._expect.jsonSchema.push({ value: get_json_from_template_or_file(path) }); | ||
this._expect.jsonSchema.push({ value: getJsonFromTemplateOrFile(path) }); | ||
} else { | ||
@@ -439,3 +439,3 @@ if (typeof path === 'object' && typeof value === 'object') { | ||
expectJsonMatch(path, value) { | ||
typeof value === 'undefined' ? this._expect.jsonMatch.push(get_json_from_template_or_file(path)) : this._expect.jsonMatchQuery.push({ path, value }); | ||
typeof value === 'undefined' ? this._expect.jsonMatch.push(getJsonFromTemplateOrFile(path)) : this._expect.jsonMatchQuery.push({ path, value }); | ||
return this; | ||
@@ -446,3 +446,3 @@ } | ||
expectJsonMatchStrict(path, value) { | ||
typeof value === 'undefined' ? this._expect.jsonMatchStrict.push(get_json_from_template_or_file(path)) : this._expect.jsonMatchStrictQuery.push({ path, value }); | ||
typeof value === 'undefined' ? this._expect.jsonMatchStrict.push(getJsonFromTemplateOrFile(path)) : this._expect.jsonMatchStrictQuery.push({ path, value }); | ||
return this; | ||
@@ -583,3 +583,3 @@ } | ||
function get_json_from_template_or_file(path) { | ||
function getJsonFromTemplateOrFile(path) { | ||
if (typeof path === 'string') { | ||
@@ -586,0 +586,0 @@ if (stash.getDataTemplate()[path]) { |
@@ -13,3 +13,3 @@ const phin = require('phin'); | ||
const hr = require('../helpers/handler.runner'); | ||
const { events, EVENT_TYPES } = require('../exports/events'); | ||
const { events, pactumEvents, EVENT_TYPES } = require('../exports/events'); | ||
@@ -261,2 +261,3 @@ class Tosser { | ||
events.emit(EVENT_TYPES.BEFORE_REQUEST, request); | ||
pactumEvents.emit(EVENT_TYPES.BEFORE_REQUEST, { request }); | ||
log.debug(`${request.method} ${request.url}`); | ||
@@ -279,2 +280,3 @@ res = await phin(request); | ||
events.emit(EVENT_TYPES.AFTER_RESPONSE, res); | ||
pactumEvents.emit(EVENT_TYPES.AFTER_RESPONSE, { request, response: res }); | ||
} | ||
@@ -281,0 +283,0 @@ return res; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178888
66
5372
4