bruno icon indicating copy to clipboard operation
bruno copied to clipboard

feature(postman_tests_scripts): automatic tests and scripts translation from postman import

Open bpoulaindev opened this issue 1 year ago • 7 comments

Description

Regarding issue #1147 Previous postman script import result : image

Translated postman script import result : image

Translations are made using a regex, with a separated typescript function Non-translatable postman code will be still returned as comments

Contribution Checklist:

  • [x] The pull request only addresses one issue or adds one feature.
  • [x] The pull request does not introduce any breaking changes
  • [x] I have added screenshots or gifs to help explain the change if applicable.
  • [x] I have read the contribution guidelines.
  • [x] Create an issue and link to the pull request.

Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.

Publishing to New Package Managers

Please see here for more information.

bpoulaindev avatar Dec 05 '23 16:12 bpoulaindev

This PR is now ready @helloanoop 🎉

bpoulaindev avatar Dec 20 '23 09:12 bpoulaindev

how to test this?

raaaouf avatar Mar 04 '24 14:03 raaaouf

how to test this?

Import a postman collection into Bruno, the collection must have postman commands in scripts and/or tests. By default scripts are inside a comment, when you enable the translation it converts pm.environment.get() to bru.getEnvVar()

bpoulaindev avatar Mar 04 '24 15:03 bpoulaindev

how can i enable this in bruno ? Because when i import collection from Postman i d'ont have this option (Enable postman translation ]

raaaouf avatar Mar 04 '24 15:03 raaaouf

how can i enable this in bruno ? Because when i import collection from Postman i d'ont have this option (Enable postman translation ]

Are you on the right branch ? There should be a checkbox in the import dialog before choosing "Postman collection"

bpoulaindev avatar Mar 04 '24 15:03 bpoulaindev

i downloaded zip file from your branch but don't know how to try it

raaaouf avatar Mar 04 '24 15:03 raaaouf

You have to clone the Bruno repository, switch to the branch feature/postman_tests_scripts, install the dependencies, follow the readme manual and launch the project locally on your machine

bpoulaindev avatar Mar 04 '24 16:03 bpoulaindev

@helloanoop : After this PR was merged, the main branch no longer builds for me. My steps are:

npm i --legacy-peer-deps
npm run build:graphql-docs  && npm run build:bruno-query && npm run build:bruno-common
npm run dev:web

Result:

error - ../../node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[2].oneOf[7].use[1]!../../node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[2].oneOf[7].use[2]!../../node_modules/codemirror/lib/codemirror.css
Error: Cannot find module 'tailwindcss/plugin'
Require stack:
- /Users/woof/SAPDevelop/git/bruno/node_modules/@tailwindcss/forms/src/index.js

mjhcorporate avatar Mar 13 '24 22:03 mjhcorporate

Can you try running npm i @tailwindcss/forms ?

bpoulaindev avatar Mar 13 '24 22:03 bpoulaindev

Yep, that fixes it.

mjhcorporate avatar Mar 13 '24 22:03 mjhcorporate

Related PR: https://github.com/usebruno/bruno/pull/1814/files

mjhcorporate avatar Mar 14 '24 12:03 mjhcorporate

Hello @bpoulaindev, Thanks, it's a great feature !

Could we go one step further, having more replacements, like :

  • pm.test => test
  • pm.response.json() => res.body
  • pm.response.to.have.status => expect(res.status).to.be.equal
  • pm.globals.set => bru.setVar
  • pm.globals.get => bru.getVar

I observed that set commands are not replaced if expression contains a . ? This was not replaced :

//     var response = pm.response.json();
//     pm.environment.set("variable_key", response.key);

could be replaced by :

var response = res.body;
bru.setEnvVar("variable_key", response.key);

BBE-91 avatar Mar 26 '24 08:03 BBE-91

Hi @BBE-91 thanks for the suggestions; I submitted a PR that was merged few das ago improving the translation : #1894 Here's the current status regarding your suggestions :

  • pm.test : ✅
  • pm.response.json() : good idea
  • pm.response.to.have.status() : ✅
  • pm.globals.set/get : not sure we can do this now, as Bruno doesn't support global variables yet, this could be misleading

bpoulaindev avatar Mar 26 '24 09:03 bpoulaindev

Thanks for the PR, I also see this one : #1909

BBE-91 avatar Mar 26 '24 11:03 BBE-91

can pm.collectionVariables get/set be added also? that and @BBE-91 suggestions would increase the coverage of the translation a lot :)

apintocd avatar Mar 27 '24 16:03 apintocd

Thanks for the PR, I also see this one : #1909

This one is interesting it should also be merged. @apintocd this has been merged in the PR i mentioned above

bpoulaindev avatar Mar 27 '24 16:03 bpoulaindev