DailyJS

Node Roundup: io.js 2.0, Bootstruct, JSVerify

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

frameworks libraries v8 node testing rest modules

Node Roundup: io.js 2.0, Bootstruct, JSVerify

Posted by Alex R. Young on .
Featured

frameworks libraries v8 node testing rest modules

Node Roundup: io.js 2.0, Bootstruct, JSVerify

Posted by Alex R. Young on .

io.js 2.0

io.js 2.0 was released this week, and it brings some big changes from V8 and fixes to core modules.

The V8 changes include the class keyword in strict mode without flags, shorthand method and property syntax, rest parameters (with --harmony-rest-parameters), computed property names (with --harmony-computed-property-names), and unicode escapes (with --harmony_unicode and --harmony_unicode_regexps). "Rest parameters" means function(a, b, ...args) {}, and args is actually a real array. MDN has more details.

Unfortunately this release has breaking changes, so you'll want to test it thoroughly. The breaking changes are partly related to V8 because the C++ API has changed. I think this might impact some native modules, but I haven't checked the details. The behaviour of os.tmpdir has changed as well, it no longer returns a path with a trailing slash.

Bootstruct

Bootstruct (GitHub: taitulism/Bootstruct, License: ISC, npm: bootstruct) by Taitu Lizenbaum is a module for creating RESTful frameworks based on files and folders. If you create a file in a folder called post, it will map the methods inside to POST requests.

To write methods, you have to create functions that take a single argument: io. This value has res and req objects, so it looks similar to other Node HTTP frameworks.

The readme has a lot of details on how Bootstruct generates the internal representation of the folders, filenames, and HTTP verbs, and it seems like it would be fairly easy to get used to the pattern. If you consider app.httpVerb to be unnecessary boilerplate, or perhaps have folders of data that you could map to a Bootstruct application with suitable wrapping code, then you might find it useful.

JSVerify

JSVerify

I'll admit that I was a little bit confused by JSVerify (GitHub: jsverify/jsverify, License: MIT, npm: jsverify). It's a "property-based" testing framework, which to my JavaScript-oriented mind interpreted as something that tests properties on objects. Property-based testing actually refers to a style of testing where properties are specifications of a behaviour that should hold certain values. I found a nice and short definition of it by Jessica Kerr:

Property-based tests make statements about the output of your code based on the input, and these statements are verified for many different possible inputs.

JSVerify will generate inputs for a function. This example is taken from the documentation:

// forall (f: json -> bool, b: bool), f (f (f b)) ≡ f(b).
var boolFnAppliedThrice =  
  jsc.forall('bool -> bool', 'bool', function(f, b) {
    return f(f(f(b))) === f(b);
  });

jsc.assert(boolFnAppliedThrice);  
// OK, passed 100 tests

It also includes examples for testing promises. The way it works with JavaScript's syntax and the compatibility with asynchronous code makes the tests look very succinct, but it will take a bit of practice to get the hang of it.