New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Centralize @babel/eslint-* tests #11106
Merged
kaicataldo
merged 3 commits into
babel:master
from
kaicataldo:centralize-babel-eslint-tests
Feb 8, 2020
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,4 @@ | ||
import eslint from "eslint"; | ||
import path from "path"; | ||
import unpad from "dedent"; | ||
import * as parser from "../src"; | ||
|
||
function verifyAndAssertMessagesWithSpecificESLint( | ||
code, | ||
rules, | ||
expectedMessages, | ||
sourceType, | ||
overrideConfig, | ||
linter, | ||
) { | ||
const config = { | ||
parser: "current-babel-eslint", | ||
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, | ||
}, | ||
}; | ||
|
||
const messages = linter.verify(code, config); | ||
|
||
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 formatedMessage = `${message.line}:${message.column} ${ | ||
message.message | ||
}${message.ruleId ? ` ${message.ruleId}` : ""}`; | ||
if (formatedMessage !== expectedMessages[i]) { | ||
throw new Error( | ||
` | ||
Message ${i} does not match: | ||
Expected: ${expectedMessages[i]} | ||
Actual: ${formatedMessage} | ||
`, | ||
); | ||
} | ||
}); | ||
} | ||
|
||
function verifyAndAssertMessages( | ||
code, | ||
rules, | ||
expectedMessages, | ||
sourceType, | ||
overrideConfig, | ||
) { | ||
const linter = new eslint.Linter(); | ||
linter.defineParser("current-babel-eslint", parser); | ||
|
||
verifyAndAssertMessagesWithSpecificESLint( | ||
unpad(`${code}`), | ||
rules || {}, | ||
expectedMessages || [], | ||
sourceType, | ||
overrideConfig, | ||
linter, | ||
); | ||
} | ||
import verifyAndAssertMessages from "../../helpers/verifyAndAssertMessages"; | ||
|
||
describe("verify", () => { | ||
it("arrow function support (issue #1)", () => { | ||
|
@@ -90,9 +13,9 @@ describe("verify", () => { | |
); | ||
}); | ||
|
||
xit("Readable error messages (issue #3)", () => { | ||
it("Readable error messages (issue #3)", () => { | ||
verifyAndAssertMessages("{ , res }", {}, [ | ||
"1:3 Parsing error: Unexpected token", | ||
/1:2 Parsing error:.*Unexpected token \(1:2\)/, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error reports an absolute file path, which is why I'm assuming it was disabled. With |
||
]); | ||
}); | ||
|
||
|
@@ -150,6 +73,7 @@ describe("verify", () => { | |
{ strict: [1, "global"] }, | ||
[], | ||
"script", | ||
{ sourceType: "script" }, | ||
); | ||
}); | ||
|
||
|
@@ -1154,7 +1078,6 @@ describe("verify", () => { | |
) { | ||
const overrideConfig = { | ||
parserOptions: { | ||
sourceType, | ||
babelOptions: { | ||
configFile: require.resolve( | ||
"@babel/eslint-shared-fixtures/config/babel.config.decorators-legacy.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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the ability to pass this function a
RegExp
so we can enable thexit
ed test below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use
jest
's methods instead of writing our own errors checking logic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be great. Mind if we do that in a follow up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok!