artillery-plugin-expect
Advanced tools
Comparing version 1.5.0 to 2.0.0-1
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
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
280822
3
644
2
4
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removeddatadog-metrics@^0.9.3
- Removedansi-styles@3.2.1(transitive)
- Removedbignumber.js@9.1.2(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddatadog-metrics@0.9.3(transitive)
- Removeddebug@3.1.03.2.7(transitive)
- Removeddeep-extend@0.6.0(transitive)
- Removeddogapi@2.8.4(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedextend@3.0.2(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedini@1.3.8(transitive)
- Removedjson-bigint@1.0.0(transitive)
- Removedminimist@1.2.8(transitive)
- Removedms@2.0.0(transitive)
- Removedrc@1.2.8(transitive)
- Removedstrip-json-comments@2.0.1(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedchalk@^4.1.2
Updateddebug@^4.3.2
Updatedlodash@^4.17.21