feat: ✨ Created a mini nodeJS server with NewMan for testing without PostMan GUI.
This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
64
node_modules/newman/lib/config/index.js
generated
vendored
Normal file
64
node_modules/newman/lib/config/index.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
var _ = require('lodash'),
|
||||
async = require('async'),
|
||||
|
||||
env = require('./process-env'),
|
||||
rcfile = require('./rc-file');
|
||||
|
||||
/**
|
||||
* Reads configuration from config file, environment variables and CLI arguments. The CLI arguments override environment
|
||||
* variables and environment variables override the configuration read from a file.
|
||||
*
|
||||
* @param {Object} overrides - Configuration overrides (these usually come from the CLI).
|
||||
* @param {Object} options - The wrapper object of settings used for selective configuration loading.
|
||||
* @param {String} options.command - Command name. Used for loading the required options from the config file.
|
||||
* @param {Boolean=} options.ignoreRcFile - If true, the RC file is ignored.
|
||||
* @param {Boolean=} options.ignoreProcessEnvironment - If true, the process environment variables are ignored.
|
||||
* @param {Object=} options.loaders - Custom loaders for specific configuration options.
|
||||
* @param {Function} callback - Is called after merging values from the overrides with the values from the rc file and
|
||||
* environment variables.
|
||||
* @returns {*}
|
||||
*/
|
||||
module.exports.get = (overrides, options, callback) => {
|
||||
!callback && _.isFunction(options) && (callback = options, options = {});
|
||||
|
||||
var loaders = options.loaders,
|
||||
commonOptions = _.pick(overrides, ['postmanApiKey']);
|
||||
|
||||
async.waterfall([
|
||||
// Load RC Files.
|
||||
!options.ignoreRcFile ? rcfile.load : (cb) => {
|
||||
return cb(null, {});
|
||||
},
|
||||
// Load Process Environment overrides
|
||||
(fileOptions, cb) => {
|
||||
fileOptions[options.command] && (fileOptions = fileOptions[options.command]);
|
||||
|
||||
return cb(null, _.merge(fileOptions, options.ignoreProcessEnvironment ? {} : env));
|
||||
}
|
||||
], (err, options) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
options = _.mergeWith({}, options, overrides, (dest, src) => {
|
||||
// If the newer value is a null, do not override it.
|
||||
return (src === null) ? dest : undefined;
|
||||
});
|
||||
|
||||
if (_.isEmpty(loaders)) {
|
||||
return callback(null, options);
|
||||
}
|
||||
// sanitize environment option
|
||||
if (!options.environment) {
|
||||
options.environment = {};
|
||||
}
|
||||
// sanitize globals option
|
||||
if (!options.globals) {
|
||||
options.globals = {};
|
||||
}
|
||||
|
||||
async.mapValues(options, (value, name, cb) => {
|
||||
return (value && _.isFunction(loaders[name])) ? loaders[name](value, commonOptions, cb) : cb(null, value);
|
||||
}, callback);
|
||||
});
|
||||
};
|
3
node_modules/newman/lib/config/process-env.js
generated
vendored
Normal file
3
node_modules/newman/lib/config/process-env.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
var envConfig = {}; // todo: read NEWMAN_* variables from process.env
|
||||
|
||||
module.exports = envConfig;
|
59
node_modules/newman/lib/config/rc-file.js
generated
vendored
Normal file
59
node_modules/newman/lib/config/rc-file.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/* eslint-disable no-process-env */
|
||||
var _ = require('lodash'),
|
||||
fs = require('fs'),
|
||||
join = require('path').join,
|
||||
async = require('async'),
|
||||
util = require('../util'),
|
||||
liquidJSON = require('liquid-json'),
|
||||
|
||||
/**
|
||||
* Name of the directory that contains the file denoted by FILE_NAME.
|
||||
*
|
||||
* @type {String}
|
||||
*/
|
||||
POSTMAN_CONFIG_DIR = 'postman',
|
||||
|
||||
/**
|
||||
* Name of the file that contains Newman compliant confguration information.
|
||||
*
|
||||
* @type {String}
|
||||
*/
|
||||
FILE_NAME = 'newmanrc';
|
||||
|
||||
/**
|
||||
* Configuration loader to acquire run settings from a file present in the home directory: POSTMAN_CONFIG_DIR/FILE_NAME.
|
||||
*
|
||||
* @param {Function} callback - The callback function invoked to mark the completion of the config loading routine.
|
||||
* @returns {*}
|
||||
*/
|
||||
module.exports.load = (callback) => {
|
||||
var iswin = (/^win/).test(process.platform),
|
||||
home = iswin ? process.env.USERPROFILE : process.env.HOME,
|
||||
|
||||
configFiles = [];
|
||||
|
||||
!iswin && configFiles.push(join('/etc', POSTMAN_CONFIG_DIR, FILE_NAME));
|
||||
home && configFiles.push(join(home, '.' + POSTMAN_CONFIG_DIR, FILE_NAME));
|
||||
configFiles.push(join(process.cwd(), '.' + FILE_NAME));
|
||||
|
||||
async.mapSeries(configFiles, (path, cb) => {
|
||||
fs.readFile(path, (err, data) => {
|
||||
if (err) {
|
||||
return cb(null, {}); // err masked to avoid overpopulating terminal with missing .newmanrc messages
|
||||
}
|
||||
data && data.toString && (data = data.toString(util.detectEncoding(data)).trim());
|
||||
try {
|
||||
return cb(null, liquidJSON.parse(data));
|
||||
}
|
||||
catch (e) {
|
||||
return cb(_.set(e, 'help', `The file at ${path} contains invalid data.`));
|
||||
}
|
||||
});
|
||||
}, (err, files) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
return callback(null, _.merge.apply(this, files));
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user