artillery-plugin-expect
Advanced tools
Comparing version 1.5.0 to 2.0.0-dev1
14
index.js
@@ -19,2 +19,12 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
function ExpectationsPlugin(script, events) { | ||
if(!global.artillery && !global.artillery.log) { | ||
console.error('This plugin requires Artillery v2'); | ||
return; | ||
} | ||
if (typeof process.env.WORKER_ID === 'undefined') { | ||
debug('Not running in a worker, exiting'); | ||
return; | ||
} | ||
this.script = script; | ||
@@ -74,5 +84,5 @@ this.events = events; | ||
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}`); | ||
} | ||
@@ -79,0 +89,0 @@ return done(); |
@@ -13,10 +13,8 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
pretty: prettyPrint, | ||
json: jsonPrint | ||
json: jsonPrint, | ||
prettyError: prettyError | ||
}; | ||
function prettyPrint(requestExpectations, req, res, userContext) { | ||
console.log( | ||
chalk.blue('*', req.method, urlparse(req.url).path), | ||
req.name ? '- ' + req.name : '' | ||
); | ||
artillery.log(`${chalk.blue('*', req.method, urlparse(req.url).path)} ${req.name ? '- ' + req.name : ''}`, {}); | ||
@@ -26,11 +24,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 +45,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 +63,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 +75,0 @@ return text |
{ | ||
"name": "artillery-plugin-expect", | ||
"version": "1.5.0", | ||
"version": "2.0.0-dev1", | ||
"description": "Expectations and assertions for HTTP", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"@commitlint/config-conventional": "^7.6.0", | ||
"artillery": "^1.7.5", | ||
"artillery": "^2.0.0-dev10", | ||
"ava": "^3.8.1", | ||
@@ -23,0 +23,0 @@ "husky": "^1.3.1", |
@@ -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`, | ||
{ | ||
@@ -172,0 +173,0 @@ silent: false |
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
281811
16
656
2
3