import { readdirSync } from 'fs' ; import { join } from 'path' ; import { Config , Variant } from './types' ; describe ( 'configs' , ( ) => { const configsPath = join ( __dirname , 'configs' ) ; const configFileNames = readdirSync ( configsPath ) ; describe . each ( configFileNames ) ( '%s' , ( configFileName ) => { const config = require ( `configs/${ configFileName }` ) . config ; describe . each ( Object . entries ( config ) ) ( 'property "%s"' , ( _ , variants ) => { const variantsByName = variants . map ( ( { name } , index ) => [ name , variants [ index ] , ] ) ; it . each ( variantsByName ) ( 'variant "%s" must use a unique Figma name' , ( _ , variant ) => { try { expect ( variant ) . toUseUniqueFigmaName ( config ) ; } catch ( error ) { error . stack = `at src/configs/${ configFileName }` ; throw error ; } } ) ; } ) ; } ) ; } ) ; expect . extend ( { toUseUniqueFigmaName ( variant , config ) { if ( this . isNot === true ) { throw new Error ( '.not is not supported' ) ; } const figmaName = variant . meta ?. figmaName ; if ( figmaName === undefined ) { return { message : ( ) => `variant ${ variant . name } has no Figma name` , pass : true , } ; } const variantsUsingFigmaName = [ ] ; for ( const [ property , variants ] of Object . entries ( config ) ) { for ( const variantForComparison of variants ) { if ( figmaName === variantForComparison . meta ?. figmaName ) { variantsUsingFigmaName . push ( { property , variant : variantForComparison , } ) ; } } } const variantsOutput = variantsUsingFigmaName . map ( ( { property , variant } ) => `- property "${ property }" variant "${ variant . name }"\n` + `${ JSON . stringify ( variant , null , 2 ) }` ) . join ( '\n' ) ; return { pass : variantsUsingFigmaName . length === 1 , message : ( ) => `${ this . utils . matcherHint ( 'toUseUniqueFigmaName' , 'variant' , 'config' ) }

Duplicate Figma name "${ figmaName }" found in variants:
${ variantsOutput }
` , } ; } , } ) ; declare global { namespace jest { interface Matchers < R > { toUseUniqueFigmaName ( config ) : R ; } } }