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

Refactor of the cmd.js - Still a WIP, but looking for comments #73

Closed
wants to merge 7 commits into from

Conversation

lholmquist
Copy link
Contributor

@lholmquist lholmquist commented Jul 25, 2019

This PR is a work in progress to discuss the refactor discussed in #71 . The goal is to refactor the cmd.js file to not be cluttered with the actual logic of what a command does, which should help in being able to test it easier.

I've tried to keep the commits logically separated.

In the first commit, I've just added comments on what is actually happening. This was more for me to understand what is going on where.

The second commit just moves the logic for the --list-subsystem flag up a little in the code. not really a functional change, but more for style.

Commits 3 and 4 are related to moving the load and loadPatch functions from the cmd.js file to the utils module. Moving them into the utils module, and exporting them, i was able to write tests for them as standalone functions. It also adds 2 new dev dependecies, proxyquire and nock.

The next 2 commits are related to moving the logic for the --validate-metadata and --tap commands out, and into the utils module. Moving the logic out into its own function, i have to pass in a Validator object, which will make it easier to mock and test

I still need to write tests for these 2 functions, but I think now it will be easier to do so.

I just wanted to start this PR to have a discussion if what i'm doing and suggesting makes sense.

squash: add more comments

squash: add more comments
* This moves the --list-subsystems command up before the creation of the Validator, since it doesn't need that to happen
* This moves the function that loads the commit, from either a 'git show' or from a url, into the util module
* This is for cleaning up the main cmd.js file which should only really have logic related to the commands
* This also adds the proxyquire and nock modules as dev dependencies
* move validate-metadata logic to utils for easier testing
* This moves the tap logic out of cmd.js and into a separate function in utils
@codecov
Copy link

codecov bot commented Jul 26, 2019

Codecov Report

Merging #73 into master will increase coverage by 2.9%.
The diff coverage is 45.33%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #73     +/-   ##
=========================================
+ Coverage   57.14%   60.04%   +2.9%     
=========================================
  Files          18       18             
  Lines         448      458     +10     
=========================================
+ Hits          256      275     +19     
+ Misses        192      183      -9
Impacted Files Coverage Δ
bin/cmd.js 38.88% <25%> (+9.67%) ⬆️
lib/utils.js 52.12% <49.2%> (-5.94%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 479fe81...28f321e. Read the comment docs.

* This adds a callback function to both the validate-metadata and tap functions.
* it also moves the process.exitCode assignment back into the cmd.js instead of the in the actual util module function
* This will make testing those indiviual functions eaiser.
* Another added benefit is if at some point a programmable API was to be created, we just want to return a code instead of assigning it to the process.exitCode
@lholmquist
Copy link
Contributor Author

This refactor and PR are getting a little big. I think i might be able to break it up into smaller chunks. I'm going to close this and re-open another PR

@lholmquist lholmquist closed this Aug 6, 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.

1 participant