Are you over 18 and want to see adult content?
More Annotations
A complete backup of parc-livradois-forez.org
Are you over 18 and want to see adult content?
A complete backup of whataboutwatermelon.com
Are you over 18 and want to see adult content?
A complete backup of adventurouskate.com
Are you over 18 and want to see adult content?
A complete backup of traditionsclub.com
Are you over 18 and want to see adult content?
A complete backup of lepetrintoussaint.fr
Are you over 18 and want to see adult content?
A complete backup of custompackagingboxes.co.uk
Are you over 18 and want to see adult content?
Favourite Annotations
A complete backup of https://theplasticshop.co.uk
Are you over 18 and want to see adult content?
A complete backup of https://elamasadero.com
Are you over 18 and want to see adult content?
A complete backup of https://eslint.org
Are you over 18 and want to see adult content?
A complete backup of https://tahiti-tourisme.com
Are you over 18 and want to see adult content?
A complete backup of https://sunnamco.com
Are you over 18 and want to see adult content?
A complete backup of https://binlist.net
Are you over 18 and want to see adult content?
A complete backup of https://zyprexa4u.top
Are you over 18 and want to see adult content?
A complete backup of https://websonic.nl
Are you over 18 and want to see adult content?
A complete backup of https://oceanofapk.com
Are you over 18 and want to see adult content?
A complete backup of https://seetalkabout.com
Are you over 18 and want to see adult content?
A complete backup of https://spookylinks.com
Are you over 18 and want to see adult content?
A complete backup of https://ldt-infocenter.com
Are you over 18 and want to see adult content?
Text
SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users. VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code.SITE MAP | VOWS JS
The site map page of Vows JS. Vows JS. Site Map Vows JS - Home Site Map Terms and Conditions TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users. RECOMMENDED LINKS MC10 The Recommended Links MC10 page of Vows JS. VOWS « ASYNCHRONOUS BDD FOR NODE Synopsis. Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. TERMS AND CONDITIONS Terms and Conditions PRIVACY POLICY Introduction. Your privacy is important to us. We collect information to provide and deliver better service and customized content to our Users.VOWS
ASYNCHRONOUS BEHAVIOUR DRIVEN DEVELOPMENT FOR NODE. THERE ARE TWO REASONS WHY WE MIGHT WANT ASYNCHRONOUS TESTING. THE FIRST, AND OBVIOUS REASON IS THAT NODE.JS IS ASYNCHRONOUS, AND THEREFORE OUR TESTS SHOULD BE. THE SECOND REASON IS TO MAKE TESTS WHICH TARGET I/O RUN MUCH FASTER, BY RUNNING THEM CONCURRENTLY. Write some vows, execute them: $ vows test/* --spec Get the report, make sure you kept your word. A non-EventEmitter return value ✓ should be converted to an EventEmitter A topic not emitting an error ✓ should pass null if the test is expecting an error ✓ should pass the result otherwise A topic emitting an error ✓ shouldn't raise an exception if the test expects it A context with a nested context ✓ has access to the environment - can make coffeeA nested context
✓ should have access to the parent topics A nested context with no topics ✓ should pass the parent topics down ✓ OK » 7 honored • 1 pending (0.112s) intro guide installing referenceSYNOPSIS
Vows is a behavior driven development framework for Node.js. Vows was built from the ground up to test asynchronous code. It executes your tests in parallel when it makes sense, and sequentially when there are dependencies. Emphasis was put on speed of execution, clarity and user experience. Here's a simple example, describing 'division by zero': // division-by-zero-test.js var vows = require('vows'), assert = require('assert'); // Create a Test Suite vows.describe('Division by Zero').addBatch({ 'when dividing a number by zero': { topic: function () { return 42 / 0 }, 'we get Infinity': function (topic) { assert.equal (topic, Infinity);}
},
'but when dividing zero by zero': { topic: function () { return 0 / 0 }, 'we get a value which': { 'is not a number': function (topic) { assert.isNaN (topic);},
'is not equal to itself': function (topic) { assert.notEqual (topic, topic);}
}
}
}).run(); // Run itAnd run it:
$ node division-by-zero-test.js ------------------------- And now, a little more involved example--let's suppose we have a module called 'the-good-things', with some fruit constructors in it: exports.Strawberry = function () { this.color = '#ff0000';};
exports.Strawberry.prototype = { isTasty: function () { return true }};
exports.Banana = function () { this.color = '#fff333';};
exports.Banana.prototype = { peel: function (callback) { process.nextTick(function () { callback(null, new(exports.PeeledBanana));});
},
peelSync: function () { return new(exports.PeeledBanana) }};
exports.PeeledBanana = function () {}; Now write some tests in _the-good-things-test.js_: var vows = require('vows'), assert = require('assert'); var theGoodThings = require('./the-good-things'); var Strawberry   = theGoodThings.Strawberry, Banana       = theGoodThings.Banana, PeeledBanana = theGoodThings.PeeledBanana; vows.describe('The Good Things').addBatch({'A strawberry': {
topic: new(Strawberry), 'is red': function (strawberry) { assert.equal (strawberry.color, '#ff0000');},
'and tasty': function (strawberry) { assert.isTrue (strawberry.isTasty());}
},
'AÂ banana':Â {
topic: new(Banana), 'when peeled *synchronously*': { topic: function (banana) { return banana.peelSync();},
'returns a `PeeledBanana`': function (result) { assert.instanceOf (result, PeeledBanana);}
},
'when peeled *asynchronously*': { topic: function (banana) { banana.peel(this.callback);},
'results in a `PeeledBanana`': function (err, result) { assert.instanceOf (result, PeeledBanana);}
}
}
}).export(module); // Export the Suite And run them with the test runner: $ vows the-good-things-test.jsINSTALLING
The easiest way to install Vows, is via npm, the node package manager,as so:
$ npm install vows This will get you the latest stable version. If you want the bleedingedge, try:
$ npm install vows@latestGUIDE
To understand Vows, we're going to start with a general overview of the different components involved in writing tests, and then go through some of them in more detail. STRUCTURE OF A TEST SUITE Test suites in Vows are the largest unit of tests. The convention is to have one test suite per file, and have the suite's subject match the file name. Test suites are created with vows.describe. var suite = vows.describe('subject'); Tests are added to suites in _batches_. This is done with the addBatchmethod.
suite.addBatch({});
You can add as many batches to a suite as you want. Batches are executed _sequentially_. suite.addBatch({/* run 1st */}).addBatch({/* 2nd */}).addBatch({/* 3rd */}); Chaining batches is useful when you want to test functionality in acertain order.
Batches contain _contexts_, which describe different components and states you want to test.suite.addBatch({
'AÂ context':Â {},
'Another context': {}});
Contexts are executed _in parallel_, they are fully asynchronous. The order in which they finish is therefore undefined. Contexts usually contain _topics_ and _vows_, which in combinationdefine your tests.
suite.addBatch({
'AÂ context':Â {
topic: function () {/* Do something async */}, 'I am a vow': function (topic) { /* Test the result of the topic */}
},
'Another context': {}});
Contexts can contain _sub-contexts_ which get executed as soon as the parent context finishes:suite.addBatch({
'AÂ context':Â {
topic: function () {/* Do something async */}, 'I am a vow': function (topic) { /* Test the result of the topic */},
'A sub-context': { /* Executed when the tests above finish running */}
},
'Another context': { /* Executed in parallel to 'A context' */}
});
SUMMARY
» A _Suite_ is an object which contains zero or more _batches_, and can be executed or exported. » A _batch_ is an object literal, representing a structure of nested_contexts_.
» A _context_ is an object with an optional _topic_, zero or more _vows_ and zero or more _sub-contexts_. » A _topic_ is either a value or a function which can executeasynchronous code.
» A _vow_ is a function which receives the _topic_ as an argument, and runs assertions on it. With that in mind, we can imagine the following grammar: Suite   → Batch* Batch   → Context* Context → Topic? Vow* Context* Here's an annotated example: vows.describe('Array').addBatch({                      // Batch 'An array': {                                      // Context 'with 3 elements': {                           // Sub-Context topic: ,                          // Topic 'has a length of 3': function (topic) {    // Vow assert.equal(topic.length, 3);}
},
'with zero elements': {                        // Sub-Context topic: ,                                 // Topic 'has a length of 0': function (topic) {    // Vow assert.equal(topic.length, 0);},
'returns *undefined*, when `pop()`ed': function (topic) { assert.isUndefined(topic.pop());}
}
}
});
HOW TOPICS WORK
Understanding _topics_ is one of the keys to understanding Vows. Unlike other testing frameworks, Vows forces a clear separation between the element which is tested, the _topic_, and the actualtests, the _vows_.
Let's start with a simple example of a context:{Â topic:Â 42,
'should be equal to 42': function (topic) { assert.equal (topic, 42);}
}
So this shows us that the value of the topic is passed down to our test function (refered to as a _vow_ from now on) as an argument. Simple enough. Now let's look at an equivalent example, writtendifferently:
{ topic: function () { return 42 }, 'should be equal to 42': function (topic) { assert.equal (topic, 42);}
}
Same thing. Topics can be functions too. The return value becomes the topic. Now what if we have multiple vows? { topic: function () { return 42 }, 'should be a number': function (topic) { assert.isNumber (topic);},
'should be equal to 42': function (topic) { assert.equal (topic, 42);}
}
It works as expected, the value is passed down to each _vow_. Note that the topic function is ONLY RUN ONCE.SCOPE
Sometimes, you might need a parent topic's value, from inside a child topic. This is easy, because there is a notion of topic _scope_. Let'slook at an example:
{ topic: new(DataStore), 'should respond to `get()` and `put()`': function (store) { assert.isFunction (store.get); assert.isFunction (store.put);},
'calling `get(42)`': { topic: function (store) { return store.get(42) }, 'should return the object with id 42': function (topic) { assert.equal (topic.id, 42);}
}
}
In the example above, the value of the top-level topic is passed as an argument to the inner topic, in the same manner it's passed to the vows. For clarity, I named both arguments which refer to the outertopic as store.
Note that the scoping isn't limited to a single level. Consider: topic: function (a, /* Parent topic                     */ b, /* Parent of parent topic           */ c  /* Parent of parent of parent topic */) {} So the parent topics are passed along to each topic function in the certain order: the immediate parent is always the first argument (a), and the outer topics follow (b, then c), like the layers of an onion.RUNNING A SUITE
The simplest way to run a test suite, is with the run method: vows.describe('subject').addBatch({/* ... */}).run(); The run method takes an optional callback, which is called when all tests are done running. The test results are passed to the callback (if provided), as an object:{ honored: 145,
broken:Â Â Â Â 4,
errored:Â Â Â 1,
pending:Â Â Â 0,
total:Â Â Â 150,
time:Â Â 5.491
};
Now if we want to execute this test suite, assuming it's in _subject-test.js_, we just do: $ node subject-test.js The results will be printed to the console with the default reporter,'dot-matrix'.
EXPORTING THE SUITE
When your tests become more complex, spanning multiple files, you're going to need a way to run them as a single entity. Vows has a test runner called vows, which you can use to run multiple test suites at once. To make use of it, you need to export your tests, instead of just running them. There's a couple of ways to do that, the easiest is through the export method://Â subject-test.js
vows.describe('subject').addBatch({/* ... */}).export(module); export takes one argument, the module you want to export the test suite to. Fortunately, node provides a global variable called module, which is a reference to the current module. Now to run that file with the test runner, we can do: $ vows subject-test.js The result should be identical to running it directly with node. The difference is that we can now do:$ vows test/*
to run all the tests in our _test/_ folder, and get combined results. We can also pass options to vows. For example, to get a "spec style" output, pass the --spec flag. The reference section has more information on the different options you can pass to it. Another way to export your test suites is by simply adding them to the exports object, the same way you would export an API to a library: exports.suite1 = vows.describe('suite one'); exports.suite2 = vows.describe('suite two');SO LET'S RECAP
//Â subject-test.js
// A test suite, describing 'subject' vows.describe('subject') // Create the suite, describing 'subject' .addBatch({})        // Add the 1st batch .addBatch({})        // Add a 2nd batch .addBatch({})        // Add a 3rd batch .export(module);     // Export it WRITING ASYNCHRONOUS TESTS > Before diving into asynchronous testing, make sure you read the > section about _topics_. Let's say we want to test that a certain file exists, and satisfies acouple criteria.
As you know, we don't 'return' a value from an asynchronous function call--the value is passed to the callback function. So how can we do that with _topics_? Take a look: { topic: function () { fs.stat('~/FILE', this.callback);},
'can be accessed': function (err, stat) { assert.isNull   (err);        // We have no error assert.isObject (stat);       // We have a stat object},
'is not empty': function (err, stat) { assert.isNotZero (stat.size); // The file size is > 0}
}
The key here is the special 'this.callback' function, which is available inside all topics. When this.callback is _called_, it passes on the arguments it received to the test functions, one by one, as if the values were returned by the topic function itself. In essence, this allows us to decouple the callback from the asyncfunction call.
This is how Vows keeps track of all the asynchronous calls, and can warn you if something hasn't returned. > Note that topics which make use of 'this.callback' must not return > anything. And likewise, topics which do not return anything must > make use of 'this.callback'.EVENTEMITTERS
Vows also supports EventEmitter-based async out of the box, so if that works better for your purpose, you can return an instance of EventEmitter from a topic, and the tests will be run when it emits a "success" or "error" event: { topic: function () { var emitter = new(events.EventEmitter); fs.stat('~/FILE', function (e, res) { if (e) { emitter.emit('error', e) } else   { emitter.emit('success', res) }});
return emitter;
},
'can be accessed': function (err, stat) { assert.isNull   (err);        // We have no error assert.isObject (stat);       // We have a stat object},
'is not empty': function (err, stat) { assert.isNotZero (stat.size); // The file size is > 0}
}
ORDER OF EXECUTION AND PARALLELISM We talked about how batches and contexts are executed briefly, but it's now time to delve into it in more detail: { topic: function () { fs.stat('~/FILE', this.callback);},
'after a successful `fs.stat`': { topic: function (stat) { fs.open('~/FILE', "r", stat.mode, this.callback);},
'after a successful `fs.open`': { topic: function (fd, stat) { fs.read(fd, stat.size, 0, "utf8", this.callback);},
'we can `fs.read` to get the file contents': function (data) { assert.isString (data);}
}
}
}
In the example above, we make use of nested contexts to mimic nested callbacks. As you can tell, the result of the parent topic is passed down to its children, as arguments. This example as a whole is therefore mostly sequential, while remaining asynchronous. ------------------------- Now let's look at an example which uses parallel tests to check forsome devices:
{ '/dev/stdout': { topic:    function () { path.exists('/dev/stdout', this.callback) }, 'exists': function (result) { assert.isTrue(result) }},
'/dev/tty':Â {
topic:    function () { path.exists('/dev/tty', this.callback) }, 'exists': function (result) { assert.isTrue(result) }},
'/dev/null':Â {
topic:    function () { path.exists('/dev/null', this.callback) }, 'exists': function (result) { assert.isTrue(result) }}
}
So in this case, the tests can finish in any order, and must not rely on each other. The test suite will exit when the last I/O call completes, and the assertions for it are run. In other words, _sibling contexts_ are executed in parallel, while _nested contexts_ are executed sequentially. Note that this all happens asynchronously, so while some contexts may be waiting for a parent context to finish, sibling contexts can still execute in themeantime.
ASSERTIONS
Vows extends the assertion module which comes bundled with node, with many useful functions, as well as better error reporting for theexisting ones.
It's always best to use the more specific assertion functions when testing a value, you'll get much better error reporting, because your intention is clearer. Let's say we have the following array:var ary = ;
and try to assert that it has 5 elements. With the built-in assert.equal, we would do something like this: assert.equal(ary.length, 5); And get the following error: expected 5, got 3 Now let's try that with one of our more specific assertion functions,assert.lengthOf:
assert.lengthOf(ary, 5); This reports the following error: expected  to have 5 elements Other useful assertion functions bundled with vows include assert.match, assert.instanceOf, assert.include and assert.isEmpty--head over to the reference to get the full list.MACROS
Sometimes, it's useful to abstract tests which are used throughout the test suite. A _batch_ in Vows, is a tree-like data structure--an Object literal to be precise. This proves to be pretty powerful, asyou'll see.
One of the things I have to test in the majority of the code I write are HTTP status codes. So let's first look at the straightforward way of doing this, given an asynchronous client library: { topic: function () { client.get('/resources/42', this.callback);},
'should respond with a 200 OK': function (e, res) { assert.equal (res.status, 200);}
}
Not too bad. But we might have a hundred of these, if we're testing an API. So let's see what we can do with macros: function assertStatus(code) { return function (e, res) { assert.equal (res.status, code);};
}
This is a function which takes a status code, and returns a function which tests for that status code. We can now improve our test likethis:
{ topic: function () { client.get('/resources/42', this.callback);},
'should respond with a 200 OK': assertStatus(200)}
Much better. How about the topic? Let's write a macro for our APIcalls:
var api = {
get: function (path) { return function () { client.get(path, this.callback);};
}
};
And rewrite our tests: { topic: api.get('/resources/42'), 'should respond with a 200 OK': assertStatus(200)}
Fantastic. Here's a an example of what these macros could look like:{Â Â Â 'GETÂ /':Â {
topic: api.get('/'), 'should respond with a 200 OK': assertStatus(200)},
'POSTÂ /':Â {
topic: api.post('/'), 'should respond with a 405 Method not allowed': assertStatus(405)},
'GET /resources (no api-key)': { topic: api.get('/resources'), 'should respond with a 403 Forbidden': assertStatus(403)},
'GET /resources?apikey=af816e859c249fe': { topic: api.get('/resources?apikey=af816e859c249fe'), 'should return a 200 OK': assertStatus(200), 'should return a list of resources': function (res) { assert.isArray (res.body);}
}
}
Can we push it further? Of course we can, and this is when it gets _really_ interesting. I'm going to show you how you can generatecontextual tests.
Instead of having a separate function which generates a _topic_, and another one which generates a _vow_, we're going to have a function which generates a _context_ which contains both a topic and a vow. The topic will perform a _contextual_ request. This is the interesting part: we're going to parse the context description to generate the api requests. So the test will be encoded within its description. Let's look at a possible implementation://
// Send a request and check the response status.//
function respondsWith(status) {var context = {
topic: function () { // Get the current context's name, such as "POST /" // and split it at the space. var req    = this.context.name.split(/ +/), // method = req.toLowerCase(),          // "post" path   = req;                        // "/" // Perform the contextual client request, // with the above method and path. client(path, this.callback);}
};
// Create and assign the vow to the context. // The description is generated from the expected status code // and status name, from node's http module. context = assertStatus(status);return context;
}
Now the first three contexts of our batch can be re-written as: { 'GET  /':                   respondsWith(200), 'POST /':                   respondsWith(405), 'GET  /resources (no key)': respondsWith(403)}
And when run, we get:GETÂ Â /
✓ should respond with a 200 OKPOST /
✓ should respond with a 405 Method Not Allowed GET  /resources (no key) ✓ should respond with a 403 Forbidden The fourth context is a little more complex, as it has two vows, but I'll let you figure that one out!REFERENCE
The CLI and assertion module are documented here.TEST RUNNER
vows
Running specific tests $ vows test-1.js test-2.js$ vows tests/*
Running all tests in your _test/_ or _spec/_ folder$Â vows
Watch mode
$ vows -w
$ vows --watch
-------------------------OPTIONS
-v, --verbose
Verbose mode
-w, --watch
Watch mode
-m STRING
String matching: Only run tests with STRING in their title-r REGEXP
Regexp matching: Only run tests with REGEXP in their title--json
Use JSON reporter
--spec
Use Spec reporter
--dot-matrix
Use Dot-Matrix reporter--version
Show version
-s, --silent
Don't report
--help
Show help
ASSERTION FUNCTIONS
EQUALITY
assert.equal          (4, 4); assert.strictEqual    (4 > 2, true); assert.notEqual       (4, 2); assert.notStrictEqual (1, true); assert.deepEqual      (, ); assert.notDeepEqual   (, ); assert.epsilon        (1e-5, 0.1 + 0.2, 0.3);TYPE
assert.isFunction (function () {}); assert.isObject   ({goo:true}); assert.isString   ('goo'); assert.isArray    (); assert.isNumber   (42); assert.isBoolean  (true); assert.typeOf     (42, 'number'); assert.instanceOf (, Array);TRUTH
assert.isTrue  (true); assert.isFalse (false); NULL, UNDEFINED, NAN assert.isNull      (null); assert.isNotNull   (undefined); assert.isUndefined ('goo'); assert.isNaN       (0/0);INCLUSION
assert.include (, 2); assert.include ({goo:true}, 'goo'); assert.include ('goo', 'o');REGEXP MATCHING
assert.match ('hello', /^+/);LENGTH
assert.lengthOf (, 3); assert.lengthOf ('goo', 3);EMPTINESS
assert.isEmpty ();
assert.isEmpty ({}); assert.isEmpty ("");EXCEPTIONS
assert.throws(function () { x + x }, ReferenceError); assert.doesNotThrow(function () { 1 + 1 }, Error); © Copyright. 2020. VowsJS. All Rights Reserved. Terms |Site Map
Details
Copyright © 2024 ArchiveBay.com. All rights reserved. Terms of Use | Privacy Policy | DMCA | 2021 | Feedback | Advertising | RSS 2.0