Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
test: add integration tests with built-in configs (#15612)
* test: add integration tests with built-in configs

* clarify test

* fix comment
  • Loading branch information
mdjermanovic committed Feb 18, 2022
1 parent 3023991 commit bfaa548
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/lib/cli-engine/file-enumerator.js
Expand Up @@ -550,7 +550,7 @@ describe("FileEnumerator", () => {
const files = {
"file.js": "",
".eslintrc.json": JSON.stringify({
extends: ["eslint:recommended"]
extends: ["eslint:recommended", "eslint:all"]
})
};
const { prepare, cleanup, getPath } = createCustomTeardown({ cwd: root, files });
Expand Down
49 changes: 49 additions & 0 deletions tests/lib/eslint/eslint.js
Expand Up @@ -413,6 +413,55 @@ describe("ESLint", () => {
]);
});

it("should use eslint:recommended rules when eslint:recommended configuration is specified", async () => {
eslint = new ESLint({
useEslintrc: false,
overrideConfig: {
extends: ["eslint:recommended"]
},
ignore: false,
cwd: getFixturePath()
});
const options = { filePath: "file.js" };
const results = await eslint.lintText("foo ()", options);

assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].messages.length, 1);
assert.strictEqual(results[0].messages[0].ruleId, "no-undef");
assert.strictEqual(results[0].messages[0].severity, 2);
});

it("should use eslint:all rules when eslint:all configuration is specified", async () => {
eslint = new ESLint({
useEslintrc: false,
overrideConfig: {
extends: ["eslint:all"]
},
ignore: false,
cwd: getFixturePath()
});
const options = { filePath: "file.js" };
const results = await eslint.lintText("foo ()", options);

assert.strictEqual(results.length, 1);

const { messages } = results[0];

// Some rules that should report errors in the given code. Not all, as we don't want to update this test when we add new rules.
const expectedRules = ["no-undef", "semi", "func-call-spacing"];

expectedRules.forEach(ruleId => {
const messageFromRule = messages.find(message => message.ruleId === ruleId);

assert.ok(
typeof messageFromRule === "object" && messageFromRule !== null, // LintMessage object
`Expected a message from rule '${ruleId}'`
);
assert.strictEqual(messageFromRule.severity, 2);
});

});

it("correctly autofixes semicolon-conflicting-fixes", async () => {
eslint = new ESLint({
cwd: path.join(fixtureDir, ".."),
Expand Down

0 comments on commit bfaa548

Please sign in to comment.