Home / File/ validator.test.ts — ui Source File

validator.test.ts — ui Source File

Architecture documentation for validator.test.ts, a typescript file in the ui codebase. 4 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  24f1b389_7a1f_e26c_433e_10dcc3d90045["validator.test.ts"]
  3c64fff0_e1b3_c39a_cce5_e39b74640768["validator.ts"]
  24f1b389_7a1f_e26c_433e_10dcc3d90045 --> 3c64fff0_e1b3_c39a_cce5_e39b74640768
  a1f86d2b_01c0_d57e_752c_db36b3a82dd0["extractEnvVarsFromRegistryConfig"]
  24f1b389_7a1f_e26c_433e_10dcc3d90045 --> a1f86d2b_01c0_d57e_752c_db36b3a82dd0
  4de38897_d4d5_9a91_2e53_093142ba5dff["validateRegistryConfig"]
  24f1b389_7a1f_e26c_433e_10dcc3d90045 --> 4de38897_d4d5_9a91_2e53_093142ba5dff
  c8d55bee_7008_1e1f_317b_8dc47b31b6a8["vitest"]
  24f1b389_7a1f_e26c_433e_10dcc3d90045 --> c8d55bee_7008_1e1f_317b_8dc47b31b6a8
  style 24f1b389_7a1f_e26c_433e_10dcc3d90045 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/* eslint-disable turbo/no-undeclared-env-vars */
import { afterEach, beforeEach, describe, expect, it } from "vitest"

import {
  extractEnvVarsFromRegistryConfig,
  validateRegistryConfig,
} from "./validator"

describe("extractEnvVarsFromRegistryConfig", () => {
  it("should extract vars from string config", () => {
    expect(
      extractEnvVarsFromRegistryConfig("https://api.com?token=${TOKEN}")
    ).toEqual(["TOKEN"])
  })

  it("should extract vars from object config", () => {
    const config = {
      url: "https://api.com/{name}?key=${API_KEY}",
      params: {
        version: "1.0",
        token: "${TOKEN}",
      },
      headers: {
        Authorization: "Bearer ${AUTH_TOKEN}",
        "X-Api-Key": "${API_KEY}",
      },
    }

    expect(extractEnvVarsFromRegistryConfig(config).sort()).toEqual([
      "API_KEY",
      "AUTH_TOKEN",
      "TOKEN",
    ])
  })

  it("should handle config without params or headers", () => {
    const config = {
      url: "https://api.com/{name}",
    }

    expect(extractEnvVarsFromRegistryConfig(config)).toEqual([])
  })
})

describe("validateRegistryConfig", () => {
  beforeEach(() => {
    process.env.TOKEN = "value"
  })

  afterEach(() => {
    delete process.env.TOKEN
  })

  describe("built-in registries", () => {
    it("should not throw for @shadcn since it's now a built-in registry", () => {
      expect(() => {
        validateRegistryConfig("@shadcn", {
          url: "https://example.com/{name}",
        })
      }).not.toThrow()
    })

    it("should not throw for non-built-in registry names", () => {
      expect(() => {
        validateRegistryConfig("@mycompany", {
          url: "https://example.com/{name}",
        })
      }).not.toThrow()
    })

    it("should not throw for similar but different registry names", () => {
      expect(() => {
        validateRegistryConfig("@shadcn-ui", {
          url: "https://example.com/{name}",
        })
      }).not.toThrow()

      expect(() => {
        validateRegistryConfig("@myshadcn", {
          url: "https://example.com/{name}",
        })
      }).not.toThrow()
    })
  })

  it("should pass when all env vars are set", () => {
    expect(() => {
      validateRegistryConfig("@test", "https://api.com?token=${TOKEN}")
    }).not.toThrow()
  })

  it("should throw when env vars are missing", () => {
    expect(() => {
      validateRegistryConfig("@test", "https://api.com?token=${MISSING}")
    }).toThrow(/Registry "@test" requires the following environment variables/)
  })

  it("should list all missing variables", () => {
    const config = {
      url: "https://api.com/{name}",
      headers: {
        Auth: "${TOKEN1}",
        Key: "${TOKEN2}",
      },
    }

    expect(() => {
      validateRegistryConfig("@test", config)
    }).toThrow(/TOKEN1[\s\S]*TOKEN2/)
  })
})

Frequently Asked Questions

What does validator.test.ts do?
validator.test.ts is a source file in the ui codebase, written in typescript. It belongs to the FrameworkTooling domain.
What does validator.test.ts depend on?
validator.test.ts imports 4 module(s): extractEnvVarsFromRegistryConfig, validateRegistryConfig, validator.ts, vitest.
Where is validator.test.ts in the architecture?
validator.test.ts is located at packages/shadcn/src/registry/validator.test.ts (domain: FrameworkTooling, directory: packages/shadcn/src/registry).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free