KC's Workspace
    Preparing search index...

    Interface TestArtifactRegistryExperimental

    Registry for custom test artifact types.

    Augment this interface to register custom artifact types that your tests can produce.

    Each custom artifact should extend TestArtifactBase and include a unique type discriminator property.

    • Use a Symbol as the registry key to guarantee uniqueness
    • The type property should follow the pattern 'package-name:artifact-name', 'internal:' is a reserved prefix
    • Use attachments to include files or data; extend TestAttachment for custom metadata
    • location property is automatically injected to indicate where the artifact was created
    // Define custom attachment type for generated PDF
    interface PDFAttachment extends TestAttachment {
    contentType: 'application/pdf'
    body: Uint8Array
    pageCount: number
    fileSize: number
    }

    interface PDFGenerationArtifact extends TestArtifactBase {
    type: 'my-plugin:pdf-generation'
    templateName: string
    isValid: boolean
    attachments: [PDFAttachment]
    }

    // Use a symbol to guarantee key uniqueness
    const pdfKey = Symbol('pdf-generation')

    declare module 'vitest' {
    interface TestArtifactRegistry {
    [pdfKey]: PDFGenerationArtifact
    }
    }

    // Custom assertion for PDF generation
    async function toGenerateValidPDF(
    this: MatcherState,
    actual: PDFTemplate,
    data: Record<string, unknown>
    ): AsyncExpectationResult {
    const pdfBuffer = await actual.render(data)
    const validation = await validatePDF(pdfBuffer)

    await recordArtifact(this.task, {
    type: 'my-plugin:pdf-generation',
    templateName: actual.name,
    isValid: validation.success,
    attachments: [{
    contentType: 'application/pdf',
    body: pdfBuffer,
    pageCount: validation.pageCount,
    fileSize: pdfBuffer.byteLength
    }]
    })

    return {
    pass: validation.success,
    message: () => validation.success
    ? `Generated valid PDF with ${validation.pageCount} pages`
    : `Invalid PDF: ${validation.error}`
    }
    }