artillery-plugin-expect
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -93,7 +93,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
let body = maybeParseBody(res); | ||
_.each(expectations, ex => { | ||
const checker = Object.keys(ex)[0]; | ||
debug(`checker: ${checker}`); | ||
let result = EXPECTATIONS[checker].call( | ||
let result = EXPECTATIONS[checker]?.call( | ||
this, | ||
@@ -156,4 +155,5 @@ ex, | ||
( | ||
res.headers['content-type'].indexOf('application/json') !== -1 || | ||
res.headers['content-type'].indexOf('application/problem+json') !== -1 | ||
res.headers['content-type'].indexOf('application/json') !== -1 | ||
|| res.headers['content-type'].indexOf('application/problem+json') !== -1 | ||
|| res.headers['content-type'].indexOf('application/ld+json') !== -1 | ||
) | ||
@@ -160,0 +160,0 @@ ) { |
@@ -8,3 +8,2 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const debug = require('debug')('plugin:expect'); | ||
const chalk = require('chalk'); | ||
const template = global.artillery ? global.artillery.util.template : require('artillery/util').template; | ||
@@ -21,5 +20,44 @@ const _ = require('lodash'); | ||
matchesRegexp: expectMatchesRegexp, | ||
notHasProperty: expectNotHasProperty | ||
notHasProperty: expectNotHasProperty, | ||
cdnHit: expectCdnHit, | ||
}; | ||
function expectCdnHit(expectation, body, req, res, userContext) { | ||
debug('check cdn'); | ||
debug('expectation'); | ||
let result = { | ||
ok: false, | ||
type: 'cdnHit', | ||
got: 'cache status header not found' | ||
}; | ||
if(expectation.cdnHit) { | ||
result.expected = 'a cache header indicating a cache hit'; | ||
} else { | ||
result.expected = 'a cache header indicating a cache miss'; | ||
} | ||
const cacheHeaderNames = [ | ||
'cf-cache-status', // CloudFlare | ||
'x-cache', // CloudFront, Fastly | ||
'x-vercel-cache' // Vercel | ||
]; | ||
const expectedHeaderValues = expectation.cdnHit ? ['hit', 'stale'] : ['miss']; | ||
for(const h of cacheHeaderNames) { | ||
if (res.headers[h]) { | ||
for(const headerValue of expectedHeaderValues) { | ||
if (res.headers[h].toLowerCase().startsWith(headerValue)) { | ||
result.ok = true; | ||
result.got = `${h} is ${res.headers[h]}`; | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
function expectEquals(expectation, body, req, res, userContext) { | ||
@@ -113,7 +151,8 @@ debug('check equals'); | ||
if ( | ||
body !== null && | ||
body !== null && | ||
typeof body === 'object' && | ||
( | ||
res.headers['content-type'].indexOf('application/json') !== -1 || | ||
res.headers['content-type'].indexOf('application/problem+json') !== -1 | ||
res.headers['content-type'].indexOf('application/json') !== -1 | ||
|| res.headers['content-type'].indexOf('application/problem+json') !== -1 | ||
|| res.headers['content-type'].indexOf('application/ld+json') !== -1 | ||
) | ||
@@ -120,0 +159,0 @@ ) { |
{ | ||
"name": "artillery-plugin-expect", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Expectations and assertions for HTTP", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
282795
731