diff --git a/lib/runner/extract-runnable-items.js b/lib/runner/extract-runnable-items.js index 1d31b5f31..7c8f7a292 100644 --- a/lib/runner/extract-runnable-items.js +++ b/lib/runner/extract-runnable-items.js @@ -4,6 +4,14 @@ var sdk = require('postman-collection'), DEFAULT_LOOKUP_STRATEGY = 'idOrName', INVALID_LOOKUP_STRATEGY_ERROR = 'runtime~extractRunnableItems: Invalid entrypoint lookupStrategy', + + DEFAULT_IGNORE_STRATEGY = 'itemOrGroup', + INVALID_IGNORE_STRATEGY_ERROR = 'runtime~extractRunnableItems: Invalid exclude ignoreStrategy', + + ignoreStrategyMap = { + itemOrGroup: findItemOrGroup, + itemsOrGroups: findItemsOrGroups + }, /** * Accumulate all items in order if entry point is a collection/folder. @@ -106,6 +114,10 @@ var sdk = require('postman-collection'), return _accumulatedItems; }, + findItemsOrGroupsToExclude = function (options, itemGroup, excludeSubset = {}, _continueAccumulation = false) { + + } + /** * Finds an item or group from a path. The path should be an array of ids from the parent chain. * @@ -115,12 +127,14 @@ var sdk = require('postman-collection'), * @param {?Array} [options.path] * @param {Function} callback */ - lookupByPath = function (collection, options, callback) { + lookupByPath = function (collection, options, exclude={}, callback) { var lookupPath, lastMatch = collection, lookupOptions = options || {}, i, ii; + + console.log('entrypoint4:', JSON.stringify(options)) // path can be empty, if item/group is at the top level lookupPath = lookupOptions.path || []; @@ -144,15 +158,25 @@ var sdk = require('postman-collection'), * @param {String} [options.execute] * @param {Function} callback */ - lookupByIdOrName = function (collection, options, callback) { + lookupByIdOrName = function (collection, options, exclude, callback) { var match = options.execute, - matched; + matched, itemToIgnore; + + console.log('entrypoint3:', JSON.stringify(options)) if (!match) { return callback(null, []); } // do a recursive lookup matched = findItemOrGroup(collection, match); + if (!exclude.ignore) { + itemToIgnore = findItemsOrGroupsToExclude(exclude, collection, exclude.ignore); + + if (matched.id === itemToIgnore.id || matched.name === itemToIgnore.name) { + return callback(null, []); + } + } + callback(null, flattenNode(matched), matched); }, @@ -166,14 +190,18 @@ var sdk = require('postman-collection'), * @param {Array} [options.execute] * @param {Function} callback */ - lookupByMultipleIdOrName = function (collection, options, callback) { + lookupByMultipleIdOrName = function (collection, options, exclude, callback) { var entrypoints = options.execute, entrypointLookup = {}, + excludeItemsLookup = {}, runnableItems = [], items, + itemsToIgnore, i, ii; + console.log('entrypoint2:', JSON.stringify(options)) + if (!(Array.isArray(entrypoints) && entrypoints.length)) { return callback(null, []); } @@ -194,6 +222,13 @@ var sdk = require('postman-collection'), return callback(null, []); } + if (exlude.ignore) { + // for (j = 0, jj = itemsToIgnore.length; j < jj; j++) { + // excludeItemsLookup[itemsToIgnore[j]] = true; + // } + itemsToIgnore = findItemsOrGroupsToExclude(exclude, collection, excludeItemsLookup, true); + } + // extract runnable items from the searched items. for (i = 0, ii = items.members.length; i < ii; i++) { runnableItems = runnableItems.concat(flattenNode(items.members[i])); @@ -212,13 +247,15 @@ var sdk = require('postman-collection'), * @param {Array} [options.execute] * @param {Function} callback */ - lookupByOrder = function (collection, options, callback) { + lookupByOrder = function (collection, options, exclude={}, callback) { var entrypoints = options.execute, entrypointLookup = {}, runnableItems = [], items, i, ii; + + console.log('entrypoint1:', JSON.stringify(options)) if (!(Array.isArray(entrypoints) && entrypoints.length)) { return callback(null, []); @@ -265,19 +302,29 @@ var sdk = require('postman-collection'), * @param {String} [entrypoint.lookupStrategy=idOrName] strategy to use for entrypoint lookup [idOrName, path] * @param {Function} callback */ - extractRunnableItems = function (collection, entrypoint, callback) { + extractRunnableItems = function (collection, entrypoint, exclude, callback) { var lookupFunction, - lookupStrategy; + ignoreFunction, + lookupStrategy, + ignoreStrategy; + + console.log('entrypoint:', JSON.stringify(entrypoint)) // if no entrypoint is specified, flatten the entire collection - if (!entrypoint) { return callback(null, flattenNode(collection), collection); } + if (!entrypoint && !exclude) { return callback(null, flattenNode(collection), collection); } lookupStrategy = entrypoint.lookupStrategy || DEFAULT_LOOKUP_STRATEGY; + ignoreStrategy = exclude.ignoreStrategy || DEFAULT_IGNORE_STRATEGY; + + // lookup exclude pool using given strategy + // eslint-disable-next-line no-cond-assign + (ignoreFunction = ignoreStrategyMap[ignoreStrategy]) ? + ignoreStrategyMap[ignoreStrategy] : callback(new Error(INVALID_IGNORE_STRATEGY_ERROR)); // eslint-disable-line callback-return // lookup entry using given strategy // eslint-disable-next-line no-cond-assign (lookupFunction = lookupStrategyMap[lookupStrategy]) ? - lookupFunction(collection, entrypoint, callback) : + lookupFunction(collection, entrypoint, exclude, callback) : callback(new Error(INVALID_LOOKUP_STRATEGY_ERROR)); // eslint-disable-line callback-return }; diff --git a/lib/runner/index.js b/lib/runner/index.js index 3e3a65fa5..64fe5f7c5 100644 --- a/lib/runner/index.js +++ b/lib/runner/index.js @@ -73,6 +73,10 @@ _.assign(Runner.prototype, { * Can be Name if `entrypoint.lookupStrategy` is `idOrName` * @param {String} [options.entrypoint.lookupStrategy=idOrName] strategy to lookup the entrypoint [idOrName, path] * @param {Array} [options.entrypoint.path] path to lookup + * @param {Object} [options.exclude] + * @param {String} [options.exclude.ignore] ID of the item-group to be ignored. + * Can be Name if `entrypoint.ignoreStrategy` is `findItemOrGroup` + * @param {String} [options.entrypoint.ignoreStrategy=findItemOrGroup] strategy to lookup the excluded items * @param {Object} [options.run] Run-specific options, such as options related to the host * * @param {Function} callback @@ -93,7 +97,7 @@ _.assign(Runner.prototype, { // required to be coded in each lookup strategy // // serialise the items into a linear array based on the lookup strategy provided as input - extractRunnableItems(collection, options.entrypoint, function (err, runnableItems, entrypoint) { + extractRunnableItems(collection, options.entrypoint, options.exclude, function (err, runnableItems, entrypoint) { if (err || !runnableItems) { return callback(new Error('Error fetching run items')); } // Bail out only if: abortOnError is set and the returned entrypoint is invalid