33
44const path = require ( 'path' ) ;
55const assert = require ( 'assert' ) ;
6+ const sinon = require ( 'sinon' ) ;
67const versionUtil = require ( '../../lib/util/version' ) ;
78
89describe ( '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