diff --git a/tests/eslint-rule-tester.js b/tests/eslint-rule-tester.js index e4379ba1..443d75b0 100644 --- a/tests/eslint-rule-tester.js +++ b/tests/eslint-rule-tester.js @@ -8,12 +8,17 @@ const { RuleTester } = require("eslint") const { FlatRuleTester } = require("eslint/use-at-your-own-risk") const globals = require("globals") const semverSatisfies = require("semver/functions/satisfies") +const os = require("os") // greater than or equal to ESLint v9 exports.gteEslintV9 = semverSatisfies(eslintVersion, ">=9", { includePrerelease: true, }) +const platform = os.platform() +exports.isCaseSensitiveFileSystem = + platform === "linux" || platform === "freebsd" || platform === "openbsd" + exports.FlatRuleTester = exports.gteEslintV9 ? RuleTester : FlatRuleTester // to support the `env:{ es6: true, node: true}` rule-tester (env has been away in flat config.) @@ -38,5 +43,19 @@ exports.RuleTester = function (config = defaultConfig) { ) const ruleTester = new exports.FlatRuleTester(config) + const $run = ruleTester.run.bind(ruleTester) + ruleTester.run = function (name, rule, tests) { + tests.valid = tests.valid.filter(shouldRun) + tests.invalid = tests.invalid.filter(shouldRun) + + $run(name, rule, tests) + } return ruleTester } + +// support skip in tests +function shouldRun(item) { + const skip = typeof item === "string" ? false : item.skip + delete item.skip + return skip === void 0 || skip === false +} diff --git a/tests/lib/rules/no-missing-import.js b/tests/lib/rules/no-missing-import.js index f2803b63..b4177d3f 100644 --- a/tests/lib/rules/no-missing-import.js +++ b/tests/lib/rules/no-missing-import.js @@ -6,7 +6,7 @@ const path = require("path") const { Linter } = require("eslint") -const { RuleTester } = require("#eslint-rule-tester") +const { RuleTester, isCaseSensitiveFileSystem } = require("#eslint-rule-tester") const rule = require("../../../lib/rules/no-missing-import") const DynamicImportSupported = (() => { @@ -427,6 +427,7 @@ ruleTester.run("no-missing-import", rule, { filename: fixture("test.js"), code: "import a from './A.js';", errors: cantResolve("./A.js"), + skip: !isCaseSensitiveFileSystem, }, { diff --git a/tests/lib/rules/no-missing-require.js b/tests/lib/rules/no-missing-require.js index c055217c..a59354e1 100644 --- a/tests/lib/rules/no-missing-require.js +++ b/tests/lib/rules/no-missing-require.js @@ -5,7 +5,7 @@ "use strict" const path = require("path") -const RuleTester = require("#eslint-rule-tester").RuleTester +const { RuleTester, isCaseSensitiveFileSystem } = require("#eslint-rule-tester") const rule = require("../../../lib/rules/no-missing-require") const tsReactExtensionMap = [ @@ -396,6 +396,7 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("test.js"), code: "require('./A');", errors: cantResolve("./A"), + skip: !isCaseSensitiveFileSystem, }, // require.resolve