Skip to content
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

Merged
merged 2 commits into from May 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 62 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -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';"), { 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 @@ -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"), { 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