{"version":3,"file":"create_vis.mjs","names":[],"sources":["../../src/setup/create_vis.ts"],"sourcesContent":["import { afterEach, beforeAll, expect } from 'vitest'\nimport { setAutoSnapshotOptions } from '../auto_snapshots/auto_snapshot_options.ts'\nimport { autoSnapshotMatcher } from '../client/suite/auto_snapshot_matcher.ts'\nimport type { SetupVisSuiteCommand } from '../shared/commands.types.ts'\nimport type { SetupVisOptions } from '../shared/types.ts'\n\n/**\n * Visual test configuration on the client side.\n */\nexport type VisClientConfigurator<GM extends Record<string, any> | unknown = unknown> = {\n\t/**\n\t * Setup the visual test configuration.\n\t *\n\t * @example\n\t * ```ts\n\t * // Setup with auto snapshot enabled\n\t * vis().setup({ auto: true })\n\t *\n\t * // Setup with auto snapshot disabled\n\t * vis().setup({ auto: false })\n\t *\n\t * // Same as `vis.setup({ auto: false })`\n\t * vis.setup()\n\t *\n\t * // Setup with auto snapshot determined by the test meta\n\t * vis.setup({\n\t * \tauto: async ({ meta }) => meta['darkOnly'],\n\t * })\n\t *\n\t * // Setup with multiple auto snapshots\n\t * vis.setup({\n\t *   auto: {\n\t *     async light() { document.body.classList.remove('dark') },\n\t *     async dark() { document.body.classList.add('dark') },\n\t *   }\n\t * })\n\t * ```\n\t */\n\tsetup(options?: SetupVisOptions<GM>): void\n}\n\nexport function createVis<GM extends Record<string, any> | unknown = unknown>(commands: SetupVisSuiteCommand) {\n\tconst matcher = autoSnapshotMatcher(commands, expect)\n\n\tconst vis: VisClientConfigurator<GM> = {\n\t\tsetup(options) {\n\t\t\tconst suiteDefaults =\n\t\t\t\toptions?.createMissingBaseline !== undefined\n\t\t\t\t\t? { createMissingBaseline: options.createMissingBaseline }\n\t\t\t\t\t: undefined\n\n\t\t\tbeforeAll(async () => {\n\t\t\t\tawait matcher.setup()\n\t\t\t\tsetAutoSnapshotOptions(!!options?.auto)\n\t\t\t})\n\n\t\t\tif (typeof options?.auto === 'function') {\n\t\t\t\tafterEach(matcher.createMatcher({ auto: options.auto }, suiteDefaults))\n\t\t\t} else if (typeof options?.auto === 'object') {\n\t\t\t\tafterEach(matcher.createMatcher(options.auto, suiteDefaults))\n\t\t\t} else {\n\t\t\t\tafterEach(matcher.createMatcher({ async auto() {} }, suiteDefaults))\n\t\t\t}\n\t\t},\n\t}\n\treturn vis\n}\n"],"mappings":";;;;;AAyCA,SAAgB,UAA8D,UAAgC;CAC7G,MAAM,UAAU,oBAAoB,UAAU,OAAO;AAuBrD,QArBuC,EACtC,MAAM,SAAS;EACd,MAAM,gBACL,SAAS,0BAA0B,SAChC,EAAE,uBAAuB,QAAQ,uBAAuB,GACxD;AAEJ,YAAU,YAAY;AACrB,SAAM,QAAQ,OAAO;AACrB,0BAAuB,CAAC,CAAC,SAAS,KAAK;IACtC;AAEF,MAAI,OAAO,SAAS,SAAS,WAC5B,WAAU,QAAQ,cAAc,EAAE,MAAM,QAAQ,MAAM,EAAE,cAAc,CAAC;WAC7D,OAAO,SAAS,SAAS,SACnC,WAAU,QAAQ,cAAc,QAAQ,MAAM,cAAc,CAAC;MAE7D,WAAU,QAAQ,cAAc,EAAE,MAAM,OAAO,IAAI,EAAE,cAAc,CAAC;IAGtE"}