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

feat: add support to skip request execution from script. #942

Closed
wants to merge 1 commit into from

Conversation

vedkribhu
Copy link
Contributor

@vedkribhu vedkribhu commented Aug 25, 2023

pm.request.stopExecution halts the execution of current request. No line after this will be executed and if invoked from a pre-request script, the request will not be sent.

@vedkribhu vedkribhu force-pushed the feat/skip-request branch 3 times, most recently from 38e4243 to 4c4c586 Compare September 1, 2023 05:04
@vedkribhu vedkribhu force-pushed the feat/skip-request branch 3 times, most recently from 2da5532 to 323de69 Compare September 12, 2023 04:42
@vedkribhu vedkribhu changed the title [PoC][WIP] Add pm.skipRequest capability feat: add pm.request.stopExecution support Sep 12, 2023
@@ -129,6 +129,20 @@ module.exports = function (exit) {
c.type.typeName.escapedText = `import("postman-collection").${currentType}`;
}
}

// For properties referencing sdk and some more properties, eg. request: Request|IRequest
if (c.type && c.type.types && c.type.types.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will happen if there is c.types.types.types. Shouldn't this be recursive?

return;
}

bridge.dispatch(event, ...args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What're your thoughts on overriding the dispatch method itself? Would solve the problem where consumers can accidentally call .dispatch directly on the bridge.

const originalDispatch = bridge.dispatch;

bridge.dispatch = function (execution, ...args) {
  if (!isExecution(execution)) {
    throw new Error('must be called with execution');
  }

  if (execution.shouldSkipExecution) {
    return;
  }

  originalDispatch.call(bridge, ...args);
};

@vedkribhu vedkribhu force-pushed the feat/skip-request branch 3 times, most recently from 3424bd3 to 6bf59fd Compare October 10, 2023 12:01
@vedkribhu vedkribhu changed the title feat: add pm.request.stopExecution support feat: add support to skip request execution from script. Oct 10, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2023

Codecov Report

Merging #942 (bf0e253) into develop (5e890c2) will increase coverage by 0.14%.
The diff coverage is 100.00%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

@@             Coverage Diff             @@
##           develop     #942      +/-   ##
===========================================
+ Coverage    60.64%   60.78%   +0.14%     
===========================================
  Files           12       12              
  Lines          559      561       +2     
  Branches       135      135              
===========================================
+ Hits           339      341       +2     
  Misses         220      220              
Flag Coverage Δ
unit 60.78% <100.00%> (+0.14%) ⬆️

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

Files Coverage Δ
lib/sandbox/execution.js 91.66% <100.00%> (+0.23%) ⬆️
lib/sandbox/pmapi.js 66.12% <100.00%> (+0.55%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

// because this event should be fired even if shouldSkipExecution is true as this event is
// used to complete the execution in the sandbox. All other events are fired only if
// shouldSkipExecution is false.
(dnd !== true) && bridge.dispatch({ shouldSkipExecution: false },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're leaking the implementation where execution can contain shouldSkipExecution.

lib/sandbox/pmapi.js Show resolved Hide resolved
declare interface Execution {
/**
* Halts the execution of current request. No line after this will be executed and
* if invoked from a pre-request script, the request will not be sent.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to be more clear for the user. Something like, no scripts associated with the current request will be executed after this and if invoked from a pre-request script, the request will not be sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No script seems more confusing as even part of current script after this won't be executed is skipRequest invoked.

declare interface Execution {
/**
* Halts the execution of current request. No line after this will be executed and
* if invoked from a pre-request script, the request will not be sent.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is prerequest.d.ts file, so you can write the doc assuming "if executed from pre-request script" to be true.

Suggested change
* if invoked from a pre-request script, the request will not be sent.
* the request will not be sent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not separated like that only some part of jsdocs around response are omitted in case of pre-request script

@vedkribhu vedkribhu force-pushed the feat/skip-request branch 3 times, most recently from 0c2c00e to abcb20c Compare October 16, 2023 04:47
@vedkribhu
Copy link
Contributor Author

Closing as we are changing the approach to: #964

@vedkribhu vedkribhu closed this Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants