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
test: Add FlatESLint
tests with missing config files
#17164
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -648,6 +648,37 @@ describe("FlatESLint", () => { | |||||
); | ||||||
}); | ||||||
|
||||||
it("should throw if eslint.config.js file is not present", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath("..") | ||||||
}); | ||||||
await assert.rejects(() => eslint.lintText("var foo = 'bar';"), /Could not find config file/u); | ||||||
}); | ||||||
|
||||||
it("should not throw if eslint.config.js file is not present and overrideConfigFile is `true`", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath(".."), | ||||||
overrideConfigFile: true | ||||||
}); | ||||||
await eslint.lintText("var foo = 'bar';"); | ||||||
}); | ||||||
|
||||||
it("should not throw if eslint.config.js file is not present and overrideConfigFile is path to a config file", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath(".."), | ||||||
overrideConfigFile: "fixtures/configurations/quotes-error.js" | ||||||
}); | ||||||
await eslint.lintText("var foo = 'bar';"); | ||||||
}); | ||||||
|
||||||
it("should throw if overrideConfigFile is path to a file that doesn't exist", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath(""), | ||||||
overrideConfigFile: "does-not-exist.js" | ||||||
}); | ||||||
await assert.rejects(() => eslint.lintText("var foo = 'bar';")); | ||||||
}); | ||||||
|
||||||
it("should throw if non-string value is given to 'code' parameter", async () => { | ||||||
eslint = new FlatESLint(); | ||||||
await assert.rejects(() => eslint.lintText(100), /'code' must be a string/u); | ||||||
|
@@ -763,6 +794,37 @@ describe("FlatESLint", () => { | |||||
assert.strictEqual(results[0].suppressedMessages.length, 0); | ||||||
}); | ||||||
|
||||||
it("should throw if eslint.config.js file is not present", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath("..") | ||||||
}); | ||||||
await assert.rejects(() => eslint.lintFiles("fixtures/undef*.js"), /Could not find config file/u); | ||||||
}); | ||||||
|
||||||
it("should not throw if eslint.config.js file is not present and overrideConfigFile is `true`", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath(".."), | ||||||
overrideConfigFile: true | ||||||
}); | ||||||
await eslint.lintFiles("fixtures/undef*.js"); | ||||||
}); | ||||||
|
||||||
it("should not throw if eslint.config.js file is not present and overrideConfigFile is path to a config file", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath(".."), | ||||||
overrideConfigFile: "fixtures/configurations/quotes-error.js" | ||||||
}); | ||||||
await eslint.lintFiles("fixtures/undef*.js"); | ||||||
}); | ||||||
|
||||||
it("should throw if overrideConfigFile is path to a file that doesn't exist", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
cwd: getFixturePath(), | ||||||
overrideConfigFile: "does-not-exist.js" | ||||||
}); | ||||||
await assert.rejects(() => eslint.lintFiles("undef*.js")); | ||||||
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. Same, do we want to check the message?
Suggested change
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. I concur. We should check the error code and message when viable as any error can mask actual errors code (working or test). 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. Added |
||||||
}); | ||||||
|
||||||
it("should throw an error when given a config file and a valid file and invalid parser", async () => { | ||||||
eslint = new FlatESLint({ | ||||||
overrideConfig: { | ||||||
|
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.
Should we add the message check here too?
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.
This is a system error thrown by
fs.stat()
:Error: ENOENT: no such file or directory, stat 'path/to/temp/eslint/fixtures/does-not-exist.js'
.I wanted to avoid checking error messages that we don't generate.
Perhaps
/ENOENT/u
?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.
Maybe
{code: "ENOENT"}
? Looks more accurate to me. We can even add a checker function that asserts the code and uses a regex on the message property. (docs: https://nodejs.org/api/assert.html#assertrejectsasyncfn-error-message)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 anything that checks the expected error message is fine. I just want to make sure we are getting the error we're expecting. I'm agnostic as to the approach.
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
{ code: "ENOENT" }
, thanks for the suggestion!