Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Introducing Google JS Test (google-opensource.blogspot.com)
125 points by cleverjake on Sept 29, 2011 | hide | past | favorite | 24 comments


This is for unit-testing in V8 only: no DOM. I'm currently using PhantomJS, which is V8 + Webkit and seems to be a superset of this new "JS Test". I can't see any reason to add JS Test in addition to PhantomJS.


For several years I have been using QtWebKit to write tests that utilize the dom. Fast startup, console output etc. I wouldn't be surprised if the Chrome guys have a similar stripped down Chrome for JS unit tests.


Another possibility, which I use for testing my Firefox Add-ons, is using Rhino + env.js, which creates a very good simulation of the DOM.


Could be very helpful as a node.js addon


Not really, node.js already has heaps of testing frameworks that work fine in it.


non-dom based javascript, would be my first thought.


What's the purpose of complex testing frameworks like this? What's wrong with using a simple framework whose tests must simply return a bool?

For example:

         var myObject = new Something("foo", "bar");	 
	
	 assert("simple operations", function() {
		return myObject.doSomething() == "baz";
	 });;
	 
	 assert("post-operational state", function() {
		return myObject.state() == 123;
	 });;
	 
	 assertAync("async polling", function() {
		return myObject.poll().length > 0;
	 });;
Note that those tests would be much prettier in CoffeeScript.

Is the purpose of heavy testing frameworks purely for the useful functions like "deepEquals"? If so, why not make a library with functions like "deepEquals" and use that library with a simple testing framework? Surely, there must be something I'm missing.

Edit: I should note that the beautifully written CoffeeScript compiler/translator doesn't use a testing framework (favoring a few simple hand-rolled functions), and it has a massive suite of tests.


One advantage is debugging failures. If the test framework only knows that a test passed or failed, but not why, then you don't get to know why either, because it can't tell you.

For instance, many test runners will show you the expected and actual values when a comparison fails. If they're large blobs of text, it can show you a diff, etc.


Did anyone else notice the screenshot is of a translucent terminal? I was curious what was in the background so I played with the levels.

http://i.imgur.com/6jifV.png http://i.imgur.com/cIXox.png


I would love to hear how did you do that.


In Photoshop, I opened the image up and first chose Image -> Adjustments -> Replace Color. I shift-clicked (sampled) each color of source code by clicking on a few different pixel of the text. I dragged the Lightness slider to zero to make the source code black thereby "erasing" the source from the window.

Next, I opened up Image -> Adjustments -> Levels and dragged the grey (middle) adjustment slider toward the left to lighten the darker areas. Dragging the white (right) slider a little left also helps to reduce the maximum blackness of the image.


Thank you for the explanation. :)


I've been using jquery in node.js for a while now in my tests. This gives me access to the DOM and all of the great stuff that jQuery gives us:

    @GET "/", ( err, response ) =>
      response.withJquery ( err, $ ) =>
        @equal $( "#blah" ).text(), "Something"
Really cool stuff.


Have you looked into zombie.js (http://zombie.labnotes.org/)? It allows for selectors as well, and is a very straight forward headless browser.


No, I hadn't. It looks great, I'll certainly check it out properly soon!


I've been really happy with JazzMoney: https://github.com/pivotalexperimental/jazz_money I'm looking over the limited documentation available and so far I'm not persuaded to switch. I'm very curious about measuring code coverage - nothing seems to be mentioned there about it, but I imagine the Goog does do that.


I'm looking to branch out after having used qUnit for the last year or so. Looks like this framework does mocking REALLY well (which I feel like I can't do well in qUnit). But it's v8 specific, so I can't test if Internet Exploder won't screw up my script.

Would anybody recommend any other unit-test frameworks for mocking stuff out?



There's also a fantastic tool for running those tests headlessly with jasmine-headless-webkit[0]. The benefit is that you can, if you so desire, test against the DOM as there is a complete browser in the background.

[0] http://johnbintz.github.com/jasmine-headless-webkit/


Ah, interesting.

If headless is not what you want, js-test-driver[1] looks promising. It has adapters for jasmine too.

1. http://code.google.com/p/js-test-driver/


Anyone recognize the font in the screenshot?


Monaco 10pt.


Rats, somehow I dismissed Monaco as the obvious answer -- I think I'm used to seeing it at smaller sizes. Thanks!


Jasmine.js FTW.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: