ItzBlitz98/torrentflix

Add some tests

Opened this issue · 9 comments

I wanted to add some tests to this repo but I think this need a refactoring of the app (maibe I'm wrong and I want to discuss). I started with Tape but in test files, we can't access to vars or functions because of the architecture of the files main.js and cli.js. All vars and function are wrapped by function which isolate all vars inside.

I'll be happy to discuss about it.

Please forgive my ignorance but what tests would we run and how would they benefit Torrentflix ?

During my last PR, I change lot of lines of code and generate error because of this change. Actually, after each change on code, we need to test manually each feature which growing.
So I ask if we could add some writing test which we launch after each development. With this we avoid regression of code with launching one command (example : tape tests/*.js).

This tests, are files where we put some code to test functions. For example :

  • I want to be alerted when my scrapers script not working anymore (website which change html)
  • I want to be alerted when a function not work (torrentflix -s title, torrentflix -o title...)

This test can be launch manually but automatically with travis (at each push for example)

I agree we need testing to start placing/accepting PRs with more confidence. I do not have much experience with testing in JS specifically, but once the initial architecture is set (testing framework chosen, some base tests as example) I could also contribute to this.

I'm not sure how we could structure the two files @ahivert mentions, but I also believe they need some refactoring and further extraction into new modules. If we can do that and at the same time prepare the ground to make that code testable, it would be a great first step.

I don't have much experience in testing but i'm not opposed to this, I think its a great idea and i might learn something in the process.

i organizied the 'search for torrent' function into a separated project just for fun and trying nodejs. I think it's more convenient to write unit test if a module does only a very well defined and limited functionality.
I'll try jasminejs as i read its one of the most renowned nodejs testing framework and can work with es6 classes and babeljs.

I don't think this is a good idea to add a layer on top of javascript in this little size app. We need to keep the code readable.
We add a layer when we need to simplify the writing to save time in a big project (learn layer take time), again, maybe I'm wrong ? 😊
For the testing framework, there is "Tape" too, which seem to be very good, easy too learn and use. Very good for an open source project like this.

My personal preference is to write reusable code.. It's your project guys :)

I'm willing to make a PR for this. Some of the endoints (Kickass) is not usable.

Thanks for the PR, I'm going to work on updating scrapers they haven't seen much attention lately.