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: enable major features of the after-response script #7411

Merged
merged 17 commits into from
May 23, 2024

Conversation

ihexxa
Copy link
Contributor

@ihexxa ihexxa commented May 15, 2024

Ref: INS-3699

Changes

This is the feature branch of the post-request script which contains following changes:

questions

  • what other paths to support? running pre/after scripts in tests, SSE, websockets, gql introspection query
  • how to better handle a selected base env, besides discarding changes, or throwing errors?

@ihexxa ihexxa self-assigned this May 15, 2024
@ihexxa ihexxa force-pushed the feature-post-request-script branch from 6743837 to 86f1a26 Compare May 15, 2024 06:30
@ihexxa ihexxa requested a review from a team May 15, 2024 06:59
@ihexxa ihexxa force-pushed the feature-post-request-script branch 2 times, most recently from 6e12103 to f7e30f0 Compare May 22, 2024 06:52
@ihexxa ihexxa changed the title feat: enable major features of the post script feat: enable major features of the after-response script May 22, 2024
ihexxa and others added 14 commits May 22, 2024 11:13
…#7329)

* feat: integrate post-request script to the engine

* refactor: some minor improvements

* fix: lint error

* chore: clean up typings

* refactor: separate transforming into sync and async parts

* use named args

* fix: renaming pre-req vars, functions and 2 minor fixes

* fix: the error message is updated

* feat: add snippets for post-request scripting (#7395)

* feat: enable extended assertion chains on `insomnia.response` (#7396)

* feat: add snippets for post-request scripting

* feat(sdk): support response.to.have assertion for verifying response

* chore: fix lint error

---------

Co-authored-by: jackkav <jackkav@gmail.com>
…NS-3786 (#7331)

* test: add some tests for post-req script and script engine

* fix: incorrect script type
* feat: support importing post-req script from Postman

* fix: introduce post-req script property for merged changes

* test: add a test case for importing scripts

* fix: add missing fixture

* chore: remove row after merging
@jackkav jackkav force-pushed the feature-post-request-script branch from 0b6803a to 8c76934 Compare May 22, 2024 09:15
jackkav
jackkav previously approved these changes May 22, 2024
@jackkav jackkav enabled auto-merge (squash) May 22, 2024 10:09
filfreire
filfreire previously approved these changes May 22, 2024
@jackkav jackkav disabled auto-merge May 22, 2024 12:47
@jackkav
Copy link
Contributor

jackkav commented May 22, 2024

Looks like this base env logic will have to change. Since throwing the error will break most of the tests. What could be added to the docs? I still feel like baseEnv should not be a concept that scripts should be aware of.

@jackkav jackkav requested review from jackkav and filfreire May 22, 2024 13:03
// when base environment is activated, `mutatedContext.environment` points to it
const isActiveEnvironmentBase = mutatedContext.environment?._id === baseEnvironment._id;
const hasEnvironmentAndIsNotBase = mutatedContext.environment && !isActiveEnvironmentBase;
if (hasEnvironmentAndIsNotBase) {
Copy link
Contributor

Choose a reason for hiding this comment

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

apparently we don't need to persist changes outside of the scripts, see INS-3852

Copy link
Contributor Author

@ihexxa ihexxa May 23, 2024

Choose a reason for hiding this comment

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

Currently the baseEnvironment handler is mainly for providing a way to manipulate base environment then composition of environments will work, anyway let's discuss.

@ihexxa ihexxa dismissed stale reviews from filfreire and jackkav via 5621418 May 23, 2024 06:41
@ihexxa ihexxa merged commit 46b6ea8 into develop May 23, 2024
7 checks passed
@ihexxa ihexxa deleted the feature-post-request-script branch May 23, 2024 07:25
stefancruz pushed a commit to stefancruz/insomnia that referenced this pull request Jun 30, 2024
* feat: update data model and request-pane to support post-req-script

* fix: unit test failed

* feat: integrate post-request script to the engine - INS-3785,INS-3786 (Kong#7329)

* feat: integrate post-request script to the engine

* refactor: some minor improvements

* fix: lint error

* chore: clean up typings

* refactor: separate transforming into sync and async parts

* use named args

* fix: renaming pre-req vars, functions and 2 minor fixes

* fix: the error message is updated

* feat: add snippets for post-request scripting (Kong#7395)

* feat: enable extended assertion chains on `insomnia.response` (Kong#7396)

* feat: add snippets for post-request scripting

* feat(sdk): support response.to.have assertion for verifying response

* chore: fix lint error

---------

Co-authored-by: jackkav <jackkav@gmail.com>

* test: add tests for post-request scripts and post-request scripts - INS-3786 (Kong#7331)

* test: add some tests for post-req script and script engine

* fix: incorrect script type

* chore: refresh package-lock after merging

* chore: clean up package-lock.json

* fix: failed tests after rebasing

* feat: support importing post-req script from Postman (Kong#7423)

* feat: support importing post-req script from Postman

* fix: introduce post-req script property for merged changes

* test: add a test case for importing scripts

* fix: add missing fixture

* chore: remove row after merging

* chore: rename to after-response-script

* fix test

* refresh lock

* update snapshot

* extract pre request logic to function

* refresh lock again

* throw on base env

* fix: revert the logic which rejects the case of unselected environment

---------

Co-authored-by: jackkav <jackkav@gmail.com>
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.

4 participants