stargazed icon indicating copy to clipboard operation
stargazed copied to clipboard

add unit tests

Open abhijithvijayan opened this issue 4 years ago • 32 comments

Checklist

  • [x] Initial barebone
  • [ ] Add unit tests for the commands offered by the cli

abhijithvijayan avatar Oct 12 '19 01:10 abhijithvijayan

Could I get assigned to this?

JacobMGEvans avatar Oct 12 '19 04:10 JacobMGEvans

@JacobMGEvans How is that PR coming ?

abhijithvijayan avatar Oct 12 '19 14:10 abhijithvijayan

I was able to get Jest working with some Babel, the tests themselves I am still working on since I have two other projects I am working on right now too. :)

On Sat, Oct 12, 2019 at 9:32 AM Abhijith Vijayan [email protected] wrote:

@JacobMGEvans https://github.com/JacobMGEvans How is that PR coming ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/abhijithvijayan/stargazed/issues/19?email_source=notifications&email_token=AGP4EOHYV5623PVVYNHTRE3QOHNYTA5CNFSM4JAARLQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCAWCI#issuecomment-541330185, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGP4EODXHIDWMNRGI6OHQE3QOHNYTANCNFSM4JAARLQQ .

JacobMGEvans avatar Oct 12 '19 22:10 JacobMGEvans

I did add exports to a lot of the functions in the file, but those can easily be removed when determined which ones are not needed for isolated testing.

I was also trying to get a feel for the codebase/the flow of data and how to approach testing it.

JacobMGEvans avatar Oct 13 '19 01:10 JacobMGEvans

@JacobMGEvans I think a lot of code refactoring is needed here and there in the source code. This was all written very soon so didn't get time to refactor.

abhijithvijayan avatar Oct 13 '19 01:10 abhijithvijayan

Well, tests will definitely help when you go to refactor because you can just run watch on them and make sure the tests don't break :)

I try to write tests so the code implementation doesn't matter i.e. refactors dont break them... the only thing that matters is the input => output and behaviors remain the same/consistent.

JacobMGEvans avatar Oct 13 '19 02:10 JacobMGEvans

@JacobMGEvans You want me to assign this to someone else?

Refactor seems to be quite needed as CLI hit 2700+ weekly downloads. :grinning:

abhijithvijayan avatar Oct 14 '19 13:10 abhijithvijayan

Wow! Congratulations, definitely a good idea to refactor for performance then!

You can assign other people, I probably will still write tests soon regardless. I am just finishing up with another issue from a different OSS and a few from my own side project.

JacobMGEvans avatar Oct 14 '19 13:10 JacobMGEvans

Also I really like your project and how you have communicated, it's been a pleasant experience. So I certainly would like to assist 😄

JacobMGEvans avatar Oct 14 '19 13:10 JacobMGEvans

@JacobMGEvans Thanks a lot for that.

It's not everyday someone helps in such tiny OSS projects. Glad that you are ready to contribute. Appreciate it.

abhijithvijayan avatar Oct 14 '19 13:10 abhijithvijayan

Last night I started focusing on the unit tests, I am having issues importing the functions and statements for some reason... Might need to spend a little more time on the jest configuration, not sure what's the exact problem yet.

JacobMGEvans avatar Oct 15 '19 12:10 JacobMGEvans

@JacobMGEvans Told ya, it's messed up.

abhijithvijayan avatar Oct 15 '19 14:10 abhijithvijayan

lmao, I am certain I can figure it out I just wanted to keep you updated 😆

JacobMGEvans avatar Oct 15 '19 17:10 JacobMGEvans

@abhijithvijayan Alright, I got this mostly figure out it was not configuration issues. The fact you were using a module.exports on an anonymous async function was making is impossible to test... I have some solutions,

  1. firstly I am going to make the test work with the code as-is then make the PR

  2. I am going to refactor it to use ES6 modules import/export which export default should would the same as how you have module.exports with the testing in place we can refactor with confidence it will keep working as expected.

  3. Once the import/export is in place testing specific functions will be far easier and refactoring the code base will be far easier.

  4. Integration and E2E(likely not needed) will be the next endeavor

JacobMGEvans avatar Oct 16 '19 02:10 JacobMGEvans

@JacobMGEvans I am open to any modifications as long as the project works and code quality is improved.

abhijithvijayan avatar Oct 16 '19 02:10 abhijithvijayan

@abhijithvijayan Interesting enough if I try to pass false into the options that are primitives is throws an error, if I pass true it works fine... I might open a bug issue a little bit

