3
3
4
4
const path = require ( 'path' ) ;
5
5
const assert = require ( 'assert' ) ;
6
+ const sinon = require ( 'sinon' ) ;
6
7
const versionUtil = require ( '../../lib/util/version' ) ;
7
8
8
9
describe ( 'Version' , ( ) => {
9
10
const base = path . resolve ( __dirname , '..' , 'fixtures' , 'version' ) ;
10
11
let cwd ;
12
+ let expectedErrorArgs = [ ] ;
11
13
12
14
beforeEach ( ( ) => {
13
15
cwd = process . cwd ( ) ;
14
16
process . chdir ( base ) ;
17
+ sinon . stub ( console , 'error' ) ;
18
+ expectedErrorArgs = [ ] ;
15
19
} ) ;
16
20
17
21
afterEach ( ( ) => {
18
22
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 ) ;
19
27
} ) ;
20
28
21
29
describe ( 'Detect version' , ( ) => {
@@ -29,6 +37,26 @@ describe('Version', () => {
29
37
30
38
it ( 'assumes latest version if react is not installed' , ( ) => {
31
39
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 ) ;
32
60
} ) ;
33
61
} ) ;
34
62
@@ -39,12 +67,24 @@ describe('Version', () => {
39
67
assert . equal ( versionUtil . testReactVersion ( context , '0.14.0' ) , true ) ;
40
68
assert . equal ( versionUtil . testReactVersion ( context , '15.0.0' ) , true ) ;
41
69
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
+ ] ;
42
76
} ) ;
43
77
44
78
it ( 'works with flow' , ( ) => {
45
79
assert . equal ( versionUtil . testFlowVersion ( context , '1.1.0' ) , true ) ;
46
80
assert . equal ( versionUtil . testFlowVersion ( context , '1.2.0' ) , true ) ;
47
81
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
+ ] ;
48
88
} ) ;
49
89
} ) ;
50
90
} ) ;
0 commit comments