Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement --browser-field option #139

Merged
merged 2 commits into from May 15, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -104,6 +104,7 @@ Run `mochify --help` to see all available options.
- `--plugin` specifies a Browserify plugin to add. Can be specified multiple
times. Options can be passed with [subargs][].
- `--extension` search for files with the extension in "require" statements.
- `--no-browser-field` turns off package.json browser field resolution.
- `--yields` or `-y` changes the yield interval to allow pending I/O to happen.
- `--version` or `-v` shows the Mochify version number.
- `--help` or `-h` shows usage and all available options.
Expand Down Expand Up @@ -197,7 +198,8 @@ mochify('./test/*.js', {
- `mochify(paths, opts)` combines custom paths and options

All long form command line options can be used. E.g. `--node` can be configured
as `{ node : true }`, `--reporter tab` as `{ reporter : 'tab' }` and so on.
as `{ node : true }`, `--no-browser-field` as `{ 'browser-field': false }`,
`--reporter tab` as `{ reporter : 'tab' }` and so on.

Additional API options:

Expand Down
3 changes: 2 additions & 1 deletion lib/args.js
Expand Up @@ -17,6 +17,7 @@ var defaults = {
wd : false,
recursive : false,
'ignore-ssl-errors': false,
'browser-field': true,
reporter : 'dot',
timeout : '2000',
port : '0',
Expand All @@ -32,7 +33,7 @@ function args(argv) {
'wd-file', 'path'],
boolean : ['help', 'version', 'watch', 'cover', 'node', 'wd',
'debug', 'invert', 'recursive', 'colors',
'ignore-ssl-errors'],
'ignore-ssl-errors', 'browser-field'],
alias : {
help : 'h',
version : 'v',
Expand Down
5 changes: 4 additions & 1 deletion lib/help.txt
Expand Up @@ -7,7 +7,7 @@ Defaults "entry" to "./test/*.js".
-w, --watch Use watchify to watch your files and run the tests on
change.

-R, --reporter Change the Mocha reporter.
-R, --reporter Change the Mocha reporter.
Mocha reporters known to work:
doc, dot (default), json, landing, list, markdown, min,
spec, tap, xunit
Expand Down Expand Up @@ -66,6 +66,9 @@ Defaults "entry" to "./test/*.js".
statements. For example, "--extension .coffee". Can be
specified multiple times.

--no-browser-field Turn off package.json browser field resolution. This is
also handy if you need to run a bundle in node.

-y, --yields Changes the yield interval to allow pending I/O to happen.

-v, --version Print mochify version and exit.
Expand Down
1 change: 1 addition & 0 deletions lib/mochify.js
Expand Up @@ -102,6 +102,7 @@ module.exports = function (_, opts) {
brOpts.insertGlobalVars = ['__dirname', '__filename'];
}
brOpts.extensions = opts.extension;
brOpts.browserField = opts['browser-field'];
brOpts.paths = opts.path;

var b = browserify(brOpts);
Expand Down
13 changes: 13 additions & 0 deletions test/args-test.js
Expand Up @@ -28,6 +28,7 @@ describe('args', function () {
assert.equal(opts.port, 0);
assert.equal(opts.yields, 0);
assert.equal(opts['ignore-ssl-errors'], false);
assert.equal(opts['browser-field'], true);
});

it('parses --reporter', function () {
Expand Down Expand Up @@ -215,6 +216,18 @@ describe('args', function () {
assert.equal(opts.colors, false);
});

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

assert(opts['browser-field']);
});

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

assert.equal(opts['browser-field'], false);
});

it('parses --path', function () {
var opts = args(['--path', './source/']);

Expand Down

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

2 changes: 2 additions & 0 deletions test/fixture/browser-field/node_modules/some-module/index.js

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

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

14 changes: 14 additions & 0 deletions test/fixture/browser-field/test/browser-field.js
@@ -0,0 +1,14 @@
/*global describe, it*/
'use strict';

var someModule = require('some-module');

describe('browser-field', function () {

it('passes in browser', function () {
if (someModule !== 'browser') {
throw new Error();
}
});

});
26 changes: 26 additions & 0 deletions test/node-test.js
Expand Up @@ -257,6 +257,32 @@ describe('node', function () {
});
});

it('passes browser-field', function (done) {
run('browser-field', ['--node', '-R', 'tap'],
function (code, stdout) {
assert.equal(stdout, '# node:\n'
+ '1..1\n'
+ 'ok 1 browser-field passes in browser\n'
+ '# tests 1\n'
+ '# pass 1\n'
+ '# fail 0\n');
assert.equal(code, 0);
done();
});
});

it('fails browser-field with --browser-field disabled', function (done) {
run('browser-field', ['--node', '-R', 'tap', '--no-browser-field'],
function (code, stdout) {
assert.equal(stdout.indexOf('# node:\n'
+ '1..1\n'
+ 'not ok 1 browser-field passes in browser\n'
+ ' Error'), 0);
assert.equal(code, 1);
done();
});
});

// This test case fails on node 0.10 only. The corresponding phantomjs test
// passes on node 0.10 and 0.12.
it.skip('shows unicode diff', function (done) {
Expand Down