JacobMGEvans avatar Oct 16 '19 03:10 JacobMGEvans

Would you be able to give me some mock or actual payloads and responses? I would rather not go through the whole process if you have anything like that leftover from developing it.

JacobMGEvans avatar Oct 16 '19 04:10 JacobMGEvans

@JacobMGEvans I have fixed the export issue and also added a sample mock payload to the test file.

Now you can continue adding tests.

abhijithvijayan avatar Oct 16 '19 18:10 abhijithvijayan

Huh, it was working fine when I tested it locally... I use babel-node though 😬 lol

Glad you got it fixed though Ill check out the changes and continue with testing.

JacobMGEvans avatar Oct 17 '19 02:10 JacobMGEvans

Someone also uncommented out tests that I had TODOs on because they were incomplete and a comment was added that "it doesnt return anything" which is why there was a TODO there to finish the test...

JacobMGEvans avatar Oct 17 '19 02:10 JacobMGEvans

@JacobMGEvans I was trying out the error fixes. Feel free to work on it.

abhijithvijayan avatar Oct 17 '19 02:10 abhijithvijayan

@JacobMGEvans Is babel config and its packages needed to run the tests?

abhijithvijayan avatar Oct 18 '19 03:10 abhijithvijayan

Yes.

On Thu, Oct 17, 2019, 10:37 PM Abhijith Vijayan [email protected] wrote:

@JacobMGEvans https://github.com/JacobMGEvans Is babel config and its packages needed to run the tests?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/abhijithvijayan/stargazed/issues/19?email_source=notifications&email_token=AGP4EODENU2T2DTN6ANWYQTQPEVNZA5CNFSM4JAARLQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBSNA4I#issuecomment-543477873, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGP4EOGKAG4QG7KPBDAMQVLQPEVNZANCNFSM4JAARLQQ .

JacobMGEvans avatar Oct 18 '19 22:10 JacobMGEvans

https://jestjs.io/docs/en/getting-started#using-babel

JacobMGEvans avatar Oct 19 '19 03:10 JacobMGEvans

@JacobMGEvans The tests are almost complete right!

abhijithvijayan avatar Oct 20 '19 16:10 abhijithvijayan

So far it's 50% coverage. Some of the functions and behavior are difficult to test due to how errors are handled and also readme is written locally... So that can overwrite the local repos readme when running parts of the code in tests.

On Sun, Oct 20, 2019, 11:45 AM Abhijith Vijayan [email protected] wrote:

@JacobMGEvans https://github.com/JacobMGEvans The tests are almost complete right!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/abhijithvijayan/stargazed/issues/19?email_source=notifications&email_token=AGP4EOBC5YN2YAFYTZMMISLQPSDJ5A5CNFSM4JAARLQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBYOJAY#issuecomment-544269443, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGP4EOG64OTXULIDQ7FOWU3QPSDJ5ANCNFSM4JAARLQQ .

JacobMGEvans avatar Oct 20 '19 17:10 JacobMGEvans

@JacobMGEvans not really.

CLI creates README.md, and local file is readme.md

If you have tried the cli within the folder, you can see it doesn't affect the original readme.md file

abhijithvijayan avatar Oct 20 '19 17:10 abhijithvijayan

I wasn't asking a question I was stating what happens when you run the function in the Jest test, also it is not cap sensitive, Node just writes to the readme.md, like I said.

JacobMGEvans avatar Oct 20 '19 19:10 JacobMGEvans

I thought since the command Node cli.js -u "USERNAME" creates README.md along with readme.md, it wouldnt be a problem too, while testing.

Maybe renaming current readme.md to just readme might help right!

abhijithvijayan avatar Oct 21 '19 03:10 abhijithvijayan

Perhaps. I haven't been able to get to it for a few days.

On Sun, Oct 20, 2019, 10:59 PM Abhijith Vijayan [email protected] wrote:

I thought since the command Node cli.js -u "USERNAME" creates README.md along with readme.md, it wouldnt be a problem too, while testing.

Maybe renaming current readme.md to just readme might help right!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/abhijithvijayan/stargazed/issues/19?email_source=notifications&email_token=AGP4EOE2YOUL55WMKTMAIHDQPUSJFA5CNFSM4JAARLQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBY7MYQ#issuecomment-544339554, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGP4EOGFRX2XVF3PJ5Y2TZTQPUSJFANCNFSM4JAARLQQ .

JacobMGEvans avatar Oct 21 '19 15:10 JacobMGEvans