Skip to content

Commit

Permalink
Introduce --no-detect-globals
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Oct 9, 2019
1 parent 2ac8921 commit 615584c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ var defaults = {
yields: '0',
colors: null,
'async-polling': true,
'request-interception': true
'request-interception': true,
'detect-globals': true
};

function args(argv) {
Expand All @@ -39,7 +40,7 @@ function args(argv) {
boolean: ['help', 'version', 'watch', 'cover', 'node', 'wd', 'debug',
'invert', 'recursive', 'colors', 'ignore-ssl-errors', 'browser-field',
'commondir', 'allow-chrome-as-root', 'async-polling', 'dumpio',
'request-interception'],
'request-interception', 'detect-globals'],
alias: {
help: 'h',
version: 'v',
Expand Down
2 changes: 2 additions & 0 deletions lib/mochify.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ module.exports = function (_, opts) {
brOpts.commondir = false;
brOpts.detectGlobals = false;
brOpts.insertGlobalVars = ['__dirname', '__filename'];
} else {
brOpts.detectGlobals = opts['detect-globals'];
}
brOpts.extensions = opts.extension;
brOpts.browserField = opts['browser-field'];
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"url": "https://github.com/mantoni/mochify.js.git"
},
"dependencies": {
"brout": "^1.1.0",
"brout": "^1.3.0",
"browserify": "^16.2.3",
"consolify": "^2.1.0",
"coverify": "^1.4.1",
Expand Down
13 changes: 13 additions & 0 deletions test/args-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('args', function () {
assert.equal(opts['browser-field'], true);
assert.equal(opts.commondir, true);
assert.equal(opts['request-interception'], true);
assert.equal(opts['detect-globals'], true);
});

it('parses --reporter', function () {
Expand Down Expand Up @@ -330,6 +331,18 @@ describe('args', function () {
assert.equal(opts['request-interception'], false);
});

it('parses --detect-globals', function () {
var opts = args(['--detect-globals']);

assert(opts['detect-globals']);
});

it('parses --no-detect-globals', function () {
var opts = args(['--no-detect-globals']);

assert.equal(opts['detect-globals'], false);
});

it('fails with invert but no grep option', function (done) {
run('passes', ['--invert'], function (code, stdout) {
assert.equal(code, 1);
Expand Down
18 changes: 18 additions & 0 deletions test/chromium-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ describe('chromium', function () {
});
});

it('detects globals by default', function (done) {
run('detect-globals', ['-R', 'tap'],
function (code, stdout, stderr) {
assert.equal(stderr, 'object\n');
assert.equal(code, 0);
done();
});
});

it('allows to turn off global detection', function (done) {
run('detect-globals', ['--no-detect-globals'],
function (code, stdout, stderr) {
assert.equal(stderr, 'undefined\n');
assert.equal(code, 0);
done();
});
});

context('https-server with a port value given', function () {
var server;
var port;
Expand Down
10 changes: 10 additions & 0 deletions test/fixture/detect-globals/test/global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*global describe, it*/
'use strict';

describe('global', function () {

it('prints typeof global', function () {
console.error(typeof global);
});

});

0 comments on commit 615584c

Please sign in to comment.