Code Monkey home page Code Monkey logo

Comments (7)

colinskow avatar colinskow commented on August 17, 2024

@tohagan Thank you very much for starting the discussion. I understand that many consider dependencies as an anti-pattern for unit testing. In SuperLogin most of the functionality is dependent on other functionality. For example logging in a user is dependent on creating a user. In order to test log out functionality, it is necessary to log in first.

Rather than wipe the database, create a new user, and initiate a session inside each test I chose to simply make them dependent on each other. From my point of view, this makes the code DRYer and easier to maintain. The tests run faster. Running each test sequentially (using previous.then(...)) ensures there are no database write conflicts.

My debugging workflow is to always handle the first failure until everything passes. If you have any concrete suggestions on how to improve I am open to a pull request.

from superlogin.

tohagan avatar tohagan commented on August 17, 2024

I'm sorry this sounded rather negative of me ... I'm really liking superlogin and your unit tests are very good.

What I eventually did was just convert the leading and trailing it() tests into before() and after() methods that setup and tear down the database. For performance I'm not using beforeEach()/afterEach(). This keeps your DRY pattern and ensures that we can run tests independently. You can still use previous.then() as before. When a unit test is failing I just make it() into it.only(function() ... )

Sometimes I make the db tear down be the 1st step in before() ... as this leaves the updated database at the end of the tests so I can inspect it when a test fails.

I've also merged changes from some forked projects. One in particular has fixed a bunch of issues I had getting your test suite working (my localhost CouchDb is not Admin Party and this broke stuff).

from superlogin.

tohagan avatar tohagan commented on August 17, 2024

Here's the patch that fixed the unit tests (not my code)

View:
ybian@24959f5

Patch:
https://github.com/ybian/superlogin/commit/24959f52db0774ce236775cb8b245889189832e6.patch

from superlogin.

tohagan avatar tohagan commented on August 17, 2024

Another observation is that you often add this at the end of a test ...

 .then(function() { done(); }).catch(function(err) { done(err); }) 

But in Mocha you don't need to since you can just return a promise and mocha will do this for you.
You don't even need to pass the done arg. Same for Jasmine if you use a plugin.

See "Working with Promises" under https://mochajs.org/

from superlogin.

colinskow avatar colinskow commented on August 17, 2024

@tohagan thank you very much for all the feedback! I am actually relatively new to the Javascript and testing scene and this is my first major project.

Within the next couple weeks I will make some time for the next release of SuperLogin and will take all this into consideration to clean up the test code.

from superlogin.

tohagan avatar tohagan commented on August 17, 2024

Sent you a PR that resolves this issue.

from superlogin.

colinskow avatar colinskow commented on August 17, 2024

Thank you for all you help @tohagan !
I am going to close this for now. If you have further feedback on how to eliminate test interdependency feel free to re-open. But since the setup and teardown takes time my preference is to leave it as is.

from superlogin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.