Comments (7)
@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.
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.
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.
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.
@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.
Sent you a PR that resolves this issue.
from superlogin.
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)
- How can I remove confirmPassword requirement?
- Validation failed HOT 8
- Validation failed HOT 1
- Calling /auth/session with authorization header is returning unauthorized HOT 1
- Use template-literal instead of EJS
- user-db-added event doesn't get emitted HOT 1
- New release? HOT 13
- Validation Failed HOT 1
- Register vaildation failed HOT 18
- Mandatory Migration from Cloudant to BlueMix not compatible with Superlogin HOT 1
- Superlogin with CouchDB crypto.pbkdf2 "digest" argument required HOT 1
- how to add profile data with registration?
- removeUser not working
- Live demo isn't working HOT 1
- Forgot Password function
- TypeError: Cannot read property 'valid' of undefined at Function.PouchDB.parseAdapter
- Howto: use superlogin with current nodejs HOT 6
- Set a Doc create limit per user
- super login spaming console with errors
- Graphql
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superlogin.