Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: exclude folders support #1145

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 56 additions & 9 deletions lib/runner/extract-runnable-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand All @@ -115,12 +127,14 @@ var sdk = require('postman-collection'),
* @param {?Array<String>} [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 || [];
Expand All @@ -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);
},

Expand All @@ -166,14 +190,18 @@ var sdk = require('postman-collection'),
* @param {Array<String>} [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, []);
}
Expand All @@ -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]));
Expand All @@ -212,13 +247,15 @@ var sdk = require('postman-collection'),
* @param {Array<String>} [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, []);
Expand Down Expand Up @@ -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
};

Expand Down
6 changes: 5 additions & 1 deletion lib/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>} [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
Expand All @@ -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
Expand Down