New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

artillery-plugin-expect

Package Overview
Dependencies
Maintainers
2
Versions
370
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

artillery-plugin-expect - npm Package Compare versions

Comparing version

to
2.2.1

18

index.js

@@ -62,2 +62,5 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

'pretty';
userContext.expectationsPlugin.expectDefault200 = (script.config.plugins.expect.expectDefault200 === true || script.config.plugins.expect.expectDefault200 === 'true');
userContext.expectationsPlugin.reportFailuresAsErrors = script.config.plugins.expect.reportFailuresAsErrors;
return done();

@@ -91,2 +94,8 @@ };

if (expectations.length === 0) {
if (userContext.expectationsPlugin.expectDefault200) {
expectations[0] = { statusCode: 200 };
}
}
const results = [];

@@ -127,5 +136,6 @@

events.emit('plugin:expect:expectations', requestExpectations);
events.emit('plugin:expect:expectations', requestExpectations, req, res, userContext);
const formatterName = userContext.expectationsPlugin.formatter;
FORMATTERS[formatterName].call(

@@ -145,3 +155,7 @@ this,

}
return done(new Error(`Failed expectations for request ${req.url}`));
if (userContext.expectationsPlugin.reportFailuresAsErrors) {
return done(new Error(`Failed expectations for request ${req.url}`));
} else {
return done();
}
} else {

@@ -148,0 +162,0 @@ return done();

@@ -14,2 +14,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

statusCode: expectStatusCode,
notStatusCode: expectNotStatusCode,
hasHeader: expectHasHeader,

@@ -197,2 +198,23 @@ headerEquals: expectHeaderEquals,

function expectNotStatusCode(expectation, body, req, res, userContext) {
debug('check notStatusCode');
const expectedNotStatusCode = template(expectation.notStatusCode, userContext);
let result = {
ok: false,
expected: `Status code different than ${expectedNotStatusCode}`,
type: 'notStatusCode',
};
if (Array.isArray(expectedNotStatusCode)) {
result.ok = !expectedNotStatusCode.filter((x) => Number(res.statusCode) === Number(x)).length;
} else {
result.ok = Number(res.statusCode) !== Number(expectedNotStatusCode);
}
result.got = res.statusCode;
return result;
}
function checkProperty(expectationName, expectedProperty, expectedCondition, failureMessage, body) {

@@ -199,0 +221,0 @@ let result = {

31

lib/formatters.js

@@ -15,3 +15,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public

prettyError: prettyError,
silent: silent
silent: silent,
};

@@ -24,4 +24,5 @@

function prettyPrint(requestExpectations, req, res, userContext) {
debug('prettyPrint formatter');
if (requestExpectations.results.length > 0) {
artillery.log(`${chalk.blue('*', req.method, urlparse(req.url).path)} ${req.name ? '- ' + req.name : ''}`);
console.log(`${chalk.blue('*', req.method, urlparse(req.url).path)} ${req.name ? '- ' + req.name : ''}\n`);
}

@@ -32,3 +33,3 @@

requestExpectations.results.forEach(result => {
artillery.log(
console.log(
` ${result.ok ? chalk.green('ok') : chalk.red('not ok')} ${

@@ -40,4 +41,4 @@ result.type

if (!result.ok) {
artillery.log(` expected: ${result.expected}`);
artillery.log(` got: ${result.got}`);
console.log(` expected: ${result.expected}`);
console.log(` got: ${result.got}`);

@@ -54,15 +55,15 @@ hasFailedExpectations = true;

function printExchangeContext(req, res, userContext) {
artillery.log(chalk.yellow(' Request params:'));
artillery.log(prepend(req.url, ' '));
artillery.log(prepend(JSON.stringify(req.json || '', null, 2), ' '));
artillery.log(chalk.yellow(' Headers:'));
console.log(chalk.yellow(' Request params:'));
console.log(prepend(req.url, ' '));
console.log(prepend(JSON.stringify(req.json || '', null, 2), ' '));
console.log(chalk.yellow(' Headers:'));
Object.keys(res.headers).forEach(function(h) {
artillery.log(` ${h}: ${res.headers[h]}`);
console.log(` ${h}: ${res.headers[h]}`);
});
artillery.log(chalk.yellow(' Body:'));
artillery.log(prepend(String(JSON.stringify(res.body, null, 2)), ' '));
console.log(chalk.yellow(' Body:'));
console.log(res.body?.substring(0, 512));
artillery.log(chalk.yellow(' User variables:'));
console.log(chalk.yellow(' User variables:'));
Object.keys(userContext.vars).filter(varName => varName !== '$processEnvironment').forEach(function(varName) {
artillery.log(` ${varName}: ${userContext.vars[varName]}`);
console.log(` ${varName}: ${userContext.vars[varName]}`);
});

@@ -72,3 +73,3 @@ }

function jsonPrint(requestExpectations, req, res, userContext) {
artillery.log(JSON.stringify(requestExpectations));
console.log(JSON.stringify(requestExpectations));
}

@@ -75,0 +76,0 @@

{
"name": "artillery-plugin-expect",
"version": "2.1.0",
"description": "Expectations and assertions for HTTP",
"version": "2.2.1",
"description": "Expectations and assertions for HTTP scenarios",
"main": "index.js",

@@ -20,14 +20,5 @@ "engines": {

"devDependencies": {
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"artillery": "^2.0.0-2",
"ava": "^3.15.0",
"husky": "^7.0.2",
"shelljs": "^0.8.4"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -e"
}
}
}