Jest – Painless JavaScript Testing
facebook.github.io
facebook.github.io
Congrats guys. :)
Leveraging Jasmine is great too. Glad to see it's not reinventing the wheel!
Here's another interesting part, on dependency injection: http://facebook.github.io/jest/docs/common-js-testing.html#c...
Right now we use jasmine internally, so I was pretty focused on getting it running with that. However, it is (quite intentionally) built such that the 'jasmine' parts are pretty isolated similar to a plug-in; So it should be possible to build plug-ins for other frameworks like Mocha as well at some point.
Jest adds multiple layers on-top:
- A mock library (also called stubs) in order to create fake functions and assert that they are called as you want: http://facebook.github.io/jest/docs/mock-functions.html#cont...
- A way to provide an alternate implementation for dependencies using require(): http://facebook.github.io/jest/docs/common-js-testing.html#c...
- It inspects the shape of your dependencies and return a mocked version of them: http://facebook.github.io/jest/docs/automatic-mocking.html#c...
- Finally, it works in node instead of the browser and uses jsdom to let you test code related to the DOM. (It also runs tests in parallel)
jest is a test runner that includes a few additional things to try to make all aspects of writing and running tests a little easier...such as:
* Searches for tests to find + execute so that you can put tests near the modules they are testing
* Runs tests in parallel processes so that your test runs finish sooner
* Replace's node's built-in require() function with a custom one that acts almost entirely the same -- except (by default) it returns mocked versions of modules (rather than the real things) when your tests run
* Gives you a fake DOM implementation (using jsdom) so that you can test code that depends on DOM APIs on the command line without having to boot up a browser
The code is now a little stale and dated, but it basically just shells out to the bin/jest.js script included with Jest. Turned out no more than a ~30lines:
https://github.com/jeffmo/react/commit/7a72cbba0eb57844f4e22...
On a side note, I got a good chuckle from the "Bobby Tables" XKCD reference[1] in the Jest tutorial[2].
[1]: http://xkcd.com/327/ [2]: http://facebook.github.io/jest/docs/tutorial.html
That way you could use it easily with Mocha (and should, etc).
Yea, I'd really like to add support for other testing frameworks as well.
Right now we use jasmine internally, so I was pretty focused on getting it running with that. However, it is (quite intentionally) built such that the 'jasmine' parts are pretty isolated similar to a plug-in; So it should be possible to build plug-ins for other frameworks as well (like Mocha, QUnit, etc) in the future.
Did you consider building on top of Sinon.JS and only having jest do the require/detect/build-mock part? Your mock API seems very similar.
* No parallelisation, even if test suites are all independent * DOM tests, which cause a lot of GC pauses * (probably) PhantomJS startup and initialisation (not measured)
I've done a simple optimization where my tests get split in the middle and run in two separate terminals (during development, continuous testing), but it's kinda iffy.
http://facebook.github.io/jest/docs/tutorial-coffeescript.ht...
jstransform also ships with a few es6 features out of the box (classes, arrow functions, etc -- and the number is growing!), but Traceur definitely has more.
So because you're too lazy to write modules with a minimum of sane dependency injection,you hack require (which is not dependency injection) to mock dependencies?
This is actually the most awfull anti pattern i've seen in javascript land yet.Unfortunatly, it's becoming the "way to go" for most developpers. Instead of making your modules pluggable and decoupled,you negates everything testing is for,you just dont write testable code.
(This is a joke. Please don't do it.)