Skip to content

Commit f67d298

Browse files
authored
test: Add FlatESLint tests with missing config files (#17164)
* test: Add `FlatESLint` tests with missing config files * assert ENOENT
1 parent e5182b7 commit f67d298

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

tests/lib/eslint/flat-eslint.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,37 @@ describe("FlatESLint", () => {
682682
);
683683
});
684684

685+
it("should throw if eslint.config.js file is not present", async () => {
686+
eslint = new FlatESLint({
687+
cwd: getFixturePath("..")
688+
});
689+
await assert.rejects(() => eslint.lintText("var foo = 'bar';"), /Could not find config file/u);
690+
});
691+
692+
it("should not throw if eslint.config.js file is not present and overrideConfigFile is `true`", async () => {
693+
eslint = new FlatESLint({
694+
cwd: getFixturePath(".."),
695+
overrideConfigFile: true
696+
});
697+
await eslint.lintText("var foo = 'bar';");
698+
});
699+
700+
it("should not throw if eslint.config.js file is not present and overrideConfigFile is path to a config file", async () => {
701+
eslint = new FlatESLint({
702+
cwd: getFixturePath(".."),
703+
overrideConfigFile: "fixtures/configurations/quotes-error.js"
704+
});
705+
await eslint.lintText("var foo = 'bar';");
706+
});
707+
708+
it("should throw if overrideConfigFile is path to a file that doesn't exist", async () => {
709+
eslint = new FlatESLint({
710+
cwd: getFixturePath(""),
711+
overrideConfigFile: "does-not-exist.js"
712+
});
713+
await assert.rejects(() => eslint.lintText("var foo = 'bar';"), { code: "ENOENT" });
714+
});
715+
685716
it("should throw if non-string value is given to 'code' parameter", async () => {
686717
eslint = new FlatESLint();
687718
await assert.rejects(() => eslint.lintText(100), /'code' must be a string/u);
@@ -797,6 +828,37 @@ describe("FlatESLint", () => {
797828
assert.strictEqual(results[0].suppressedMessages.length, 0);
798829
});
799830

831+
it("should throw if eslint.config.js file is not present", async () => {
832+
eslint = new FlatESLint({
833+
cwd: getFixturePath("..")
834+
});
835+
await assert.rejects(() => eslint.lintFiles("fixtures/undef*.js"), /Could not find config file/u);
836+
});
837+
838+
it("should not throw if eslint.config.js file is not present and overrideConfigFile is `true`", async () => {
839+
eslint = new FlatESLint({
840+
cwd: getFixturePath(".."),
841+
overrideConfigFile: true
842+
});
843+
await eslint.lintFiles("fixtures/undef*.js");
844+
});
845+
846+
it("should not throw if eslint.config.js file is not present and overrideConfigFile is path to a config file", async () => {
847+
eslint = new FlatESLint({
848+
cwd: getFixturePath(".."),
849+
overrideConfigFile: "fixtures/configurations/quotes-error.js"
850+
});
851+
await eslint.lintFiles("fixtures/undef*.js");
852+
});
853+
854+
it("should throw if overrideConfigFile is path to a file that doesn't exist", async () => {
855+
eslint = new FlatESLint({
856+
cwd: getFixturePath(),
857+
overrideConfigFile: "does-not-exist.js"
858+
});
859+
await assert.rejects(() => eslint.lintFiles("undef*.js"), { code: "ENOENT" });
860+
});
861+
800862
it("should throw an error when given a config file and a valid file and invalid parser", async () => {
801863
eslint = new FlatESLint({
802864
overrideConfig: {

0 commit comments

Comments
 (0)