Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ internals.traverse = function (paths, options) {
if (testFiles.length) {
testFiles.forEach(function (file) {

global._labScriptRun = false;
file = Path.resolve(file);
var pkg = require(file);
if (pkg.lab &&
pkg.lab._root) {

scripts.push(pkg.lab);
}
else if (global._labScriptRun) {
options.output.write('The file: ' + file + ' includes a lab script that is not exported via exports.lab');
return process.exit(1);
}
});
}

Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ exports.script = function (options) {

options = options || {};

global._labScriptRun = true; // Compared by CLI to detect missing exports.lab

var script = {
_current: {
experiments: [],
Expand Down
2 changes: 2 additions & 0 deletions lib/leaks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var internals = {};
exports.detect = function (customGlobals) {

var whitelist = {
_labScriptRun: true, // Lab global to detect script executions

// Enumerable globals
setTimeout: true,
setInterval: true,
Expand Down
48 changes: 48 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,52 @@ describe('CLI', function () {
done();
});
});

it('Displays error message when a script is detected without an exports.lab', function (done) {

var cli = ChildProcess.spawn('node', [labPath, 'test/cli_no_exports/missingExports.js']);
var output = '';

cli.stdout.on('data', function (data) {

output += data;
});

cli.stderr.on('data', function (data) {

expect(data).to.not.exist;
});

cli.on('close', function (code, signal) {

expect(code).to.equal(1);
expect(signal).to.not.exist;
expect(output).to.contain('includes a lab script that is not exported via exports.lab');
done();
});
});

it('Displays error message when a script is missing exports and other scripts contain them', function (done) {

var cli = ChildProcess.spawn('node', [labPath, 'test/cli_no_exports/']);
var output = '';

cli.stdout.on('data', function (data) {

output += data;
});

cli.stderr.on('data', function (data) {

expect(data).to.not.exist;
});

cli.on('close', function (code, signal) {

expect(code).to.equal(1);
expect(signal).to.not.exist;
expect(output).to.contain('includes a lab script that is not exported via exports.lab');
done();
});
});
});
27 changes: 27 additions & 0 deletions test/cli_no_exports/hasExports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Load modules

var _Lab = require('../../test_runner');


// Declare internals

var internals = {};


// Test shortcuts

var lab = exports.lab = _Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = _Lab.expect;


describe('Test CLI Exports', function () {

it('adds two numbers together', function (done) {

expect(1+1).to.equal(2);
done();
});
});

26 changes: 26 additions & 0 deletions test/cli_no_exports/missingExports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Load modules

var _Lab = require('../../test_runner');


// Declare internals

var internals = {};


// Test shortcuts

var lab = _Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = _Lab.expect;


describe('Test CLI', function () {

it('adds two numbers together', function (done) {

expect(1+1).to.equal(2);
done();
});
});