Skip to content
This repository has been archived by the owner on Feb 2, 2020. It is now read-only.

Commit

Permalink
Merge e90bf88 into 990ff70
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Apr 8, 2017
2 parents 990ff70 + e90bf88 commit 1fa9806
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 37 deletions.
14 changes: 9 additions & 5 deletions bin/eslint-mocha.js
Expand Up @@ -50,9 +50,13 @@ var mochaFiles = mochaArgs._;
var mochaCompilers = words(mochaArgs.compilers, /[^,]+/g);

eslintMocha({
eslintFiles: eslintFiles,
mochaFiles: mochaFiles,
isEslintDebug: eslintArgs.debug,
isMochaRecursive: mochaArgs.recursive,
mochaCompilers: mochaCompilers
eslint: {
files: eslintFiles,
isDebug: eslintArgs.debug
},
mocha: {
files: mochaFiles,
isRecursive: mochaArgs.recursive,
compilers: mochaCompilers
}
});
6 changes: 3 additions & 3 deletions lib/eslint-mocha.js
@@ -1,8 +1,8 @@
import initEslint from './eslint/initialize';
import runMocha from './mocha/run';

export default options => {
let lintTestFile = initEslint(options);
export default ({ eslint, mocha }) => {
let lintTestFile = initEslint(eslint);

runMocha(lintTestFile, options);
runMocha(lintTestFile, mocha);
};
14 changes: 6 additions & 8 deletions lib/eslint/initialize.js
@@ -1,16 +1,14 @@
import path from 'path';

export default options => {
let {
eslintFiles,
isEslintDebug
} = options;

if (isEslintDebug) {
export default ({
files,
isDebug
}) => {
if (isDebug) {
process.env.NPM_PACKAGE_CONFIG_ESLINT_DEBUG = 'eslint:*,-eslint:code-path';
}

process.env.NPM_PACKAGE_CONFIG_ESLINT_FILES = eslintFiles.join(',');
process.env.NPM_PACKAGE_CONFIG_ESLINT_FILES = files.join(',');

let testFile = path.resolve(__dirname, '../../assets/test-file.js');

Expand Down
15 changes: 7 additions & 8 deletions lib/mocha/run.js
Expand Up @@ -2,17 +2,16 @@ import Mocha from 'mocha';
import addCompilers from './add-compilers';
import addFiles from './add-files';

export default (lintTestFile, options) => {
let {
mochaFiles,
isMochaRecursive,
mochaCompilers
} = options;
export default (lintTestFile, {
files,
isRecursive,
compilers
}) => {
let extensions = ['js'];
let mocha = new Mocha();

addCompilers(mochaCompilers, extensions);
addFiles(mocha, mochaFiles, extensions, isMochaRecursive, lintTestFile);
addCompilers(compilers, extensions);
addFiles(mocha, files, extensions, isRecursive, lintTestFile);

mocha.run(process.exit);
};
41 changes: 37 additions & 4 deletions test/unit/eslint-mocha-test.js
Expand Up @@ -17,13 +17,15 @@ describe('unit - eslint-mocha', function() {

it('calls initEslint correctly', function() {
eslintMocha({
'test-prop': 'test-val'
eslint: {
testProp: 'test-val'
}
});

expect(initEslint.args).to.deep.equal([
[
{
'test-prop': 'test-val'
testProp: 'test-val'
}
]
]);
Expand All @@ -33,16 +35,47 @@ describe('unit - eslint-mocha', function() {
initEslint.returns('test-lint-file');

eslintMocha({
'test-prop': 'test-val'
mocha: {
testProp: 'test-val'
}
});

expect(runMocha.args).to.deep.equal([
[
'test-lint-file',
{
'test-prop': 'test-val'
testProp: 'test-val'
}
]
]);
});

it('doesn\'t call initEslint with mocha options', function() {
eslintMocha({
mocha: {
testProp: 'test-val'
}
});

expect(initEslint.args).to.deep.equal([
[
undefined
]
]);
});

it('doesn\'t call runMocha with eslint options', function() {
eslintMocha({
eslint: {
testProp: 'test-val'
}
});

expect(runMocha.args).to.deep.equal([
[
undefined,
undefined
]
]);
});
});
10 changes: 5 additions & 5 deletions test/unit/eslint/initialize-test.js
Expand Up @@ -31,24 +31,24 @@ describe('unit - eslint/initialize', function() {

it('sets files env variable', function() {
initialize({
eslintFiles: ['test-file-1', 'test-file-2']
files: ['test-file-1', 'test-file-2']
});

expect(process.env.NPM_PACKAGE_CONFIG_ESLINT_FILES).to.equal('test-file-1,test-file-2');
});

it('doesn\'t set debug env variable', function() {
initialize({
eslintFiles: []
files: []
});

expect(process.env.NPM_PACKAGE_CONFIG_ESLINT_DEBUG).to.equal('');
});

it('sets debug env variable', function() {
initialize({
eslintFiles: [],
isEslintDebug: true
files: [],
isDebug: true
});

expect(process.env.NPM_PACKAGE_CONFIG_ESLINT_DEBUG).to.equal('eslint:*,-eslint:code-path');
Expand All @@ -58,7 +58,7 @@ describe('unit - eslint/initialize', function() {
resolve.returns('resolved-test-path');

let testFile = initialize({
eslintFiles: []
files: []
});

expect(resolve.args).to.deep.equal([
Expand Down
8 changes: 4 additions & 4 deletions test/unit/mocha/run-test.js
Expand Up @@ -21,7 +21,7 @@ describe('unit - mocha/run', function() {

it('calls addCompilers correctly', function() {
run(null, {
mochaCompilers: ['test-compilers']
compilers: ['test-compilers']
});

expect(addCompilers.args).to.deep.equal([
Expand All @@ -30,7 +30,7 @@ describe('unit - mocha/run', function() {
});

it('calls addFiles correctly', function() {
run.__Rewire__('addCompilers', (mochaCompilers, extensions) => {
run.__Rewire__('addCompilers', (compilers, extensions) => {
extensions.pop();
extensions.push('test-ext');
});
Expand All @@ -40,8 +40,8 @@ describe('unit - mocha/run', function() {
run.__Rewire__('Mocha', Mocha);

run('lint-test-file', {
mochaFiles: ['mocha-file-test'],
isMochaRecursive: true
files: ['mocha-file-test'],
isRecursive: true
});

expect(addFiles.callCount).to.equal(1);
Expand Down

0 comments on commit 1fa9806

Please sign in to comment.