Skip to content

Instantly share code, notes, and snippets.

@paolochiodi
Last active September 11, 2015 15:39
Show Gist options
  • Save paolochiodi/74f462492ec45756fd9d to your computer and use it in GitHub Desktop.
Save paolochiodi/74f462492ec45756fd9d to your computer and use it in GitHub Desktop.
Example to create importable test suites with lab

This is a possible approach to create a set of tests (child.js) that can be imported into another project (parent.js) and run through it. This kind of approach also allows to pass parameters and options to the initial set of tests (in this case si).

Another possible approach is to just return lab from the child test and have it re-exported by parent (in this case parameteres would need to be added to tests).

Tests are run with lab parent.js.

This has been explored for use in seneca-store-test. Using this approach we can refactore seneca-store-test to directly use experiments and tests (or describe/it in BDD parlance) while still depende on store implementation to provide a correctly configured seneca instance. The added benefits imho are:

  1. easier and clearer for stores to implement
  2. better reporting
  3. more tools available to seneca-store-test to write tests (e.g.: before, after)
var assert = require("assert");
var Lab = require("lab");
function childTests(si) {
var lab = exports.lab = Lab.script();
lab.describe("child test", function () {
lab.it("should work", function (done) {
assert.equal(si, "seneca");
done();
});
});
return lab;
}
module.exports = childTests;
{
"name": "test_lab",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"lab": "^5.16.0"
}
}
var assert = require("assert");
var Lab = require("lab");
var si = "seneca";
var tests = exports.lab = require("./child")(si);
tests.describe("parent test", function () {
tests.it("should work too", function (done) {
assert(true);
done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment