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
368
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 1.5.0 to 2.0.0-1

test/lib/formatters.js

56

index.js

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

const FORMATTERS = require('./lib/formatters');
const REPORTERS = require('./lib/reporters');

@@ -20,2 +19,12 @@ module.exports.Plugin = ExpectationsPlugin;

function ExpectationsPlugin(script, events) {
if(!global.artillery && !global.artillery.log) {
console.error('artillery-plugin-expect requires Artillery v2');
return;
}
if (typeof process.env.WORKER_ID === 'undefined') {
debug('Not running in a worker, exiting');
return;
}
this.script = script;

@@ -52,17 +61,5 @@ this.events = events;

userContext.expectationsPlugin = {};
userContext.expectationsPlugin.outputFormat =
script.config.plugins.expect.outputFormat || 'pretty';
if (script.config.plugins.expect.externalReporting) {
// Datadog-only right now
userContext.expectationsPlugin.reporter = 'datadog';
const reportingConfig = script.config.plugins.expect.externalReporting;
// TODO fix this - metrics is undefined since the beginning
userContext.expectationsPlugin.datadog = metrics.init({
host: reportingConfig.host || 'artillery-expectations',
prefix: reportingConfig.prefix,
flushIntervalSeconds: 5,
defaultTags: reportingConfig.tags
});
}
userContext.expectationsPlugin.formatter = script.config.plugins.expect.formatter ||
script.config.plugins.expect.outputFormat ||
'pretty';
return done();

@@ -76,5 +73,5 @@ };

if (userContext.expectationsPlugin.outputFormat === 'json') {
console.log(JSON.stringify({ ok: false, error: scenarioErr.message }));
artillery.log(JSON.stringify({ ok: false, error: scenarioErr.message }));
} else {
console.log(chalk.red('Error:'), scenarioErr.message);
artillery.log(`${chalk.red('Error:')} ${scenarioErr.message}`);
}

@@ -123,3 +120,14 @@ return done();

FORMATTERS[userContext.expectationsPlugin.outputFormat].call(
requestExpectations.results.forEach((e) => {
if (e.ok) {
events.emit('counter', `plugins.expect.ok`, 1);
events.emit('counter', `plugins.expect.ok.${e.type}`, 1);
} else {
events.emit('counter', `plugins.expect.failed`, 1);
events.emit('counter', `plugins.expect.failed.${e.type}`, 1);
}
});
const formatterName = userContext.expectationsPlugin.formatter;
FORMATTERS[formatterName].call(
this,

@@ -132,12 +140,2 @@ requestExpectations,

if (userContext.expectationsPlugin.reporter) {
REPORTERS[userContext.expectationsPlugin.reporter].call(
this,
requestExpectations,
req,
res,
userContext
);
}
const failedExpectations = results.filter(res => !res.ok).length > 0;

@@ -144,0 +142,0 @@

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

pretty: prettyPrint,
json: jsonPrint
json: jsonPrint,
prettyError: prettyError,
silent: silent
};
function silent(requestExpectation, req, res, userContext) {
return;
}
function prettyPrint(requestExpectations, req, res, userContext) {
console.log(
chalk.blue('*', req.method, urlparse(req.url).path),
req.name ? '- ' + req.name : ''
);
if (requestExpectations.results.length > 0) {
artillery.log(`${chalk.blue('*', req.method, urlparse(req.url).path)} ${req.name ? '- ' + req.name : ''}`, {});
}

@@ -26,11 +31,11 @@ let hasFailedExpectations = false;

requestExpectations.results.forEach(result => {
console.log(
artillery.log(
` ${result.ok ? chalk.green('ok') : chalk.red('not ok')} ${
result.type
} ${result.got} `
} ${result.got} `, {}
);
if (!result.ok) {
console.log(' expected:', result.expected);
console.log(' got:', result.got);
artillery.log(` expected: ${result.expected}`);
artillery.log(` got: ${result.got}`);

@@ -47,15 +52,15 @@ hasFailedExpectations = true;

function printExchangeContext(req, res, userContext) {
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:'));
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:'));
Object.keys(res.headers).forEach(function(h) {
console.log(' ', h, ':', res.headers[h]);
artillery.log(` ${h}: ${res.headers[h]}`);
});
console.log(chalk.yellow(' Body:'));
console.log(prepend(String(JSON.stringify(res.body, null, 2)), ' '));
artillery.log(chalk.yellow(' Body:'));
artillery.log(prepend(String(JSON.stringify(res.body, null, 2)), ' '));
console.log(chalk.yellow(' User variables:'));
artillery.log(chalk.yellow(' User variables:'));
Object.keys(userContext.vars).filter(varName => varName !== '$processEnvironment').forEach(function(varName) {
console.log(' ', varName, ':', userContext.vars[varName]);
artillery.log(` ${varName}: ${userContext.vars[varName]}`);
});

@@ -65,5 +70,12 @@ }

function jsonPrint(requestExpectations, req, res, userContext) {
console.log(JSON.stringify(requestExpectations));
artillery.log(JSON.stringify(requestExpectations));
}
function prettyError(requestExpectations, req, res, userContext) {
if (requestExpectations.results.find(result => !result.ok) === undefined) {
return;
}
prettyPrint(requestExpectations, req, res, userContext);
}
function prepend(text, str) {

@@ -70,0 +82,0 @@ return text

{
"name": "artillery-plugin-expect",
"version": "1.5.0",
"version": "2.0.0-1",
"description": "Expectations and assertions for HTTP",
"main": "index.js",
"engines": {
"node": ">= 14.17.6"
},
"scripts": {

@@ -12,14 +15,13 @@ "test": "bash test/run.sh"

"dependencies": {
"chalk": "^2.4.2",
"datadog-metrics": "^0.9.3",
"debug": "^3.2.6",
"lodash": "^4.17.15"
"chalk": "^4.1.2",
"debug": "^4.3.2",
"lodash": "^4.17.21"
},
"devDependencies": {
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^7.6.0",
"artillery": "^1.7.5",
"ava": "^3.8.1",
"husky": "^1.3.1",
"shelljs": "^0.8.3"
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"artillery": "^2.0.0-dev10",
"ava": "^3.15.0",
"husky": "^7.0.2",
"shelljs": "^0.8.4"
},

@@ -26,0 +28,0 @@ "husky": {

@@ -19,3 +19,4 @@ 'use strict';

template: require('artillery/util').template
}
},
log: console.log.bind(console)
};

@@ -140,3 +141,3 @@

[ 'json', {}, 'charset=utf-8; application/problem+json', {}, true ],
[ 'text/plain', 'string', 'text/plain', {}, true ],

@@ -169,3 +170,3 @@ [ 'TEXT/PLAIN', 'string', 'text/plain', {}, true ],

const result = shelljs.exec(
`${__dirname}/../node_modules/.bin/artillery run ${__dirname}/pets-test.yaml`,
`${__dirname}/../node_modules/.bin/artillery run --solo -q ${__dirname}/pets-test.yaml`,
{

@@ -193,1 +194,17 @@ silent: false

});
test('Produce metrics', async(t) => {
shelljs.env["ARTILLERY_PLUGIN_PATH"] = path.resolve(__dirname, '..', '..');
shelljs.env["PATH"] = process.env.PATH;
const result = shelljs.exec(
`${__dirname}/../node_modules/.bin/artillery run --solo ${__dirname}/pets-test.yaml`,
{
silent: false
});
const output = result.stdout;
console.log(output);
t.true(output.indexOf('plugins.expect') > -1);
t.true(result.code === 0);
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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