Skip to content

Commit

Permalink
[Tests] add test case for import-js#1645
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 5, 2020
1 parent e1ed323 commit 206bd33
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintignore
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
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
@@ -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
@@ -0,0 +1 @@
,
49 changes: 49 additions & 0 deletions tests/src/cli.js
@@ -1,6 +1,8 @@
/**
* tests that require fully booting up ESLint
*/
import path from 'path'

import { expect } from 'chai'
import { CLIEngine } from 'eslint'

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

describe('issue #1645', function () {
let cli
beforeEach(function () {
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 206bd33

Please sign in to comment.