Skip to content

Commit

Permalink
test: Add FlatESLint tests with missing config files (#17164)
Browse files Browse the repository at this point in the history
* test: Add `FlatESLint` tests with missing config files

* assert ENOENT
  • Loading branch information
mdjermanovic committed May 29, 2023
1 parent e5182b7 commit f67d298
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -682,6 +682,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';"), { code: "ENOENT" });
});

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);
Expand Down Expand Up @@ -797,6 +828,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"), { code: "ENOENT" });
});

it("should throw an error when given a config file and a valid file and invalid parser", async () => {
eslint = new FlatESLint({
overrideConfig: {
Expand Down

0 comments on commit f67d298

Please sign in to comment.