Skip to content

Commit

Permalink
[Tests] improve version detection tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 17, 2019
1 parent 2dd2277 commit c7e5f38
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -38,6 +38,7 @@
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"sinon": "^7.2.2",
"typescript": "^3.2.2",
"typescript-eslint-parser": "^20.1.1"
},
Expand Down
40 changes: 40 additions & 0 deletions tests/util/version.js
Expand Up @@ -3,19 +3,27 @@

const path = require('path');
const assert = require('assert');
const sinon = require('sinon');
const versionUtil = require('../../lib/util/version');

describe('Version', () => {
const base = path.resolve(__dirname, '..', 'fixtures', 'version');
let cwd;
let expectedErrorArgs = [];

beforeEach(() => {
cwd = process.cwd();
process.chdir(base);
sinon.stub(console, 'error');
expectedErrorArgs = [];
});

afterEach(() => {
process.chdir(cwd);

const actualArgs = console.error.args; // eslint-disable-line no-console
console.error.restore(); // eslint-disable-line no-console
assert.deepEqual(actualArgs, expectedErrorArgs);
});

describe('Detect version', () => {
Expand All @@ -29,6 +37,26 @@ describe('Version', () => {

it('assumes latest version if react is not installed', () => {
assert.equal(versionUtil.testReactVersion(context, '999.999.999'), true);

expectedErrorArgs = [
['Warning: React version was set to "detect" in eslint-plugin-react settings, but the "react" package is not installed. Assuming latest React version for linting.']
];
});
});

describe('string version', () => {
const context = {settings: {react: {version: '15.0', flowVersion: '1.2'}}};

it('works with react', () => {
assert.equal(versionUtil.testReactVersion(context, '0.14.0'), true);
assert.equal(versionUtil.testReactVersion(context, '15.0.0'), true);
assert.equal(versionUtil.testReactVersion(context, '16.0.0'), false);
});

it('works with flow', () => {
assert.equal(versionUtil.testFlowVersion(context, '1.1.0'), true);
assert.equal(versionUtil.testFlowVersion(context, '1.2.0'), true);
assert.equal(versionUtil.testFlowVersion(context, '1.3.0'), false);
});
});

Expand All @@ -39,12 +67,24 @@ describe('Version', () => {
assert.equal(versionUtil.testReactVersion(context, '0.14.0'), true);
assert.equal(versionUtil.testReactVersion(context, '15.0.0'), true);
assert.equal(versionUtil.testReactVersion(context, '16.0.0'), false);

expectedErrorArgs = [
['Warning: React version specified in eslint-plugin-react-settings must be a string; got “number”'],
['Warning: React version specified in eslint-plugin-react-settings must be a string; got “number”'],
['Warning: React version specified in eslint-plugin-react-settings must be a string; got “number”']
];
});

it('works with flow', () => {
assert.equal(versionUtil.testFlowVersion(context, '1.1.0'), true);
assert.equal(versionUtil.testFlowVersion(context, '1.2.0'), true);
assert.equal(versionUtil.testFlowVersion(context, '1.3.0'), false);

expectedErrorArgs = [
['Warning: Flow version specified in eslint-plugin-react-settings must be a string; got “number”'],
['Warning: Flow version specified in eslint-plugin-react-settings must be a string; got “number”'],
['Warning: Flow version specified in eslint-plugin-react-settings must be a string; got “number”']
];
});
});
});

0 comments on commit c7e5f38

Please sign in to comment.