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

Refactored validateJob method complexity #56

Merged
merged 26 commits into from Dec 9, 2020

Conversation

naz
Copy link
Member

@naz naz commented Nov 25, 2020

The main aim of this refactor is to simplify extremely complex validateJob method and make it easier to reason about job object construction/shape. Initially proposed in this comment.

The plan is to:

  • Extract as methods used by validateJob function into separate module
  • Divide validateJob method into two separate parts - (1) validation and (2) job object construction
  • Extract buildJob into separate module
  • Abstract away validateJob dependance on internal state of Bree instance - this.config.jobs
  • Extract validateJob into separate module

Above should not change module's API or change it's behavior.

@naz
Copy link
Member Author

naz commented Nov 25, 2020

No clue why tests are failing 🤔 they pass locally, but that just might be my modified configuration.

@codecov-io
Copy link

codecov-io commented Nov 25, 2020

Codecov Report

Merging #56 (baedefc) into master (ef8a363) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #56   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         4    +3     
  Lines          297       368   +71     
=========================================
+ Hits           297       368   +71     
Impacted Files Coverage Δ
src/index.js 100.00% <100.00%> (ø)
src/job-builder.js 100.00% <100.00%> (ø)
src/job-utils.js 100.00% <100.00%> (ø)
src/job-validator.js 100.00% <100.00%> (ø)

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 ef8a363...baedefc. Read the comment docs.

@naz naz force-pushed the validate-job-method-complexity-refactor branch from a814868 to bbe1332 Compare November 25, 2020 23:19
@naz naz force-pushed the validate-job-method-complexity-refactor branch from 931d2c8 to 7bbb690 Compare November 26, 2020 01:32
@naz
Copy link
Member Author

naz commented Nov 26, 2020

@niftylettuce I've finished the refactor I had in mind. valiedaJob function is now broken down into smaller bites and there are two separate stages: job validation and job construction. Would love to know what you think about this direction! Not really sure why tests are failing on CI as they pass just fine locally (or is it the code coverage issue?)

Was wondering what's your opinion on use of JSDocs? I think it would help to somewhat document what each utility does and even assist with some type checking in the IDE.

@naz
Copy link
Member Author

naz commented Nov 26, 2020

I've added as much coverage as possible but can't find the last piece to cover last 3% Currently nyc reports:

 job-validator.js |     100 |    97.94 |     100 |     100 | 198               
------------------|---------|----------|---------|---------|-------------------

And the 198th line is being hit from multiple tests and I'm pretty sure that didn't introduce many new pathways 🤔

@naz naz marked this pull request as ready for review November 30, 2020 23:30
@naz naz force-pushed the validate-job-method-complexity-refactor branch from 58680ca to 4cec467 Compare December 1, 2020 00:06
@naz
Copy link
Member Author

naz commented Dec 1, 2020

@niftylettuce this PR is ready to be reviewed. The test are failing for the same flaky reason as they do in master. The coverage is 100% on Node v10. Let me know what you think about the changes, happy to break them down a little if that's to much to review (tried to do incremental changes with each commit instead of one bulk of changes)

@shadowgate15
Copy link
Member

@naz When I pulled into my local environment all of the tests worked, however this is what I got back on the coverage:

------------------|---------|----------|---------|---------|----------------------------------------------------------------------------
File              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------|---------|----------|---------|---------|----------------------------------------------------------------------------
All files         |   90.73 |    86.93 |   93.33 |   91.03 |
 index.js         |   99.56 |      100 |   96.67 |   99.51 | 342
 job-builder.js   |     100 |      100 |     100 |     100 |
 job-utils.js     |     100 |      100 |     100 |     100 |
 job-validator.js |   61.86 |    57.89 |   77.78 |   64.84 | 14,26-33,52-61,68-72,74,99,133-179,210,220,227,234,238-241,256,267,274,282
------------------|---------|----------|---------|---------|----------------------------------------------------------------------------

@naz
Copy link
Member Author

naz commented Dec 2, 2020

@shadowgate15 I think the problem with coverage is the same one as in current master - it works for Node v10 but then fails for Node v12. I have not introduced any new pathways, so the coverage should stays the same.

@shadowgate15
Copy link
Member

Wow! I just re-ran the tests and got a completely different coverage... looks like I really need to sit down with the tests and make them more stable... Well, ignore my earlier comment. I do like this though and it looks really good.

@naz
Copy link
Member Author

naz commented Dec 2, 2020

@shadowgate15 what's your opinion on adding jsdocs wherever possible? I found it helpful to add inline documentation of some sort and have loose type checking available within IDE.

@shadowgate15
Copy link
Member

I don't really have an opinion on it. Both @niftylettuce and I use vim so type checking doesn't do a whole lot for us. I think that if you want to add it in there and maintain it, then go for it.

@naz
Copy link
Member Author

naz commented Dec 9, 2020

The tests that are failing are only limited to Node v12 and are the same as master's. Failing tests will be resolved through #60 eventually.

@naz naz merged commit 679da94 into breejs:master Dec 9, 2020
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

3 participants