chai-postman
Advanced tools
Comparing version 1.0.5 to 1.1.0-beta.1
# Chai Postman Changelog | ||
#### v1.1.0 (Unreleased) | ||
* Added support for JSON schema assertions | ||
* Updated dependencies :arrow_up: | ||
#### v1.0.5 (September 21, 2018) | ||
@@ -4,0 +8,0 @@ * Updated dependencies :arrow_up: |
@@ -29,5 +29,6 @@ var FIRST_LINE = /(.*?)\n.*/g, | ||
* @param {Object} _ - An instance of Lodash, passed from the Sandbox. | ||
* @param {Function} Ajv - An instance of Ajv, passed from the Sandbox. | ||
* @returns {Function} - A chai assertion extension method that references the sdk in a closure. | ||
*/ | ||
module.exports = function (sdk, _) { | ||
module.exports = function (sdk, _, Ajv) { | ||
var requestOrResponse = function (what) { | ||
@@ -381,2 +382,30 @@ return sdk.Request.isRequest(what) && 'request' || sdk.Response.isResponse(what) && 'response' || undefined; | ||
Assertion.addMethod('jsonSchema', function (schema, options) { | ||
new Assertion(schema).to.be.an('object'); | ||
var ajv, | ||
valid, | ||
data; | ||
options = Object.assign({ | ||
allErrors: true // check all rules collecting all errors | ||
}, options); | ||
if (sdk.Response.isResponse(this._obj) || sdk.Request.isRequest(this._obj) && | ||
typeof this._obj.json === 'function') { | ||
data = this._obj.json(); | ||
} | ||
else { | ||
data = this._obj; | ||
} | ||
ajv = new Ajv(options); | ||
valid = ajv.validate(schema, data); | ||
this.assert(valid && !ajv.errors, | ||
'expected data to satisfy schema but found following errors: \n' + | ||
ajv.errorsText(), | ||
'expected data to not satisfy schema', true, valid); | ||
}); | ||
// @todo add tests for: | ||
@@ -383,0 +412,0 @@ // 1. request and response content type |
@@ -15,5 +15,3 @@ #!/usr/bin/env node | ||
'./lib', | ||
'./bin', | ||
'./test', | ||
'./examples/*.js', | ||
'./npm/*.js', | ||
@@ -20,0 +18,0 @@ './index.js' |
#!/usr/bin/env node | ||
require('shelljs/global'); | ||
var chalk = require('chalk'), | ||
var sh = require('shelljs'), | ||
chalk = require('chalk'), | ||
async = require('async'), | ||
_ = require('lodash'), | ||
path = require('path'), | ||
Mocha = require('mocha'), | ||
@@ -16,15 +14,4 @@ recursive = require('recursive-readdir'), | ||
*/ | ||
SPEC_SOURCE_DIR = './test/system', | ||
SPEC_SOURCE_DIR = './test/system'; | ||
/** | ||
* Load a JSON from file synchronously, used as an alternative to dynamic requires. | ||
* | ||
* @param {String} file - The path to the JSON file to load from. | ||
* @returns {Object} - The parsed JSON object contained in the file at the provided path. | ||
* @throws {SyntaxError} - Throws an error if the provided JSON file is invalid. | ||
*/ | ||
loadJSON = function (file) { | ||
return JSON.parse(require('fs').readFileSync(path.join(__dirname, file)).toString()); | ||
}; | ||
module.exports = function (exit) { | ||
@@ -45,3 +32,3 @@ // banner line | ||
exec('dependency-check ./package.json --extra --no-dev --missing', next); | ||
sh.exec('dependency-check ./package.json --extra --no-dev --missing', next); | ||
}, | ||
@@ -76,42 +63,2 @@ | ||
}); | ||
}, | ||
/** | ||
* Execute nsp checks on project dependencies. In-program usage of nsp is a bit tricky as we have to emulate the | ||
* cli script's usage of internal nsp functions. | ||
* | ||
* @param {Function} next - The callback function invoked upon completion of the NSP check. | ||
* @returns {*} | ||
*/ | ||
function (next) { | ||
var nsp = require('nsp'), | ||
pkg = loadJSON('../package.json'), | ||
nsprc = loadJSON('../.nsprc'); | ||
console.info('processing nsp for security vulnerabilities...\n'); | ||
// we do not pass full package for privacy concerns and also to add the ability to ignore exclude packages, | ||
// hence we customise the package before we send it | ||
nsp.check({ | ||
offline: false, | ||
package: _.merge({ | ||
dependencies: _.omit(pkg.dependencies, _.keys(nsprc.exclusions) || []) | ||
}, _.pick(pkg, ['name', 'version', 'homepage', 'repository'])) | ||
}, function (err, result) { | ||
// if processing nsp had an error, simply print that and exit | ||
if (err) { | ||
console.error(chalk.red('There was an error processing NSP!\n') + chalk.gray(err.message || err) + | ||
'\n\nSince NSP server failure is not a blocker for tests, tests are not marked as failure!'); | ||
return next(); | ||
} | ||
// in case an nsp violation is found, we raise an error | ||
if (result.length) { | ||
console.error(nsp.formatters.default(err, result)); | ||
return next(1); | ||
} | ||
console.info(chalk.green('nsp ok!\n')); | ||
return next(); | ||
}); | ||
} | ||
@@ -122,2 +69,2 @@ ], exit); | ||
// ensure we run this script exports if this is a direct stdin.tty run | ||
!module.parent && module.exports(exit); | ||
!module.parent && module.exports(process.exit); |
@@ -7,8 +7,7 @@ #!/usr/bin/env node | ||
require('shelljs/global'); | ||
// set directories and files for test and coverage report | ||
var path = require('path'), | ||
const path = require('path'), | ||
NYC = require('nyc'), | ||
sh = require('shelljs'), | ||
chalk = require('chalk'), | ||
@@ -24,8 +23,9 @@ recursive = require('recursive-readdir'), | ||
test('-d', COV_REPORT_PATH) && rm('-rf', COV_REPORT_PATH); | ||
mkdir('-p', COV_REPORT_PATH); | ||
sh.test('-d', COV_REPORT_PATH) && sh.rm('-rf', COV_REPORT_PATH); | ||
sh.mkdir('-p', COV_REPORT_PATH); | ||
var Mocha = require('mocha'), | ||
nyc = new NYC({ | ||
reporter: ['text', 'lcov'], | ||
hookRequire: true, | ||
reporter: ['text', 'lcov', 'text-summary'], | ||
reportDir: COV_REPORT_PATH, | ||
@@ -57,2 +57,2 @@ tempDirectory: COV_REPORT_PATH | ||
// ensure we run this script exports if this is a direct stdin.tty run | ||
!module.parent && module.exports(exit); | ||
!module.parent && module.exports(process.exit); |
{ | ||
"name": "chai-postman", | ||
"version": "1.0.5", | ||
"version": "1.1.0-beta.1", | ||
"description": "A Chai plugin for Postman assertions", | ||
@@ -28,12 +28,13 @@ "main": "index.js", | ||
"devDependencies": { | ||
"ajv": "6.6.2", | ||
"async": "2.6.1", | ||
"browserify": "16.2.2", | ||
"chai": "4.1.2", | ||
"browserify": "16.2.3", | ||
"chai": "4.2.0", | ||
"chalk": "2.4.1", | ||
"dependency-check": "3.2.0", | ||
"editorconfig": "0.15.0", | ||
"eslint": "4.19.1", | ||
"eslint-plugin-jsdoc": "3.7.1", | ||
"eslint-plugin-lodash": "3.1.0", | ||
"eslint-plugin-mocha": "4.12.0", | ||
"dependency-check": "3.2.1", | ||
"editorconfig": "0.15.2", | ||
"eslint": "5.8.0", | ||
"eslint-plugin-jsdoc": "3.14.1", | ||
"eslint-plugin-lodash": "5.0.1", | ||
"eslint-plugin-mocha": "5.2.0", | ||
"eslint-plugin-security": "1.4.0", | ||
@@ -43,3 +44,3 @@ "js-yaml": "3.12.0", | ||
"jsdoc-to-markdown": "4.0.1", | ||
"karma": "2.0.2", | ||
"karma": "3.1.4", | ||
"karma-browserify": "5.3.0", | ||
@@ -51,9 +52,9 @@ "karma-chrome-launcher": "2.2.0", | ||
"mocha": "5.2.0", | ||
"nsp": "2.8.1", | ||
"nyc": "11.7.2", | ||
"parse-gitignore": "0.4.0", | ||
"postman-collection": "3.3.0", | ||
"pretty-ms": "3.2.0", | ||
"nyc": "13.1.0", | ||
"parse-gitignore": "1.0.1", | ||
"postman-collection": "3.4.0", | ||
"pretty-ms": "4.0.0", | ||
"puppeteer": "1.11.0", | ||
"recursive-readdir": "2.2.2", | ||
"shelljs": "0.8.2", | ||
"shelljs": "0.8.3", | ||
"watchify": "3.11.0" | ||
@@ -60,0 +61,0 @@ }, |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
63180
30
16
558
1