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 ca89d5e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
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 @@
,
50 changes: 50 additions & 0 deletions tests/src/cli.js
@@ -1,6 +1,9 @@
/**
* tests that require fully booting up ESLint
*/
import fs from 'fs'
import path from 'path'

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

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

const eslintConfig = JSON.parse(fs.readFileSync('./tests/files/just-json-files/.eslintrc.json'))
describe('issue #1645', function () {
let cli
beforeEach(function () {
cli = new CLIEngine({
useEslintrc: false,
configFile: './tests/files/just-json-files/.eslintrc.json',
rulePaths: ['./src/rules'],
})
})

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 ca89d5e

Please sign in to comment.