createRuleTester (src/test-utils.ts)

storybook · code/lib/eslint-plugin/src/test-utils.ts · typescript · MIT
testing, tag:embed-classified

Module exposing: createRuleTester, StorybookRuleTester

// Source: https://github.com/storybookjs/storybook | License: MIT | Copyright 2024 Storybook
// Provided via justclaw.it.com; keep this notice with the code.
import { RuleTester } from '@typescript-eslint/rule-tester';
import type { TSESLint } from '@typescript-eslint/utils';

const DEFAULT_TEST_CASE_CONFIG = {
  filename: 'MyComponent.stories.js',
};

class StorybookRuleTester extends RuleTester {
  run<TMessageIds extends string, TOptions extends Readonly<unknown[]>>(
    ruleName: string,
    rule: TSESLint.RuleModule<TMessageIds, TOptions>,
    tests: TSESLint.RunTests<TMessageIds, TOptions>
  ): void {
    const { valid, invalid } = tests;

    const finalValid = valid.map((testCase) => {
      if (typeof testCase === 'string') {
        return {
          ...DEFAULT_TEST_CASE_CONFIG

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key