Package testing using 'describe' like syntax

Hi All, after a long time being a meteor user, I’ve decided it’s time to give something back, so I created a package for testing meteor packages using describe, context, it blocks with Tinytest underneath.

… long story short: smithy:describe

I’ve struggled with tests for a long time, but lately I’ve been moving towards a “packages only” app, and writing tests using the great Tinytest package created by MDG. Meteor itself is tested with it, so I assumed it is the safest bet.

While I was able to structure my tests using tinytest only, I missed how I was able to define my test suite using before, after, beforeEach and afterEach calls and after seeing a package that was trying address this same problem (peterellisjones:describe), I decided to give it a try.

So I released the package named: smithy:describe. It’s the very first version, and it only wraps Tinytest.add, although it may not be so hard to add Tinytest.addAsync support following peterellisjones:describe code. I had to implement before, after, beforeEach, afterEach and it so they all add a new test, this is what makes the whole suite run in the expected order after a change (and not just the it part as I experienced on early commits).

I hope to hear some comments, suggestions and feedback and what I hope the most, is that this is helpful for someone else.

Thanks to all the community and MDG.

Nice! You should also check out the Meteor Guide and feel free to weigh in. Check the issues as well for some testing discussion.

1 Like

@rdickert thanks for your comment, I’ll now keep an eye on the Meteor Guide as well, hopefully we all end up with a final, highly recommended way of testing.

why not just use Munit? :smiley: https://github.com/practicalmeteor/meteor-munit

1 Like

well, I thought munit was being replaced by practicalmeteor:mocha, which is a great package btw, and I actually tried to use that one instead, but I had some problem with async hooks and with it’s html reporter, what I’m trying to do know is share mocha’s syntax, but use tinytest’s reporter. I’ve recently included sinon and chai on smithy:describe for that purpuse.

You are right, OK so we dont need that group async yet.
Will use your package while Velocity package unit tests are not working.
Jasmine style expect would be nice too :smiley: But chai seems similar and would have to be enough in the meantime.
Good luck.

I’ve updated this package and released it as version 1.0.0, you can take a look at it at smithy:describe and you’ll find a much more detailed Readme as well.

To summarise:

  • I’ve added support for Asynchronous tests through the use of test.addAsync behind the scenes.
  • I’ve added sinon and chai support, along with chai’s expect assertions.
  • I’ve implemented a couple of helpers particularly useful for asynchronous tests.
    • catchable to wrap async blocks into a try/catch that calls done(e) on any exception.
    • promisify to create promises out of functions with a callback similar to the one needed for Meteor.call.

I have 2 projects on which I was using mike:mocha, and the migration was pretty straight forward, I pretty much just moved my files and tests into packages, replaced inner describe calls with context (help needed to fix that :smile: ) and tests ran, much much faster, reliable errors (no more timeouts) and quite frankly Tinytest reporter turned out to be quite good! We can select a subset of tests and only those will re-run on changes, and there’s also a debug button for each tests which I haven’t yet been able to try out.

Again, I just hope this package can be useful to the community.

@rdickert, @shock, @arunoda (since you mention it could be useful for flow-router tests)

2 Likes

Nice.

We would love to use this in our tests.