11/**
22 * tests that require fully booting up ESLint
33 */
4+ import path from 'path'
5+
46import { expect } from 'chai'
57import { CLIEngine } from 'eslint'
8+ import eslintPkg from 'eslint/package.json'
9+ import semver from 'semver'
610
711describe ( 'CLI regression tests' , function ( ) {
812 describe ( 'issue #210' , function ( ) {
@@ -21,4 +25,55 @@ describe('CLI regression tests', function () {
2125 expect ( ( ) => cli . executeOnFiles ( [ './tests/files/issue210.js' ] ) ) . not . to . throw ( Error )
2226 } )
2327 } )
28+
29+ describe ( 'issue #1645' , function ( ) {
30+ let cli
31+ beforeEach ( function ( ) {
32+ if ( semver . satisfies ( eslintPkg . version , '< 6' ) ) {
33+ this . skip ( )
34+ } else {
35+ cli = new CLIEngine ( {
36+ useEslintrc : false ,
37+ configFile : './tests/files/just-json-files/.eslintrc.json' ,
38+ rulePaths : [ './src/rules' ] ,
39+ ignore : false ,
40+ } )
41+ }
42+ } )
43+
44+ it ( 'throws an error on invalid JSON' , function ( ) {
45+ const invalidJSON = './tests/files/just-json-files/invalid.json'
46+ const results = cli . executeOnFiles ( [ invalidJSON ] )
47+ expect ( results ) . to . eql ( {
48+ results : [
49+ {
50+ filePath : path . resolve ( invalidJSON ) ,
51+ messages : [
52+ {
53+ column : 2 ,
54+ endColumn : 3 ,
55+ endLine : 1 ,
56+ line : 1 ,
57+ message : 'Expected a JSON object, array or literal.' ,
58+ nodeType : results . results [ 0 ] . messages [ 0 ] . nodeType , // we don't care about this one
59+ ruleId : 'json/*' ,
60+ severity : 2 ,
61+ source : '\n' ,
62+ } ,
63+ ] ,
64+ errorCount : 1 ,
65+ warningCount : 0 ,
66+ fixableErrorCount : 0 ,
67+ fixableWarningCount : 0 ,
68+ source : ',\n' ,
69+ } ,
70+ ] ,
71+ errorCount : 1 ,
72+ warningCount : 0 ,
73+ fixableErrorCount : 0 ,
74+ fixableWarningCount : 0 ,
75+ usedDeprecatedRules : results . usedDeprecatedRules , // we don't care about this one
76+ } )
77+ } )
78+ } )
2479} )
0 commit comments