forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize @babel/eslint-* tests (babel#11106)
* Centralize @babel/eslint-* tests * Enable linting of @babel/eslint-* test files * Add missing sourceType
- Loading branch information
1 parent
1599e90
commit 5aa368c
Showing
20 changed files
with
112 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
eslint/babel-eslint-parser/test/fixtures/rules/syntax-error.js
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@babel/eslint-tests", | ||
"version": "0.0.0", | ||
"description": "Tests for babel/eslint-* packages", | ||
"license": "MIT", | ||
"private": true, | ||
"devDependencies": { | ||
"@babel/eslint-parser": "*", | ||
"@babel/eslint-plugin": "*", | ||
"@babel/eslint-shared-fixtures": "*", | ||
"dedent": "^0.7.0", | ||
"eslint": "^6.0.0", | ||
"eslint-plugin-import": "^2.20.1" | ||
} | ||
} |
6 changes: 1 addition & 5 deletions
6
...xtures/eslint-plugin-import/.eslintrc.yml → ...xtures/eslint-plugin-import/.eslintrc.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
69 changes: 69 additions & 0 deletions
69
eslint/babel-eslint-tests/test/helpers/verifyAndAssertMessages.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import eslint from "eslint"; | ||
import unpad from "dedent"; | ||
import * as parser from "@babel/eslint-parser"; | ||
|
||
export default function verifyAndAssertMessages( | ||
code, | ||
rules = {}, | ||
expectedMessages = [], | ||
sourceType, | ||
overrideConfig, | ||
) { | ||
const linter = new eslint.Linter(); | ||
linter.defineParser("@babel/eslint-parser", parser); | ||
|
||
const messages = linter.verify(unpad(`${code}`), { | ||
parser: "@babel/eslint-parser", | ||
rules, | ||
env: { | ||
node: true, | ||
es6: true, | ||
}, | ||
...overrideConfig, | ||
parserOptions: { | ||
sourceType, | ||
requireConfigFile: false, | ||
babelOptions: { | ||
configFile: require.resolve( | ||
"@babel/eslint-shared-fixtures/config/babel.config.js", | ||
), | ||
}, | ||
...overrideConfig?.parserOptions, | ||
}, | ||
}); | ||
|
||
if (messages.length !== expectedMessages.length) { | ||
throw new Error( | ||
`Expected ${expectedMessages.length} message(s), got ${ | ||
messages.length | ||
}\n${JSON.stringify(messages, null, 2)}`, | ||
); | ||
} | ||
|
||
messages.forEach((message, i) => { | ||
const formattedMessage = `${message.line}:${message.column} ${ | ||
message.message | ||
}${message.ruleId ? ` ${message.ruleId}` : ""}`; | ||
const expectedMessage = expectedMessages[i]; | ||
|
||
if (expectedMessage instanceof RegExp) { | ||
if (!expectedMessage.test(formattedMessage)) { | ||
throw new Error( | ||
` | ||
Message ${i} does not pass RegExp test: | ||
Test: ${expectedMessage} | ||
Actual: ${formattedMessage} | ||
`, | ||
); | ||
} | ||
} else if (formattedMessage !== expectedMessage) { | ||
throw new Error( | ||
` | ||
Message ${i} does not match: | ||
Expected: ${expectedMessage} | ||
Actual: ${formattedMessage} | ||
`, | ||
); | ||
} | ||
}); | ||
} |
13 changes: 13 additions & 0 deletions
13
eslint/babel-eslint-tests/test/integration/eslint-plugin-import.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import eslint from "eslint"; | ||
import path from "path"; | ||
|
||
describe("https://github.com/babel/babel-eslint/issues/558", () => { | ||
it("doesn't crash with eslint-plugin-import", () => { | ||
const engine = new eslint.CLIEngine({ ignore: false }); | ||
engine.executeOnFiles( | ||
["a.js", "b.js", "c.js"].map(file => | ||
path.resolve(__dirname, `../fixtures/eslint-plugin-import/${file}`), | ||
), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters