import * as axe from "axe-core";
import { afterEach, expect } from "vitest";
expect.extend({
  async toBeAccessible(received, options = {}) {
    const { rules = {} } = options;
    const results = await axe.run(received, {
      rules: {
        // Disable color-contrast by default as it's often problematic in test environments
        "color-contrast": { enabled: false },
        ...rules
      }
    });
    const violations = results.violations;
    if (violations.length === 0) {
      return {
        pass: true,
        message: () => "Expected element to have accessibility violations"
      };
    }
    const formattedViolations = violations.map((violation) => {
      const nodes = violation.nodes.map((node) => `    - ${node.html}`).join("\n");
      return `  ${violation.id}: ${violation.description}
${nodes}`;
    }).join("\n\n");
    return {
      pass: false,
      message: () => `Expected element to be accessible, but found the following violations:

${formattedViolations}`
    };
  }
});
afterEach(() => {
  document.body.innerHTML = "";
});
