Skip to content

Commit

Permalink
[Tests] add test case for #1645
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 5, 2020
1 parent e1ed323 commit 0547c7e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ coverage
node_modules
tests/files/malformed.js
tests/files/with-syntax-error
tests/files/just-json-files/invalid.json
resolvers/webpack/test/files
# we want to ignore "tests/files" here, but unfortunately doing so would
# interfere with unit test and fail it for some reason.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"eslint-module-utils": "file:./utils",
"eslint-plugin-eslint-plugin": "^2.2.1",
"eslint-plugin-import": "2.x",
"eslint-plugin-json": "^2.1.1",
"fs-copy-file-sync": "^1.1.1",
"glob": "^7.1.6",
"in-publish": "^2.0.0",
Expand Down
22 changes: 22 additions & 0 deletions tests/files/just-json-files/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"root": true,

"plugins": ["import", "json"],

"rules": {
"import/no-unused-modules": [
"error",
{
"missingExports": false,
"unusedExports": true
}
]
},

"overrides": [
{
"files": "*.json",
"extends": "plugin:json/recommended"
}
]
}
1 change: 1 addition & 0 deletions tests/files/just-json-files/invalid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,
55 changes: 55 additions & 0 deletions tests/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/**
* tests that require fully booting up ESLint
*/
import path from 'path'

import { expect } from 'chai'
import { CLIEngine } from 'eslint'
import eslintPkg from 'eslint/package.json'
import semver from 'semver'

describe('CLI regression tests', function () {
describe('issue #210', function () {
Expand All @@ -21,4 +25,55 @@ describe('CLI regression tests', function () {
expect(() => cli.executeOnFiles(['./tests/files/issue210.js'])).not.to.throw(Error)
})
})

describe('issue #1645', function () {
let cli
beforeEach(function () {
if (semver.satisfies(eslintPkg.version, '< 6')) {
this.skip()
} else {
cli = new CLIEngine({
useEslintrc: false,
configFile: './tests/files/just-json-files/.eslintrc.json',
rulePaths: ['./src/rules'],
ignore: false,
})
}
})

it('throws an error on invalid JSON', function () {
const invalidJSON = './tests/files/just-json-files/invalid.json'
const results = cli.executeOnFiles([invalidJSON])
expect(results).to.eql({
results: [
{
filePath: path.resolve(invalidJSON),
messages: [
{
column: 2,
endColumn: 3,
endLine: 1,
line: 1,
message: 'Expected a JSON object, array or literal.',
nodeType: results.results[0].messages[0].nodeType, // we don't care about this one
ruleId: 'json/*',
severity: 2,
source: '\n',
},
],
errorCount: 1,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
source: ',\n',
},
],
errorCount: 1,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
usedDeprecatedRules: results.usedDeprecatedRules, // we don't care about this one
})
})
})
})

0 comments on commit 0547c7e

Please sign in to comment.