-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add ability to pass in test files to be ran before positional files via --file #3190
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -736,6 +736,7 @@ Mocha supports the `err.expected` and `err.actual` properties of any thrown `Ass | |
--debug-brk enable node's debugger breaking on the first line | ||
--globals <names> allow the given comma-delimited global [names] | ||
--es_staging enable all staged features | ||
--file <file> include a file to be ran during the suite [file] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a section in the documentation for this option. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added below. |
||
--harmony<_classes,_generators,...> all node --harmony* flags are available | ||
--preserve-symlinks Instructs the module loader to preserve symbolic links when resolving and caching modules | ||
--icu-data-dir include ICU data | ||
|
@@ -849,6 +850,10 @@ Specifies the test-case timeout, defaulting to 2 seconds. To override you may pa | |
|
||
Specify the "slow" test threshold, defaulting to 75ms. Mocha uses this to highlight test-cases that are taking too long. | ||
|
||
### `--file <file>` | ||
|
||
Add a file you want included first in a test suite. This is useful if you have some generic setup code that must be included within the test suite. The file passed is not affected by any other flags (`--recursive` or `--sort` have no effect). Accepts multiple `--file` flags to include multiple files, the order in which the flags are given are the order in which the files are included in the test suite. Can also be used in `mocha.opts`. | ||
|
||
### `-g, --grep <pattern>` | ||
|
||
The `--grep` option when specified will trigger mocha to only run tests matching the given `pattern` which is internally compiled to a `RegExp`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
describe('alpha', function () { | ||
it('should be executed first', function () { | ||
if (global.beta !== undefined) { | ||
throw new Error('alpha was not executed first'); | ||
} | ||
|
||
if (global.theta !== undefined) { | ||
throw new Error('alpha was not executed first'); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
|
||
describe('beta', function () { | ||
it('should be executed second', function () { | ||
global.beta = 1; | ||
|
||
if (global.theta !== undefined) { | ||
throw new Error('beta was not executed second'); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
describe('theta', function () { | ||
it('should be executed third', function () { | ||
global.theta = 1; | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ | |
|
||
var path = require('path'); | ||
var assert = require('assert'); | ||
var run = require('./helpers').runMochaJSON; | ||
var directInvoke = require('./helpers').invokeMocha; | ||
var helpers = require('./helpers'); | ||
var run = helpers.runMochaJSON; | ||
var directInvoke = helpers.invokeMocha; | ||
var resolvePath = helpers.resolveFixturePath; | ||
var args = []; | ||
|
||
describe('options', function () { | ||
|
@@ -91,6 +93,53 @@ describe('options', function () { | |
}); | ||
}); | ||
|
||
describe('--file', function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we also test multiple you may need to monkey with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added an individual additional test that should provide coverage for this. |
||
it('should run tests passed via file first', function (done) { | ||
args = ['--file', resolvePath('options/file-alpha.fixture.js')]; | ||
|
||
run('options/file-beta.fixture.js', args, function (err, res) { | ||
if (err) { | ||
done(err); | ||
return; | ||
} | ||
assert.equal(res.stats.pending, 0); | ||
assert.equal(res.stats.passes, 2); | ||
assert.equal(res.stats.failures, 0); | ||
|
||
assert.equal(res.passes[0].fullTitle, | ||
'alpha should be executed first'); | ||
assert.equal(res.code, 0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should run multiple tests passed via file first', function (done) { | ||
args = [ | ||
'--file', resolvePath('options/file-alpha.fixture.js'), | ||
'--file', resolvePath('options/file-beta.fixture.js') | ||
]; | ||
|
||
run('options/file-theta.fixture.js', args, function (err, res) { | ||
if (err) { | ||
done(err); | ||
return; | ||
} | ||
assert.equal(res.stats.pending, 0); | ||
assert.equal(res.stats.passes, 3); | ||
assert.equal(res.stats.failures, 0); | ||
|
||
assert.equal(res.passes[0].fullTitle, | ||
'alpha should be executed first'); | ||
assert.equal(res.passes[1].fullTitle, | ||
'beta should be executed second'); | ||
assert.equal(res.passes[2].fullTitle, | ||
'theta should be executed third'); | ||
assert.equal(res.code, 0); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('--delay', function () { | ||
before(function () { | ||
args = ['--delay']; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, so
--sort
doesn't work with--file
, which makes sense. that should be noted somewhere if it isn't already.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in
docs/index.md