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

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Jan 9, 2016
1 parent fbb6d27 commit 6dfdde9
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/eslint/initialize.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path';

const testFile = path.resolve(__dirname, 'test-file.js');

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

process.env.NODE_ESLINT_FILES = eslintFiles.join(',');

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

return testFile;
}
42 changes: 42 additions & 0 deletions test/unit/eslint/initialize-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { expect } from 'chai';
import sinon from 'sinon';
import initialize from '../../../lib/eslint/initialize';

describe.only('unit - eslint/initialize', function() {
let env;

beforeEach(function() {
env = process.env.NODE_ESLINT_FILES;
process.env.NODE_ESLINT_FILES = '';

initialize.__Rewire__('path', {
resolve: sinon.stub()
});
});

afterEach(function() {
process.env.NODE_ESLINT_FILES = env;

initialize.__ResetDependency__('path');
});

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

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

it('returns test file path', function() {
initialize.__Rewire__('path', {
resolve: sinon.stub().returns('resolved-test-path')
});

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

expect(testFile).to.equal('resolved-test-path');
});
});
52 changes: 52 additions & 0 deletions test/unit/mocha/run-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect } from 'chai';
import sinon from 'sinon';
import Mocha from 'mocha';
import run from '../../../lib/mocha/run';

describe('unit - mocha/run', function() {
beforeEach(function() {
run.__Rewire__('addCompilers', sinon.stub());
run.__Rewire__('addFiles', sinon.stub());
});

afterEach(function() {
run.__ResetDependency__('addCompilers');
run.__ResetDependency__('addFiles');
});

it('calls addCompilers correctly', function() {
let addCompilers = sinon.stub();
run.__Rewire__('addCompilers', addCompilers);

run(null, {
mochaCompilers: ['test-compilers']
});

expect(addCompilers.args).to.deep.equal([
[['test-compilers'], ['js']]
]);
});

it('calls addFiles correctly', function() {
let addFiles = sinon.stub();
run.__Rewire__('addFiles', addFiles);

run.__Rewire__('addCompilers', (mochaCompilers, extensions) => {
extensions.pop();
extensions.push('test-ext');
});

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

expect(addFiles.callCount).to.equal(1);
let call = addFiles.getCall(0);
expect(call.args[0]).to.be.an.instanceof(Mocha);
expect(call.args[1]).to.deep.equal(['mocha-file-test']);
expect(call.args[2]).to.deep.equal(['test-ext']);
expect(call.args[3]).to.be.true;
expect(call.args[4]).to.equal('lint-test-file');
});
});

0 comments on commit 6dfdde9

Please sign in to comment.