Skip to content

Commit fdaa0fc

Browse files
wip: exclude folders support
1 parent daf1da0 commit fdaa0fc

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

lib/runner/extract-runnable-items.js

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ var sdk = require('postman-collection'),
44

55
DEFAULT_LOOKUP_STRATEGY = 'idOrName',
66
INVALID_LOOKUP_STRATEGY_ERROR = 'runtime~extractRunnableItems: Invalid entrypoint lookupStrategy',
7+
8+
DEFAULT_IGNORE_STRATEGY = 'itemOrGroup',
9+
INVALID_IGNORE_STRATEGY_ERROR = 'runtime~extractRunnableItems: Invalid exclude ignoreStrategy',
10+
11+
ignoreStrategyMap = {
12+
itemOrGroup: findItemOrGroup,
13+
itemsOrGroups: findItemsOrGroups
14+
},
715

816
/**
917
* Accumulate all items in order if entry point is a collection/folder.
@@ -106,6 +114,10 @@ var sdk = require('postman-collection'),
106114
return _accumulatedItems;
107115
},
108116

117+
findItemsOrGroupsToExclude = function (options, itemGroup, excludeSubset = {}, _continueAccumulation = false) {
118+
119+
}
120+
109121
/**
110122
* Finds an item or group from a path. The path should be an array of ids from the parent chain.
111123
*
@@ -115,12 +127,14 @@ var sdk = require('postman-collection'),
115127
* @param {?Array<String>} [options.path]
116128
* @param {Function} callback
117129
*/
118-
lookupByPath = function (collection, options, callback) {
130+
lookupByPath = function (collection, options, exclude={}, callback) {
119131
var lookupPath,
120132
lastMatch = collection,
121133
lookupOptions = options || {},
122134
i,
123135
ii;
136+
137+
console.log('entrypoint4:', JSON.stringify(options))
124138

125139
// path can be empty, if item/group is at the top level
126140
lookupPath = lookupOptions.path || [];
@@ -144,15 +158,25 @@ var sdk = require('postman-collection'),
144158
* @param {String} [options.execute]
145159
* @param {Function} callback
146160
*/
147-
lookupByIdOrName = function (collection, options, callback) {
161+
lookupByIdOrName = function (collection, options, exclude, callback) {
148162
var match = options.execute,
149-
matched;
163+
matched, itemToIgnore;
164+
165+
console.log('entrypoint3:', JSON.stringify(options))
150166

151167
if (!match) { return callback(null, []); }
152168

153169
// do a recursive lookup
154170
matched = findItemOrGroup(collection, match);
155171

172+
if (!exclude.ignore) {
173+
itemToIgnore = findItemsOrGroupsToExclude(exclude, collection, exclude.ignore);
174+
175+
if (matched.id === itemToIgnore.id || matched.name === itemToIgnore.name) {
176+
return callback(null, []);
177+
}
178+
}
179+
156180
callback(null, flattenNode(matched), matched);
157181
},
158182

@@ -166,14 +190,18 @@ var sdk = require('postman-collection'),
166190
* @param {Array<String>} [options.execute]
167191
* @param {Function} callback
168192
*/
169-
lookupByMultipleIdOrName = function (collection, options, callback) {
193+
lookupByMultipleIdOrName = function (collection, options, exclude, callback) {
170194
var entrypoints = options.execute,
171195
entrypointLookup = {},
196+
excludeItemsLookup = {},
172197
runnableItems = [],
173198
items,
199+
itemsToIgnore,
174200
i,
175201
ii;
176202

203+
console.log('entrypoint2:', JSON.stringify(options))
204+
177205
if (!(Array.isArray(entrypoints) && entrypoints.length)) {
178206
return callback(null, []);
179207
}
@@ -194,6 +222,13 @@ var sdk = require('postman-collection'),
194222
return callback(null, []);
195223
}
196224

225+
if (exlude.ignore) {
226+
// for (j = 0, jj = itemsToIgnore.length; j < jj; j++) {
227+
// excludeItemsLookup[itemsToIgnore[j]] = true;
228+
// }
229+
itemsToIgnore = findItemsOrGroupsToExclude(exclude, collection, excludeItemsLookup, true);
230+
}
231+
197232
// extract runnable items from the searched items.
198233
for (i = 0, ii = items.members.length; i < ii; i++) {
199234
runnableItems = runnableItems.concat(flattenNode(items.members[i]));
@@ -212,13 +247,15 @@ var sdk = require('postman-collection'),
212247
* @param {Array<String>} [options.execute]
213248
* @param {Function} callback
214249
*/
215-
lookupByOrder = function (collection, options, callback) {
250+
lookupByOrder = function (collection, options, exclude={}, callback) {
216251
var entrypoints = options.execute,
217252
entrypointLookup = {},
218253
runnableItems = [],
219254
items,
220255
i,
221256
ii;
257+
258+
console.log('entrypoint1:', JSON.stringify(options))
222259

223260
if (!(Array.isArray(entrypoints) && entrypoints.length)) {
224261
return callback(null, []);
@@ -265,19 +302,29 @@ var sdk = require('postman-collection'),
265302
* @param {String} [entrypoint.lookupStrategy=idOrName] strategy to use for entrypoint lookup [idOrName, path]
266303
* @param {Function} callback
267304
*/
268-
extractRunnableItems = function (collection, entrypoint, callback) {
305+
extractRunnableItems = function (collection, entrypoint, exclude, callback) {
269306
var lookupFunction,
270-
lookupStrategy;
307+
ignoreFunction,
308+
lookupStrategy,
309+
ignoreStrategy;
310+
311+
console.log('entrypoint:', JSON.stringify(entrypoint))
271312

272313
// if no entrypoint is specified, flatten the entire collection
273-
if (!entrypoint) { return callback(null, flattenNode(collection), collection); }
314+
if (!entrypoint && !exclude) { return callback(null, flattenNode(collection), collection); }
274315

275316
lookupStrategy = entrypoint.lookupStrategy || DEFAULT_LOOKUP_STRATEGY;
317+
ignoreStrategy = exclude.ignoreStrategy || DEFAULT_IGNORE_STRATEGY;
318+
319+
// lookup exclude pool using given strategy
320+
// eslint-disable-next-line no-cond-assign
321+
(ignoreFunction = ignoreStrategyMap[ignoreStrategy]) ?
322+
ignoreStrategyMap[ignoreStrategy] : callback(new Error(INVALID_IGNORE_STRATEGY_ERROR)); // eslint-disable-line callback-return
276323

277324
// lookup entry using given strategy
278325
// eslint-disable-next-line no-cond-assign
279326
(lookupFunction = lookupStrategyMap[lookupStrategy]) ?
280-
lookupFunction(collection, entrypoint, callback) :
327+
lookupFunction(collection, entrypoint, exclude, callback) :
281328
callback(new Error(INVALID_LOOKUP_STRATEGY_ERROR)); // eslint-disable-line callback-return
282329
};
283330

lib/runner/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ _.assign(Runner.prototype, {
7373
* Can be Name if `entrypoint.lookupStrategy` is `idOrName`
7474
* @param {String} [options.entrypoint.lookupStrategy=idOrName] strategy to lookup the entrypoint [idOrName, path]
7575
* @param {Array<String>} [options.entrypoint.path] path to lookup
76+
* @param {Object} [options.exclude]
77+
* @param {String} [options.exclude.ignore] ID of the item-group to be ignored.
78+
* Can be Name if `entrypoint.ignoreStrategy` is `findItemOrGroup`
79+
* @param {String} [options.entrypoint.ignoreStrategy=findItemOrGroup] strategy to lookup the excluded items
7680
* @param {Object} [options.run] Run-specific options, such as options related to the host
7781
*
7882
* @param {Function} callback
@@ -93,7 +97,7 @@ _.assign(Runner.prototype, {
9397
// required to be coded in each lookup strategy
9498
//
9599
// serialise the items into a linear array based on the lookup strategy provided as input
96-
extractRunnableItems(collection, options.entrypoint, function (err, runnableItems, entrypoint) {
100+
extractRunnableItems(collection, options.entrypoint, options.exclude, function (err, runnableItems, entrypoint) {
97101
if (err || !runnableItems) { return callback(new Error('Error fetching run items')); }
98102

99103
// Bail out only if: abortOnError is set and the returned entrypoint is invalid

0 commit comments

Comments
 (0)