| 1 | import rule from "../../lib/rules/plugin-name.cjs"; |
| 2 | import RuleTester from "../../../babel-eslint-shared-fixtures/utils/RuleTester.js"; |
| 3 | |
| 4 | const missingPluginError = "This file does not export a Babel plugin."; |
| 5 | const missingNameError = "This Babel plugin doesn't have a 'name' property."; |
| 6 | |
| 7 | const ruleTester = new RuleTester(); |
| 8 | |
| 9 | ruleTester.run("plugin-name", rule, { |
| 10 | valid: [ |
| 11 | `export default function () { return { name: "test-plugin" } }`, |
| 12 | `import { declare } from "@babel/helper-plugin-utils"; declare(() => { return { name: "test-plugin" } })`, |
| 13 | `import { declare } from "@babel/helper-plugin-utils"; declare(() => ({ name: "test-plugin" }))`, |
| 14 | `module.exports = function () { return { name: "foo" }; }`, |
| 15 | ], |
| 16 | invalid: [ |
| 17 | { |
| 18 | code: `function fn() { return { name: "foo" } }`, |
| 19 | errors: [missingPluginError], |
| 20 | }, |
| 21 | { |
| 22 | code: `export function fn() { return { name: "foo" } }`, |
| 23 | errors: [missingPluginError], |
| 24 | }, |
| 25 | { |
| 26 | code: `(function fn() { return { name: "foo" } })`, |
| 27 | errors: [missingPluginError], |
| 28 | }, |
| 29 | { |
| 30 | code: `() => { return { name: "foo" } }`, |
| 31 | errors: [missingPluginError], |
| 32 | }, |
| 33 | { |
| 34 | code: `export default function fn() {}`, |
| 35 | errors: [missingPluginError], |
| 36 | }, |
| 37 | { |
| 38 | code: `export default function fn() { return {} }`, |
| 39 | errors: [missingNameError], |
| 40 | }, |
| 41 | { |
| 42 | code: `import { declare } from "@babel/helper-plugin-utils"; declare(() => ({}))`, |
| 43 | errors: [missingNameError], |
| 44 | }, |
| 45 | { |
| 46 | code: `module.exports = function () { return {} }`, |
| 47 | errors: [missingNameError], |
| 48 | }, |
| 49 | ], |
| 50 | }); |