Skip to content

Added ES6 feature support to NodeJS Native codegen#196

Merged
shreys7 merged 2 commits intopostmanlabs:developfrom
sastava007:ES6-NodeJS-Native
Mar 11, 2020
Merged

Added ES6 feature support to NodeJS Native codegen#196
shreys7 merged 2 commits intopostmanlabs:developfrom
sastava007:ES6-NodeJS-Native

Conversation

@sastava007
Copy link
Contributor

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 false

  • Also added the newly created option parameter in structure.test.js file 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! ❤️

@sastava007
Copy link
Contributor Author

@umeshp7 @codenirvana @abhijitkane Please review!

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`;
}
Copy link
Member

Choose a reason for hiding this comment

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

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'),
Copy link
Member

Choose a reason for hiding this comment

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

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 () {
Copy link
Member

Choose a reason for hiding this comment

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

Can we also test for other changes, i.e. postData, qs, etc.

@sastava007
Copy link
Contributor Author

@shreys7 I have updated everything as you said, please have a look.
🙂

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.

2 participants