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

Passing custom parameters to Reporters via JS API, logic from bin script to CoffeeScript #154

Merged
merged 10 commits into from Mar 2, 2015

Conversation

kuba-kubula
Copy link
Member

Because clone cannot clone process.stdout, custom configuration is passed to Dredd class as a second argument

usedFileReportersLength = usedFileReportersLength - 1
if process.env['DREDD_REST_TOKEN'] == undefined or process.env['DREDD_REST_SUITE'] == undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought this part was supposed to be moved and handled in apiary-reporter class

Copy link
Contributor

Choose a reason for hiding this comment

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

And tested there :)

@netmilk
Copy link
Contributor

netmilk commented Feb 23, 2015

I'm sorry, but:

  • I can't find out any clear purpose of this pull request. It's not explained anywhere and it should be evident.
  • I assume it's a combination of:
    1. refactoring of layer handling CLI
    2. extension of Dredd class JS API to support custom configuration data e.g. for reporters

My 0,02$:

  • Please never refactor and introduce new functionality in one PR
  • It's fine that junk form bin/dredd was refactored and sliced into separate, more readable, JS testable layer under DreddCommand class
  • It's not fine that test/unit/command-test.coffee does not test functionality in DreddCommand, it's only a copy of CLI integration test which is end-to-end testing whole Dredd functionality through CLI interface. Unit tests for DreddCommand should test functionality and units in DreddComand class, such is:
    • Handling expanded globs from shell and filling option['path']
    • Showing help
    • Showing version
    • Error handling on missing arguments for blueprint and server
    • Running Dredd
    • Error handling for Dredd#run
  • It's** not** fine extending surface of DreddCommand class interface only for purpose of testing, it should be through mocking output from process.cwd etc..

@kuba-kubula
Copy link
Member Author

@netmilk Understood most of the problems about "why is there console, why is there the config.options.custom.env.

Unfortunately, you can't simply mock process or even process.stdout. Those two can't be even cloned. If you try to mock these two, you are facing problems deep in your dependencies. Really.
There are some articles about it, programers suggest to actually pass console or stdout into the script, and work on top of that. That is the reason I am passing stdout or console separately.
http://yahooeng.tumblr.com/post/75054690857/code-coverage-for-executable-node-js-scripts

Other option would be to use config.custom instead of taking it from the really deep config.options.custom.

Why I chose custom.env? Because there are other possible things you actually want to wrap. One is env, the other one would be a stdout, then maybe anything else like process.exit function? The list gets longer really soon.

@netmilk
Copy link
Contributor

netmilk commented Feb 24, 2015

Ok, thanks for the explanation. In my opinion it's not needed at all, because if you want to test behavior of DreddCommand class, you can spy on console.log and use proxyquire with stubs and spies for loading dredd-command module. Get rid with it please and please don't be afraid to write proper unit tests. ;p

@@ -16,9 +16,6 @@ packageConfig = require './../package.json'
logger = require './logger'


String::startsWith = (str) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@netmilk netmilk changed the title Command interface has tests Passing custom parameters to Reporters via JS API, logic from bin script to CoffeeScript Feb 26, 2015
@kuba-kubula kuba-kubula force-pushed the kubula/command_as_src branch 2 times, most recently from a33bf5a to cc8e90c Compare February 27, 2015 14:21
kuba-kubula added a commit that referenced this pull request Mar 2, 2015
Passing custom parameters to Reporters via JS API, logic from bin script to CoffeeScript
@kuba-kubula kuba-kubula merged commit e790f50 into master Mar 2, 2015
@kuba-kubula kuba-kubula deleted the kubula/command_as_src branch March 2, 2015 12:45
logger.warn "Apiary reporter environment variable APIARY_API_KEY or APIARY_API_NAME not defined."
@configuration.apiSuite ?= 'public'

_get: (customProperty, envProperty, defaultVal) ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Get what? I prefer to name methods/functions based on what they are doing.

artem-zakharchenko pushed a commit that referenced this pull request Oct 9, 2019
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.

None yet

2 participants