As someone who's become a React core contributor since React was released a year ago and had the opportunity to work with a handful of people from the Facebook frontend team, I want to say that I'm really impressed with the quality of the JavaScript libraries that Facebook has released. React is the obvious big one, but other smaller projects like regenerator and jstransform are awesome too. I'm excited to see Jest join the party.
At some point I'd like to add support for using mocha within Jest 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 like Mocha as well at some point.
Mock functions are a really powerful tool. They let you test asynchronous functions in an entirely synchronous way. Because of that, Jest doesn't need to provide special support for asynchronous testing
That might work for simple cases but I'd be worried that switching all your asynchronous calls to synchronous has the potential to introduce bugs that your tests would then miss. Testing asynchronous functions is hard for lots of reasons, and only one of them is that you have to wait for it to finish.
Sorry for the dumb question, but as a JS (and JS testing) newbie, could someone explain how Jest is different from Jasmine (from which it's built on) or, say, from Mocha?
jasmine and mocha are test frameworks (they're the things that supply your describe() and it() functions), but they don't really supply you with everything you need to get set up to run tests.
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
Nice. When will there be a grunt plugin for it? I'm using the qunit plugin right now and I notice that it's 10x slower to run than viewing it in the browser. This 10 second feedback loop is driving me crazy.
About a month or three ago I hacked up a grunt task for React, but it wasn't very useful since we hadn't opensourced Jest yet.
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:
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.
You might want to look at http://www.venusjs.org/ to get some ideas for supporting multiple testing frameworks. It uses an annotation approach kind of how you include files for tests. The automatic mocking is pretty awesome though.
Might be a silly question, but has anyone tried Jest along with AngularJS and survived to tell the story? Mocking stuff has always been one of my biggest pain points when testing on Angular and I'm really itching to try this! Congrats folks at Facebook.
Where did I say "difficult"? I said "pain point", which is different. In my experience, same as your sibling comment, you end up having a lot of boilerplate and it's just convoluted. Mocking out stuff should be simpler, in my opinion. How about auto-generating Jasmine spies, for example?
Resharper added jasmine support in v.7 as far as I remember. I wonder if Jest would work with Resharper out of the box, would be helpful in .NET world to have the Jest runner integrated with VS.
Looks interesting: the test suite for our current AngularJS project is slowly slowing down, in part because there's just more tests, but the major performance bottlenecks are:
* 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.
We're not using CoffeeScript inside of Facebook. But we are using many ES6 features that make JS look a lot like CoffeeScript such as classes, arrow functions, rest arguments, destructuring assignment ... I figured that CoffeeScript would be a good example to show that Jest supports languages that transpile to JS :)
Internally we use jstransform (github.com/facebook/jstransform) because it allows us to plug in individual transforms more easily. It's also what React uses for it's jsx transformations.
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.
I think auto mocking modules is the most horrible trick a testing framework can pull.
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.
Congrats guys. :)