Closed mizzao closed 10 years ago
@matb33 Actually, upon closer inspection it looks like the tests are failing on reload because the find
hooks are not properly cleaning up the referenced userId
. I'll let you take a look at this first before I do more digging. Just run the tests and hit reload on the page to see what happens. The tests are all in insert/update/remove.
@mizzao First, big thanks for working on this. Apologies for not responding any sooner!
Second, I looked at your new tests (nice work) and noticed your TODO concerning the tests getting duplicated on the server on client reload. I did a simple if
statement to guard against that, and it appears to be working now.
Concerning how Tinytest doesn't like us adding tests once the InsecureLogin.ready
fires, I suspect it's because Tinytest's test runner expects all tests to be defined on the initial tick of the event loop. That is to say, if we define any tests asynchronously, the test runner won't find them and doesn't have any plumbing to support defining tests later on.
EDIT: I'll let you close this issue if you're satisfied with your work and my if
statement
Hi @matb33, looks good. I did notice some tests failed right when I first started Meteor, but on subsequent tests (either manual reload or hot code reload) everything worked, so it's probably not worth pursuing that. And it's not because of the other error I conjectured, so that's good.
I think the adding tests problem is a little more nuanced than that. For example in that same file we add the server tests in the publish
function and it works just fine. Maybe it's what you said, but only on the client side (server supports adding tests whenever.) I would say it's probably a bug with Tinytest but something we shall just work around for now because it's not the future of Meteor testing anyway.
I've been using InsecureLogin
for tests in some of my other packages as well. Really neat code. Would be awesome if it supported both logging in and logging out during tests instead of just once at the beginning - I might be adding that for something else soon, but loathe to spend so much time investing in a testing methodology that is not really future proof.
I just spent some time fixing the
find
/findOne
userId tests (5de03e1b49734a23c613c5e97690114423009a59), and wanted to document some weird stuff in case someone wanted to look into it.First, the original structure of the tests had some logical problems. The
test.notEqual
assertion was run inside the hook to check for theuserId
. This assumed that the hook was actually being run in the first place. If it wasn't, the test would pass tautologically. I guess this is okay if something else checks for the hook, but it seemed to be safer to not assume anything for this test if we didn't have to.The tests are also created in the
publish
function to get around the asynchrony issues that @matb33 was having before. However, this results in some complaining from Tinytest when the publish function is hit again. I'm interested in seeing any creative ways to fix this problem so the test works across reloads (see below.)Otherwise, I observed two weird issues:
Tinytest.add
/Tinytest.addAsync
doesn't seem to work insideInsecureLogin.ready()
for some reason. (Test just don't appear.) See tests/find_findone_userid.js. I moved them out for now, and on my computer the login happens quickly enough for the tests to pass. However, it isn't logically correct.Finally, do we need to add tests for
userId
being available infind
/findOne
calls from server side methods? This is way less complicated than thepublish
case, as theMeteor.userId()
is typically already available. But just wondering...P.S. Loving the new two-space soft tabs that you are using. Makes it much easier to contribute!