|
1 |
| -import { testBlock } from "bingo-stratum-testers"; |
2 |
| -import { describe, expect, test } from "vitest"; |
| 1 | +import { testBlock, testIntake } from "bingo-stratum-testers"; |
| 2 | +import { describe, expect, it, test } from "vitest"; |
3 | 3 |
|
4 | 4 | import { blockESLintPlugin } from "./blockESLintPlugin.js";
|
5 | 5 | import { optionsBase } from "./options.fakes.js";
|
6 | 6 |
|
7 | 7 | describe("blockESLintPlugin", () => {
|
8 |
| - test("without options or mode", () => { |
| 8 | + test("without addons, mode, or options", () => { |
9 | 9 | const creation = testBlock(blockESLintPlugin, {
|
10 | 10 | options: optionsBase,
|
11 | 11 | });
|
@@ -506,4 +506,276 @@ describe("blockESLintPlugin", () => {
|
506 | 506 | }
|
507 | 507 | `);
|
508 | 508 | });
|
| 509 | + |
| 510 | + test("addons", () => { |
| 511 | + const creation = testBlock(blockESLintPlugin, { |
| 512 | + addons: { |
| 513 | + configEmoji: [ |
| 514 | + ["recommended", "✅"], |
| 515 | + ["legacy-recommended", "✔️"], |
| 516 | + ], |
| 517 | + }, |
| 518 | + options: optionsBase, |
| 519 | + }); |
| 520 | + |
| 521 | + expect(creation).toMatchInlineSnapshot(` |
| 522 | + { |
| 523 | + "addons": [ |
| 524 | + { |
| 525 | + "addons": { |
| 526 | + "words": [ |
| 527 | + "eslint-doc-generatorrc", |
| 528 | + ], |
| 529 | + }, |
| 530 | + "block": [Function], |
| 531 | + }, |
| 532 | + { |
| 533 | + "addons": { |
| 534 | + "sections": { |
| 535 | + "Building": { |
| 536 | + "innerSections": [ |
| 537 | + { |
| 538 | + "contents": " |
| 539 | + Run [\`eslint-doc-generator\`](https://github.com/bmish/eslint-doc-generator) to generate Markdown files documenting rules. |
| 540 | +
|
| 541 | + \`\`\`shell |
| 542 | + pnpm build:docs |
| 543 | + \`\`\` |
| 544 | + ", |
| 545 | + "heading": "Building Docs", |
| 546 | + }, |
| 547 | + ], |
| 548 | + }, |
| 549 | + "Linting": { |
| 550 | + "contents": { |
| 551 | + "items": [ |
| 552 | + "- \`pnpm lint:docs\` ([eslint-doc-generator](https://github.com/bmish/eslint-doc-generator)): Generates and validates documentation for ESLint rules", |
| 553 | + ], |
| 554 | + }, |
| 555 | + }, |
| 556 | + }, |
| 557 | + }, |
| 558 | + "block": [Function], |
| 559 | + }, |
| 560 | + { |
| 561 | + "addons": { |
| 562 | + "extensions": [ |
| 563 | + "eslintPlugin.configs["flat/recommended"]", |
| 564 | + ], |
| 565 | + "ignores": [ |
| 566 | + ".eslint-doc-generatorrc.js", |
| 567 | + "docs/rules/*/*.ts", |
| 568 | + ], |
| 569 | + "imports": [ |
| 570 | + { |
| 571 | + "source": { |
| 572 | + "packageName": "eslint-plugin-eslint-plugin", |
| 573 | + "version": "6.4.0", |
| 574 | + }, |
| 575 | + "specifier": "eslintPlugin", |
| 576 | + }, |
| 577 | + ], |
| 578 | + }, |
| 579 | + "block": [Function], |
| 580 | + }, |
| 581 | + { |
| 582 | + "addons": { |
| 583 | + "jobs": [ |
| 584 | + { |
| 585 | + "name": "Lint Docs", |
| 586 | + "steps": [ |
| 587 | + { |
| 588 | + "run": "pnpm build || exit 0", |
| 589 | + }, |
| 590 | + { |
| 591 | + "run": "pnpm lint:docs", |
| 592 | + }, |
| 593 | + ], |
| 594 | + }, |
| 595 | + ], |
| 596 | + }, |
| 597 | + "block": [Function], |
| 598 | + }, |
| 599 | + { |
| 600 | + "addons": { |
| 601 | + "properties": { |
| 602 | + "devDependencies": { |
| 603 | + "eslint-doc-generator": "2.1.0", |
| 604 | + "eslint-plugin-eslint-plugin": "6.4.0", |
| 605 | + }, |
| 606 | + "scripts": { |
| 607 | + "build:docs": "pnpm build --no-dts && eslint-doc-generator", |
| 608 | + "lint:docs": "eslint-doc-generator --check", |
| 609 | + }, |
| 610 | + }, |
| 611 | + }, |
| 612 | + "block": [Function], |
| 613 | + }, |
| 614 | + { |
| 615 | + "addons": { |
| 616 | + "coverage": { |
| 617 | + "exclude": [ |
| 618 | + "src/index.ts", |
| 619 | + "src/rules/index.ts", |
| 620 | + ], |
| 621 | + }, |
| 622 | + }, |
| 623 | + "block": [Function], |
| 624 | + }, |
| 625 | + ], |
| 626 | + "files": { |
| 627 | + ".eslint-doc-generatorrc.js": "import prettier from "prettier"; |
| 628 | +
|
| 629 | + /** @type {import('eslint-doc-generator').GenerateOptions} */ |
| 630 | + const config = { |
| 631 | + configEmoji: [["recommended","✅"],["legacy-recommended","✔️"]], |
| 632 | + postprocess: async (content, path) => |
| 633 | + prettier.format(content, { |
| 634 | + ...(await prettier.resolveConfig(path)), |
| 635 | + parser: "markdown", |
| 636 | + }), |
| 637 | + ruleDocTitleFormat: "name", |
| 638 | + }; |
| 639 | +
|
| 640 | + export default config; |
| 641 | + ", |
| 642 | + }, |
| 643 | + } |
| 644 | + `); |
| 645 | + }); |
| 646 | + |
| 647 | + describe("intake", () => { |
| 648 | + it("returns nothing when .eslint-doc-generatorrc.js and .eslint-doc-generatorrc.mjs do not exist", () => { |
| 649 | + const actual = testIntake(blockESLintPlugin, { |
| 650 | + files: {}, |
| 651 | + options: optionsBase, |
| 652 | + }); |
| 653 | + |
| 654 | + expect(actual).toEqual(undefined); |
| 655 | + }); |
| 656 | + |
| 657 | + it("returns nothing when .eslint-doc-generatorrc.js does not have a to const config =", () => { |
| 658 | + const actual = testIntake(blockESLintPlugin, { |
| 659 | + files: { |
| 660 | + ".eslint-doc-generatorrc.js": [`const other = {};`], |
| 661 | + }, |
| 662 | + options: optionsBase, |
| 663 | + }); |
| 664 | + |
| 665 | + expect(actual).toEqual(undefined); |
| 666 | + }); |
| 667 | + |
| 668 | + it("returns nothing when .eslint-doc-generatorrc.js passes nothing to config =", () => { |
| 669 | + const actual = testIntake(blockESLintPlugin, { |
| 670 | + files: { |
| 671 | + ".eslint-doc-generatorrc.js": [`const config = {};`], |
| 672 | + }, |
| 673 | + options: optionsBase, |
| 674 | + }); |
| 675 | + |
| 676 | + expect(actual).toEqual(undefined); |
| 677 | + }); |
| 678 | + |
| 679 | + it("returns nothing when .eslint-doc-generatorrc.js passes invalid syntax to config =", () => { |
| 680 | + const actual = testIntake(blockESLintPlugin, { |
| 681 | + files: { |
| 682 | + ".eslint-doc-generatorrc.js": [`const config = { ! }`], |
| 683 | + }, |
| 684 | + options: optionsBase, |
| 685 | + }); |
| 686 | + |
| 687 | + expect(actual).toEqual(undefined); |
| 688 | + }); |
| 689 | + |
| 690 | + it("returns nothing when .eslint-doc-generatorrc.js passes unrelated properties to config =", () => { |
| 691 | + const actual = testIntake(blockESLintPlugin, { |
| 692 | + files: { |
| 693 | + ".eslint-doc-generatorrc.js": [`const config = { other: true }`], |
| 694 | + }, |
| 695 | + options: optionsBase, |
| 696 | + }); |
| 697 | + |
| 698 | + expect(actual).toEqual(undefined); |
| 699 | + }); |
| 700 | + |
| 701 | + it("returns configEmoji when it exists alone in .eslint-doc-generatorrc.js", () => { |
| 702 | + const actual = testIntake(blockESLintPlugin, { |
| 703 | + files: { |
| 704 | + ".eslint-doc-generatorrc.js": [ |
| 705 | + `const config = { configEmoji: [["recommended", "✅"]] }`, |
| 706 | + ], |
| 707 | + }, |
| 708 | + options: optionsBase, |
| 709 | + }); |
| 710 | + |
| 711 | + expect(actual).toEqual({ |
| 712 | + configEmoji: [["recommended", "✅"]], |
| 713 | + }); |
| 714 | + }); |
| 715 | + }); |
| 716 | + |
| 717 | + it("returns configEmoji when it exists alone in .eslint-doc-generatorrc.mjs", () => { |
| 718 | + const actual = testIntake(blockESLintPlugin, { |
| 719 | + files: { |
| 720 | + ".eslint-doc-generatorrc.mjs": [ |
| 721 | + `const config = { configEmoji: [["recommended", "✅"]] }`, |
| 722 | + ], |
| 723 | + }, |
| 724 | + options: optionsBase, |
| 725 | + }); |
| 726 | + |
| 727 | + expect(actual).toEqual({ |
| 728 | + configEmoji: [["recommended", "✅"]], |
| 729 | + }); |
| 730 | + }); |
| 731 | + |
| 732 | + it("returns configEmoji when it exists with other data in .eslint-doc-generatorrc.js", () => { |
| 733 | + const actual = testIntake(blockESLintPlugin, { |
| 734 | + files: { |
| 735 | + ".eslint-doc-generatorrc.js": [ |
| 736 | + `const config = { configEmoji: [["recommended", "✅"]], other: true }`, |
| 737 | + ], |
| 738 | + }, |
| 739 | + options: optionsBase, |
| 740 | + }); |
| 741 | + |
| 742 | + expect(actual).toEqual({ |
| 743 | + configEmoji: [["recommended", "✅"]], |
| 744 | + }); |
| 745 | + }); |
| 746 | + |
| 747 | + it("returns configEmoji when it exists with other, non-JSON5 data in a full .eslint-doc-generatorrc.js", () => { |
| 748 | + const actual = testIntake(blockESLintPlugin, { |
| 749 | + files: { |
| 750 | + ".eslint-doc-generatorrc.js": [ |
| 751 | + `import prettier from "prettier"; |
| 752 | +
|
| 753 | +/** @type {import('eslint-doc-generator').GenerateOptions} */ |
| 754 | +const config = { |
| 755 | + configEmoji: [ |
| 756 | + ["recommended", "✅"], |
| 757 | + ["legacy-recommended", "✔️"], |
| 758 | + ], |
| 759 | + postprocess: async (content, path) => |
| 760 | + prettier.format(content, { |
| 761 | + ...(await prettier.resolveConfig(path)), |
| 762 | + parser: "markdown", |
| 763 | + }), |
| 764 | + ruleDocTitleFormat: "name", |
| 765 | +}; |
| 766 | +
|
| 767 | +export default config; |
| 768 | +`, |
| 769 | + ], |
| 770 | + }, |
| 771 | + options: optionsBase, |
| 772 | + }); |
| 773 | + |
| 774 | + expect(actual).toEqual({ |
| 775 | + configEmoji: [ |
| 776 | + ["recommended", "✅"], |
| 777 | + ["legacy-recommended", "✔️"], |
| 778 | + ], |
| 779 | + }); |
| 780 | + }); |
509 | 781 | });
|
0 commit comments