Skip to content

Commit

Permalink
Chore: initCLI test helper takes any CLIEngine options
Browse files Browse the repository at this point in the history
In the next commit, I'm going to need to pass in other options besides
`fix`.
  • Loading branch information
btmills committed Mar 30, 2021
1 parent 79be776 commit e0c8bce
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tests/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ const CLIEngine = require("eslint").CLIEngine;
const path = require("path");
const plugin = require("../..");

/**
* @typedef {import('eslint/lib/cli-engine/cli-engine').CLIEngineOptions} CLIEngineOptions
*/

/**
* Helper function which creates CLIEngine instance with enabled/disabled autofix feature.
* @param {string} fixtureConfigName ESLint JSON config fixture filename.
* @param {boolean} [isAutofixEnabled=false] Whether to enable autofix feature.
* @param {CLIEngineOptions} [options={}] Whether to enable autofix feature.
* @returns {CLIEngine} CLIEngine instance to execute in tests.
*/
function initCLI(fixtureConfigName, isAutofixEnabled) {
const fix = isAutofixEnabled || false;
function initCLI(fixtureConfigName, options = {}) {
const cli = new CLIEngine({
cwd: path.resolve(__dirname, "../fixtures/"),
fix,
ignore: false,
useEslintrc: false,
configFile: path.resolve(__dirname, "../fixtures/", fixtureConfigName)
configFile: path.resolve(__dirname, "../fixtures/", fixtureConfigName),
...options
});

cli.addPlugin("markdown", plugin);
Expand Down Expand Up @@ -282,7 +285,7 @@ describe("plugin", () => {
describe("should fix code", () => {

before(() => {
cli = initCLI("eslintrc.json", true);
cli = initCLI("eslintrc.json", { fix: true });
});

it("in the simplest case", () => {
Expand Down

0 comments on commit e0c8bce

Please sign in to comment.