Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
hswolff committed Jan 5, 2018
1 parent 3ba35d6 commit 0008924
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
7 changes: 2 additions & 5 deletions bin/_mocha
Expand Up @@ -81,10 +81,7 @@ const list = str => str.split(/ *, */);
/**
* Parse multiple flag.
*/
const collect = (val, memo) => {
memo.push(val);
return memo;
};
const collect = (val, memo) => memo.concat(val);

/**
* Hide the cursor.
Expand Down Expand Up @@ -208,7 +205,7 @@ program
.option('--allow-uncaught', 'enable uncaught errors to propagate')
.option('--forbid-only', 'causes test marked with only to fail the suite')
.option('--forbid-pending', 'causes pending tests and test marked with skip to fail the suite')
.option('--file [file]', 'include a file to be ran during the suite', collect, []);
.option('--file <file>', 'include a file to be ran during the suite', collect, []);

program._name = 'mocha';

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Expand Up @@ -852,7 +852,7 @@ Specify the "slow" test threshold, defaulting to 75ms. Mocha uses this to highli

### `--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 effected by any other flags (`--recursive` or `--sort` have no effect). Accepts multiple `--file` flags to include multiple files.
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>`

Expand Down
4 changes: 4 additions & 0 deletions test/integration/fixtures/options/file-alpha.fixture.js
Expand Up @@ -5,5 +5,9 @@ describe('alpha', 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');
}
});
});
4 changes: 4 additions & 0 deletions test/integration/fixtures/options/file-beta.fixture.js
Expand Up @@ -3,5 +3,9 @@
describe('beta', function () {
it('should be executed second', function () {
global.beta = 1;

if (global.theta !== undefined) {
throw new Error('beta was not executed second');
}
});
});
7 changes: 7 additions & 0 deletions test/integration/fixtures/options/file-theta.fixture.js
@@ -0,0 +1,7 @@
'use strict';

describe('theta', function () {
it('should be executed third', function () {
global.theta = 1;
});
});
30 changes: 27 additions & 3 deletions test/integration/options.spec.js
Expand Up @@ -94,11 +94,9 @@ describe('options', function () {
});

describe('--file', function () {
beforeEach(function () {
it('should run tests passed via file first', function (done) {
args = ['--file', resolvePath('options/file-alpha.fixture.js')];
});

it('should run tests passed via file first', function (done) {
run('options/file-beta.fixture.js', args, function (err, res) {
if (err) {
done(err);
Expand All @@ -114,6 +112,32 @@ describe('options', function () {
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 () {
Expand Down

0 comments on commit 0008924

Please sign in to comment.