Skip to content

Commit

Permalink
fix timeout/slow string values and duplicate arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Mar 12, 2019
1 parent a3089ad commit 299a710
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/cli/run-option-metadata.js
Expand Up @@ -44,8 +44,8 @@ exports.types = {
'sort',
'watch'
],
number: ['retries', 'slow', 'timeout'],
string: ['fgrep', 'grep', 'package', 'reporter', 'ui']
number: ['retries'],
string: ['fgrep', 'grep', 'package', 'reporter', 'ui', 'slow', 'timeout']
};

/**
Expand Down
10 changes: 10 additions & 0 deletions lib/cli/run.js
Expand Up @@ -258,6 +258,16 @@ exports.builder = yargs =>
}
});

types.boolean.concat(types.string, types.number).forEach(opt => {
if (Array.isArray(argv[opt])) {
throw createInvalidArgumentValueError(
`Argument "${opt}" can only be provided once`,
opt,
argv[opt]
);
}
});

// yargs.implies() isn't flexible enough to handle this
if (argv.invert && !('fgrep' in argv || 'grep' in argv)) {
throw createMissingArgumentError(
Expand Down
11 changes: 11 additions & 0 deletions test/integration/fixtures/options/slow-test.fixture.js
@@ -0,0 +1,11 @@
'use strict';

describe('a suite', function() {
it('should succeed, slowly', function(done) {
setTimeout(done, 500);
});

it('should succeed, very slowly', function(done) {
setTimeout(done, 1500);
});
});
45 changes: 32 additions & 13 deletions test/integration/invalid-arguments.spec.js
Expand Up @@ -3,18 +3,37 @@
var invokeMocha = require('./helpers').invokeMocha;

describe('invalid arguments', function() {
it('should exit with failure if arguments are invalid', function(done) {
invokeMocha(
['--ui'],
function(err, result) {
if (err) {
return done(err);
}
expect(result, 'to have failed');
expect(result.output, 'to match', /not enough arguments/i);
done();
},
{stdio: 'pipe'}
);
describe('when argument is missing required value', function() {
it('should exit with failure', function(done) {
invokeMocha(
['--ui'],
function(err, result) {
if (err) {
return done(err);
}
expect(result, 'to have failed');
expect(result.output, 'to match', /not enough arguments/i);
done();
},
{stdio: 'pipe'}
);
});
});

describe('when argument is provided twice', function() {
it('should exit with failure', function(done) {
invokeMocha(
['--timeout', '600', '--timeout', '600'],
function(err, result) {
if (err) {
return done(err);
}
expect(result, 'to have failed');
expect(result.output, 'to match', /can only be provided once/i);
done();
},
{stdio: 'pipe'}
);
});
});
});
35 changes: 35 additions & 0 deletions test/integration/options/timeout.spec.js
@@ -0,0 +1,35 @@
'use strict';

var helpers = require('../helpers');
var runMochaJSON = helpers.runMochaJSON;

describe('--timeout', function() {
it('should allow human-readable string value', function(done) {
runMochaJSON('options/slow-test', ['--timeout', '1s'], function(err, res) {
if (err) {
done(err);
return;
}
expect(res, 'to have failed')
.and('to have passed test count', 1)
.and('to have failed test count', 1);
done();
});
});

it('should allow numeric value', function(done) {
runMochaJSON('options/slow-test', ['--timeout', '1000'], function(
err,
res
) {
if (err) {
done(err);
return;
}
expect(res, 'to have failed')
.and('to have passed test count', 1)
.and('to have failed test count', 1);
done();
});
});
});
4 changes: 2 additions & 2 deletions test/node-unit/cli/options.spec.js
Expand Up @@ -624,7 +624,7 @@ describe('options', function() {
findupSync
});

expect(loadOptions(), 'to satisfy', {timeout: 800, require: ['foo']});
expect(loadOptions(), 'to satisfy', {timeout: '800', require: ['foo']});
});

it('should prioritize package.json over mocha.opts', function() {
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('options', function() {
loadOptions('--timeout 500'),
'to have property',
'timeout',
500
'500'
);
});
});
Expand Down

0 comments on commit 299a710

Please sign in to comment.