Added ES6 feature support to NodeJS Native codegen#196
Merged
shreys7 merged 2 commits intopostmanlabs:developfrom Mar 11, 2020
Merged
Added ES6 feature support to NodeJS Native codegen#196shreys7 merged 2 commits intopostmanlabs:developfrom
shreys7 merged 2 commits intopostmanlabs:developfrom
Conversation
Contributor
Author
|
@umeshp7 @codenirvana @abhijitkane Please review! |
shreys7
requested changes
Mar 9, 2020
Comment on lines
+21
to
+36
| if (options.ES6_enabled) { | ||
| snippet = 'const '; | ||
| } | ||
| else { | ||
| snippet = 'var '; | ||
| } | ||
| snippet += `${nativeModule} = require('${nativeModule}');\n`; | ||
| if (options.followRedirect) { | ||
| snippet = `var ${nativeModule} = require('follow-redirects').${nativeModule};\n`; | ||
| if (options.ES6_enabled) { | ||
| snippet = 'const '; | ||
| } | ||
| else { | ||
| snippet = 'var '; | ||
| } | ||
| snippet += `${nativeModule} = require('follow-redirects').${nativeModule};\n`; | ||
| } |
Member
There was a problem hiding this comment.
Can you refactor this flow, such that we only test for ES6_enabled only once?
Something like below
if (options.ES6_enabled) {
snippet = 'const ';
}
else {
snippet = 'var ';
}
if (options.followRedirect) {
require('follow-redirects).nativeModule;
}
else {
require('nativeModule');
}
| ] | ||
| } | ||
| }), | ||
| nativeModule = (request.url.protocol === 'http' ? 'http' : 'https'), |
Member
There was a problem hiding this comment.
you don't need to take it from request.url.protocol. directly use https
| }); | ||
| }); | ||
|
|
||
| it('should return snippet with ES6 features when ES6_enabled is set to true', function () { |
Member
There was a problem hiding this comment.
Can we also test for other changes, i.e. postData, qs, etc.
Contributor
Author
|
@shreys7 I have updated everything as you said, please have a look. |
shreys7
approved these changes
Mar 11, 2020
This was referenced Oct 3, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
It allows the user to generate the code snippet for NodeJS Native in ES6 format.
This is in response to issue #115 requested by one of the users.
Changes you made
Registered a new parameter ES6_enabled in
options()which allows the user to toggle between whether codegen generates snippet with ES6 features or not.By default ES6_enabled is set to
falseAlso added the newly created option parameter in
structure.test.jsfile to register it as a valid option id.Added unit tests to verify the generated snippets in snippet.test.js
Added a new mocha test suite to verify that the generated snippet is runnable in newman.test.js.
Updated the readme.md file with new option parameter.
Screenshot/ CodeSnippet
Not required
Test Configuration:
Added a unit test to check the snippet generated
Added a new block of mocha test inside the main suite to verify that the snippet produced is runnable.
Follow up
Not required
Thanks for contributing! ❤️