artillery-plugin-expect
Advanced tools
Comparing version
70
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,8 +19,8 @@ module.exports.Plugin = ExpectationsPlugin; | ||
function ExpectationsPlugin(script, events) { | ||
if(!global.artillery && !global.artillery.log) { | ||
console.error('This plugin requires Artillery v2'); | ||
if(!global.artillery || !global.artillery.log) { | ||
console.error('artillery-plugin-expect requires Artillery v2'); | ||
return; | ||
} | ||
if (typeof process.env.WORKER_ID === 'undefined') { | ||
if (typeof process.env.LOCAL_WORKER_ID === 'undefined') { | ||
debug('Not running in a worker, exiting'); | ||
@@ -49,3 +48,2 @@ return; | ||
scenario.afterScenario = [].concat(scenario.afterScenario || []); | ||
scenario.afterScenario.push('expectationsPluginMaybeFlushDatadog'); | ||
}); | ||
@@ -55,3 +53,2 @@ | ||
script.config.processor.expectationsPluginOnError = expectationsPluginOnError; | ||
script.config.processor.expectationsPluginMaybeFlushDatadog = expectationsPluginMaybeFlushDatadog; | ||
@@ -64,17 +61,5 @@ script.config.processor.expectationsPluginSetExpectOptions = function( | ||
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(); | ||
@@ -134,3 +119,16 @@ }; | ||
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); | ||
} | ||
}); | ||
events.emit('plugin:expect:expectations', requestExpectations); | ||
const formatterName = userContext.expectationsPlugin.formatter; | ||
FORMATTERS[formatterName].call( | ||
this, | ||
@@ -143,12 +141,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; | ||
@@ -166,20 +154,2 @@ | ||
function expectationsPluginMaybeFlushDatadog(userContext, events, done) { | ||
if ( | ||
userContext.expectationsPlugin && | ||
userContext.expectationsPlugin.datadog | ||
) { | ||
userContext.expectationsPlugin.datadog.flush( | ||
() => { | ||
return done(); | ||
}, | ||
() => { | ||
return done(); | ||
} | ||
); | ||
} else { | ||
return done(); | ||
} | ||
} | ||
function maybeParseBody(res) { | ||
@@ -186,0 +156,0 @@ let body; |
@@ -82,7 +82,7 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const valueToCheck = res.headers[expected[0]]; | ||
const valueToCheck = res.headers[expected[0]].toString(); | ||
debug('valueToCheck = ' + valueToCheck); | ||
result.got = valueToCheck; | ||
if (valueToCheck === expected[1]) { | ||
if (valueToCheck === (expected[1] || '').toString()) { | ||
result.ok = true; | ||
@@ -89,0 +89,0 @@ } |
@@ -14,7 +14,14 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
json: jsonPrint, | ||
prettyError: prettyError | ||
prettyError: prettyError, | ||
silent: silent | ||
}; | ||
function silent(requestExpectation, req, res, userContext) { | ||
return; | ||
} | ||
function prettyPrint(requestExpectations, req, res, userContext) { | ||
artillery.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 : ''}`); | ||
} | ||
@@ -27,3 +34,3 @@ let hasFailedExpectations = false; | ||
result.type | ||
} ${result.got} `, {} | ||
} ${result.got} ` | ||
); | ||
@@ -30,0 +37,0 @@ |
{ | ||
"name": "artillery-plugin-expect", | ||
"version": "2.0.0-dev1", | ||
"version": "2.0.0", | ||
"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": "^2.0.0-dev10", | ||
"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-2", | ||
"ava": "^3.15.0", | ||
"husky": "^7.0.2", | ||
"shelljs": "^0.8.4" | ||
}, | ||
@@ -26,0 +28,0 @@ "husky": { |
@@ -20,3 +20,3 @@ # artillery-plugin-expect | ||
🐞 Please report bugs over at [https://github.com/artilleryio/artillery/issues](https://github.com/artilleryio/artillery/issues) | ||
💬 Ask for help or propose a new features via [Github Discussions](https://github.com/artilleryio/artillery/discussions) our our [Discord server](https://discord.gg/37vGhH3NMB) | ||
💬 Ask for help or propose a new features via [Github Discussions](https://github.com/artilleryio/artillery/discussions) | ||
🐦 Follow [@artilleryio](https://twitter.com/intent/follow?original_referer=https%3A%2F%2Fartillery.io%2F&ref_src=twsrc%5Etfw®ion=follow_link&screen_name=artilleryio&tw_p=followbutton) on Twitter for updates | ||
@@ -23,0 +23,0 @@ |
@@ -164,2 +164,76 @@ 'use strict'; | ||
test('Expectation: headerEquals', t => { | ||
const expectations = require('../lib/expectations'); | ||
// expectation - response object - user context - expected result | ||
const data = [ | ||
[ | ||
[ | ||
'set-cookie', | ||
[ | ||
'cookie1-name={{ cookie1value }};Path=/', | ||
'cookie2-name={{ cookie2value }};Path=/', | ||
], | ||
], | ||
{ | ||
headers: { | ||
'set-cookie': [ | ||
'cookie1-name=value1;Path=/', | ||
'cookie2-name=value2;Path=/', | ||
], | ||
}, | ||
}, | ||
{ | ||
vars: { | ||
cookie1value: 'value1', | ||
cookie2value: 'value2', | ||
}, | ||
}, | ||
true | ||
], | ||
[ | ||
[ | ||
'content-encoding', | ||
'deflate, gzip', | ||
], | ||
{ | ||
headers: { | ||
'content-enconding': 'gzip', | ||
}, | ||
}, | ||
{ | ||
vars: {}, | ||
}, | ||
false | ||
], | ||
[ | ||
[ | ||
'x-request-id', | ||
'{{ reqId }}', | ||
], | ||
{ | ||
headers: { | ||
'x-request-id': 'abcdef', | ||
}, | ||
}, | ||
{ | ||
vars: { | ||
reqId: 'abcdef' | ||
}, | ||
}, | ||
true | ||
] | ||
]; | ||
data.forEach((e) => { | ||
const result = expectations.headerEquals( | ||
{ headerEquals: e[0] }, | ||
{}, // body | ||
{}, // req | ||
e[1], // res | ||
e[2]); // userContext | ||
t.true(result.ok === e[3]); | ||
}); | ||
}); | ||
test('Integration with Artillery', async (t) => { | ||
@@ -192,1 +266,16 @@ shelljs.env["ARTILLERY_PLUGIN_PATH"] = path.resolve(__dirname, '..', '..'); | ||
}); | ||
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; | ||
t.true(output.indexOf('expect.ok') > -1); | ||
t.true(result.code === 0); | ||
}); |
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
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
3
-25%696
6.1%1
-50%281638
-0.06%15
-6.25%4
33.33%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated