Skip to content

Commit

Permalink
Outsource run test method
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Dec 15, 2024
1 parent 1cc1ba9 commit d9b3dd0
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions tests/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ const assert = require("chai").assert;
const plugin = require("../lib/index.js");
const { ESLint } = require("eslint");

describe("Integration tests", () => {
const eslint = new ESLint({
fix: true,
overrideConfigFile: "./tests/eslint.test.config.js",
overrideConfig: {
processor: plugin.processors.processorJs,
},
});
const eslint = new ESLint({
fix: true,
overrideConfigFile: "./tests/eslint.test.config.js",
overrideConfig: {
processor: plugin.processors.processorJs,
files: ["**/*.js"],
},
});

async function runTest(filename, expectedFilename) {
const testCode = fs.readFileSync(filename, "utf-8");
const result = await eslint.lintText(testCode, { filePath: filename });
const expectedCode = fs.readFileSync(expectedFilename, "utf-8");
assert.strictEqual(result[0].output, expectedCode);
}

describe("Integration tests (JS)", () => {
const mapFiles = [
"common",
"each-do",
Expand All @@ -22,13 +30,7 @@ describe("Integration tests", () => {
];
mapFiles.forEach((name) => {
it(`performs linting as we expect it on ${name}.js`, async () => {
const filename = `tests/fixtures/${name}.js`;
const testCode = fs.readFileSync(filename, "utf-8");

const result = await eslint.lintText(testCode, { filePath: filename });

const expectedCode = fs.readFileSync(`tests/fixtures/${name}.expected.js`, "utf-8");
assert.strictEqual(result[0].output, expectedCode);
await runTest(`tests/fixtures/${name}.js`, `tests/fixtures/${name}.expected.js`, eslint);
});
});
});

0 comments on commit d9b3dd0

Please sign in to comment.