newman icon indicating copy to clipboard operation
newman copied to clipboard

Feature: Running Single Request from a folder in a Collection

Open adityaofficial10 opened this issue 4 years ago • 13 comments

Fixes #2566, Fixes #1851 .

What does this PR do? This PR is a follow-up to the feature request mentioned under the above cited issue. It allows the user to specify a path to an item which doesn't have unique name in the collection and runs the item at the specified path.

What changes have been made?

  • An extra option --item-from-folder has been added.
  • It can have one or more than one arguments.
  • It uses string for one argument and array for more than one arguments.
  • It overrides folder option if both are specified.
  • It halts the run if the path specified is invalid.
  • Unit, Library and Integration Tests have been added.

What things are still expected? Since I am still working on it, there will be following changes:

  • Functionality for more than one arguments is being implemented.
  • CLI and Unit tests will be added. P.S. Coverage may not be appropriate right now but will increase surely once remaining CLI and Unit tests are added.

adityaofficial10 avatar Mar 11 '21 20:03 adityaofficial10

Codecov Report

Merging #2654 (dab06d3) into develop (994a0e6) will decrease coverage by 0.08%. The diff coverage is 88.57%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2654      +/-   ##
===========================================
- Coverage    90.85%   90.77%   -0.09%     
===========================================
  Files           21       21              
  Lines         1105     1138      +33     
  Branches       334      347      +13     
===========================================
+ Hits          1004     1033      +29     
- Misses         101      105       +4     
Flag Coverage Δ
cli 80.31% <14.28%> (-2.13%) :arrow_down:
integration 43.23% <74.28%> (+0.97%) :arrow_up:
library 61.33% <85.71%> (+0.79%) :arrow_up:
unit 75.13% <17.14%> (-1.71%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
bin/newman.js 84.90% <0.00%> (-5.30%) :arrow_down:
lib/run/options.js 94.89% <83.33%> (-0.53%) :arrow_down:
lib/run/index.js 93.75% <100.00%> (+0.15%) :arrow_up:
lib/util.js 96.22% <100.00%> (+0.98%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 994a0e6...dab06d3. Read the comment docs.

codecov[bot] avatar Mar 11 '21 20:03 codecov[bot]

@codenirvana Once I add the tests here, this feature can be really useful as it would make Newman more versatile with respect to choice of items. It can actually be considered as an upgrade to folder option. I might merge the new option with folder option if it is possible.

adityaofficial10 avatar Mar 11 '21 20:03 adityaofficial10

@shamasis Actually I thought over that and thought that it would increase running time but now I actually think this is the wrong way... Thanks for your valuable feedback. I'll make the required changes...

adityaofficial10 avatar Mar 15 '21 21:03 adityaofficial10

Double check @codenirvana once. I know there are some concerns about mutating original collection. A cloning may be needed. Or there is an underlying runtime extraction option that can be used for this.

Check the code around extractRunnable function in runtime.

shamasis avatar Mar 15 '21 21:03 shamasis

@shamasis Actually @codenirvana told me to find a different way if I can, in a similar pull request. He's not sure about mutating the collection object.. If I can help there in postman-runtime, kindly let me know..

adityaofficial10 avatar Mar 15 '21 21:03 adityaofficial10

Let's wait on @codenirvana for feedback.

See, mutating collection is a problem only because in programmatic usage and export scenarios the user is not expecting the collection object to unexpectedly change. However, if we clone and mutate it solves the input worries (though adds memory pressure) and for output, it's a matter of choice and documentation (and reviewing the side-effects.)

shamasis avatar Mar 15 '21 22:03 shamasis

@shamasis I understand. Thanks for the review.

adityaofficial10 avatar Mar 15 '21 22:03 adityaofficial10

@shamasis I've found a way out here. We can actually take some code from extractRunnableItems and use it here. It is basically a recursive method to reach any folder depth, if the folder exists. I'll move ahead with this.

adityaofficial10 avatar Mar 20 '21 11:03 adityaofficial10

@codenirvana @shamasis Kindly guide me regarding how can I make both folder and this path to a request option work together.

adityaofficial10 avatar Apr 04 '21 10:04 adityaofficial10

@adityaofficial10 You just have to find the specified request's item.id and use the lookupStrategy=idOrName but here the challenge is, what's the best way to take this (path leading to a request) input?

Honestly, I don't feel we need to introduce this complex CLI input at this moment because one can execute a single request using --folder also, provided the request name is unique in the request (otherwise it choose the first matching request).

And to overcome this limitation, you can pass the request UUID... which is very easy to get with Postman v8's info panel:

Screenshot 2021-04-04 at 5 08 27 PM

codenirvana avatar Apr 04 '21 11:04 codenirvana

@codenirvana Thanks for the help. What I feel is passing a path like ' parent/child ' would work and it's not very complex too as it can be interpreted by the end users...

adityaofficial10 avatar Apr 04 '21 11:04 adityaofficial10

@codenirvana I've found out a way. For qualified path requests, we can just fetch the UUID and pass it to the entrypoint just like we do with folders. This way both of them will work together. I feel this feature can be really great.. Kindly allow me to go ahead..

adityaofficial10 avatar Apr 09 '21 10:04 adityaofficial10

@adityaofficial10 are you still working on this PR?

gfernandes410 avatar Mar 15 '22 01:03 gfernandes410