Skip to content

Commit c7e5f38

Browse files
committed
[Tests] improve version detection tests.
See #2128
1 parent 2dd2277 commit c7e5f38

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"eslint": "^3.0.0 || ^4.0.0 || ^5.0.0",
3939
"istanbul": "^0.4.5",
4040
"mocha": "^5.2.0",
41+
"sinon": "^7.2.2",
4142
"typescript": "^3.2.2",
4243
"typescript-eslint-parser": "^20.1.1"
4344
},

tests/util/version.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33

44
const path = require('path');
55
const assert = require('assert');
6+
const sinon = require('sinon');
67
const versionUtil = require('../../lib/util/version');
78

89
describe('Version', () => {
910
const base = path.resolve(__dirname, '..', 'fixtures', 'version');
1011
let cwd;
12+
let expectedErrorArgs = [];
1113

1214
beforeEach(() => {
1315
cwd = process.cwd();
1416
process.chdir(base);
17+
sinon.stub(console, 'error');
18+
expectedErrorArgs = [];
1519
});
1620

1721
afterEach(() => {
1822
process.chdir(cwd);
23+
24+
const actualArgs = console.error.args; // eslint-disable-line no-console
25+
console.error.restore(); // eslint-disable-line no-console
26+
assert.deepEqual(actualArgs, expectedErrorArgs);
1927
});
2028

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

3038
it('assumes latest version if react is not installed', () => {
3139
assert.equal(versionUtil.testReactVersion(context, '999.999.999'), true);
40+
41+
expectedErrorArgs = [
42+
['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.']
43+
];
44+
});
45+
});
46+
47+
describe('string version', () => {
48+
const context = {settings: {react: {version: '15.0', flowVersion: '1.2'}}};
49+
50+
it('works with react', () => {
51+
assert.equal(versionUtil.testReactVersion(context, '0.14.0'), true);
52+
assert.equal(versionUtil.testReactVersion(context, '15.0.0'), true);
53+
assert.equal(versionUtil.testReactVersion(context, '16.0.0'), false);
54+
});
55+
56+
it('works with flow', () => {
57+
assert.equal(versionUtil.testFlowVersion(context, '1.1.0'), true);
58+
assert.equal(versionUtil.testFlowVersion(context, '1.2.0'), true);
59+
assert.equal(versionUtil.testFlowVersion(context, '1.3.0'), false);
3260
});
3361
});
3462

@@ -39,12 +67,24 @@ describe('Version', () => {
3967
assert.equal(versionUtil.testReactVersion(context, '0.14.0'), true);
4068
assert.equal(versionUtil.testReactVersion(context, '15.0.0'), true);
4169
assert.equal(versionUtil.testReactVersion(context, '16.0.0'), false);
70+
71+
expectedErrorArgs = [
72+
['Warning: React version specified in eslint-plugin-react-settings must be a string; got “number”'],
73+
['Warning: React version specified in eslint-plugin-react-settings must be a string; got “number”'],
74+
['Warning: React version specified in eslint-plugin-react-settings must be a string; got “number”']
75+
];
4276
});
4377

4478
it('works with flow', () => {
4579
assert.equal(versionUtil.testFlowVersion(context, '1.1.0'), true);
4680
assert.equal(versionUtil.testFlowVersion(context, '1.2.0'), true);
4781
assert.equal(versionUtil.testFlowVersion(context, '1.3.0'), false);
82+
83+
expectedErrorArgs = [
84+
['Warning: Flow version specified in eslint-plugin-react-settings must be a string; got “number”'],
85+
['Warning: Flow version specified in eslint-plugin-react-settings must be a string; got “number”'],
86+
['Warning: Flow version specified in eslint-plugin-react-settings must be a string; got “number”']
87+
];
4888
});
4989
});
5090
});

0 commit comments

Comments
 (0)