Skip to content

chore: add tests for a11y and example scripts#3250

Open
rivka-ungar wants to merge 3 commits intomasterfrom
vibe-mcp-add-tests-for-scripts-11227738642
Open

chore: add tests for a11y and example scripts#3250
rivka-ungar wants to merge 3 commits intomasterfrom
vibe-mcp-add-tests-for-scripts-11227738642

Conversation

@rivka-ungar
Copy link
Contributor

@rivka-ungar rivka-ungar commented Feb 9, 2026

User description

https://monday.monday.com/boards/3532714909/views/113184182/pulses/11227738642


PR Type

Tests, Enhancement


Description

  • Add comprehensive test suites for accessibility and code sample extraction scripts

  • Create Vitest configuration for running tests in Node environment

  • Refactor scripts to export functions for testability and conditional execution

  • Fix Babel import compatibility issues with default exports


Diagram Walkthrough

flowchart LR
  A["Test Files Created"] -->|test extract-accessibility| B["cleanUpAccessibilityContent"]
  A -->|test extract-code-samples| C["generateCodeForOneLiner"]
  D["Vitest Config"] -->|configures| A
  E["Script Refactoring"] -->|exports functions| B
  E -->|exports functions| C
  E -->|conditional execution| F["if process.argv check"]
  G["Babel Import Fix"] -->|handles default exports| C
Loading

File Walkthrough

Relevant files
Configuration changes
vitest.config.ts
Vitest configuration for Node environment                               

packages/mcp/vitest.config.ts

  • Created new Vitest configuration file for the MCP package
  • Configured test environment as Node with globals enabled
  • Set test file pattern to **/__tests__/**/*.test.js
  • Enabled automatic mock clearing between tests
+10/-0   
Tests
extract-accessibility.test.js
Test suite for accessibility content extraction                   

packages/mcp/scripts/tests/extract-accessibility.test.js

  • Added 162 lines of comprehensive test coverage for
    cleanUpAccessibilityContent function
  • Tests cover UsageGuidelines extraction with numbered formatting
  • Tests validate React fragment handling and code tag conversion to
    backticks
  • Integration test verifies markdown file generation from MDX files
+162/-0 
extract-code-samples.test.js
Test suite for code sample extraction                                       

packages/mcp/scripts/tests/extract-code-samples.test.js

  • Added 113 lines of test coverage for generateCodeForOneLiner function
  • Tests validate variable declaration parsing and JSX handling
  • Tests verify createComponentTemplate filtering behavior
  • Integration test confirms markdown generation from story files
+113/-0 
Enhancement
extract-accessibility.js
Refactor for testability and exports                                         

packages/mcp/scripts/extract-accessibility.js

  • Exported getMdxFiles, extractAccessibilityFromMdx,
    cleanUpAccessibilityContent, and run functions for testing
  • Moved directory creation logic inside run function for better
    testability
  • Added conditional execution check using process.argv[1] to allow
    module imports
  • Maintained all existing functionality while improving modularity
+11/-9   
extract-code-samples.js
Refactor for testability and Babel compatibility                 

packages/mcp/scripts/extract-code-samples.js

  • Exported getStoryFiles, generateCodeForOneLiner, extractMarkdown, and
    run functions
  • Fixed Babel import compatibility by handling default exports with
    fallback pattern
  • Moved directory creation and file retrieval into run function
  • Added conditional execution check using process.argv[1] for module
    imports
+24/-20 

@rivka-ungar rivka-ungar requested a review from a team as a code owner February 9, 2026 17:55
@qodo-free-for-open-source-projects
Copy link
Contributor

qodo-free-for-open-source-projects bot commented Feb 9, 2026

PR Reviewer Guide 🔍

(Review updated until commit 4aae4e2)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Flaky Tests

The integration test calls run() and asserts that at least one .md file exists in a real dist/generated/accessibility directory. This makes the test dependent on the local filesystem state and on the presence/shape of MDX files in docs, which can be flaky in CI or when run from different working directories. Consider isolating via a temp directory and/or mocking filesystem + input discovery so the test is deterministic and doesn’t leave artifacts behind.

describe("run - integration", () => {
  it("should generate accessibility markdown files from MDX files", () => {
    run();

    const outputFiles = fs.readdirSync(outputDir).filter(f => f.endsWith(".md"));
    expect(outputFiles.length).toBeGreaterThan(0);
  });
Flaky Tests

The integration test calls run() and checks for generated .md files under dist/generated. This introduces side effects and makes the test depend on existing Story files and write permissions. Prefer a temp output directory (passed into run/extractMarkdown) or mock fs/file discovery to keep tests hermetic.

describe("run - integration", () => {
  it("should generate markdown files from story files", () => {
    run();

    const outputFiles = fs.readdirSync(outputDir).filter(f => f.endsWith(".md"));
    expect(outputFiles.length).toBeGreaterThan(0);
  });
Possible Issue

run() creates outputDir with fs.mkdirSync(outputDir) but without { recursive: true }. If parent directories don’t exist (common in clean CI checkouts), this can throw. Consider using { recursive: true } (as done in the other script) to avoid runtime failures.

export function run() {
  if (!fs.existsSync(outputDir)) {
    fs.mkdirSync(outputDir);
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant