{"version":3,"file":"auto_snapshot_options.mjs","names":[],"sources":["../../src/auto_snapshots/auto_snapshot_options.ts"],"sourcesContent":["import { assertSnapshotKeyWithoutDash } from '../shared/asserts.ts'\nimport { NAME } from '../shared/constants.ts'\nimport type { ComparisonMethod } from '../shared/types.ts'\nimport { ctx } from './_ctx.ts'\nimport type { SnapshotMeta } from './snapshot_meta.ts'\n\ntype Suite = { meta: Record<string, any>; suite?: Suite | undefined }\n\nexport type MetaTask =\n\t| {\n\t\t\tfile?: { meta: Record<string, any> } | undefined\n\t\t\tsuite?: Suite | undefined\n\t\t\tmeta: Record<string, any>\n\t  }\n\t| undefined\n\n/**\n * Set the snapshot options for auto snapshot.\n *\n * You can use it in beforeAll, beforeEach, or individual test cases.\n *\n * @param meta - The snapshot options to set.\n * You can pass a boolean to enable/disable the snapshot, or an object with the snapshot options.\n * When passing an object, the `enable` property will be set to `true` by default unless you explicitly set it to `false`.\n * @param meta.enable - Whether to enable the snapshot.\n * @param meta.snapshotKey - The key to use for the snapshot.\n * @param meta.comparisonMethod - The comparison method to use for the snapshot.\n * @param meta.diffOptions - The diff options to use for the snapshot.\n * @param meta.failureThreshold - The failure threshold to use for the snapshot.\n * @param meta.failureThresholdType - The failure threshold type to use for the snapshot.\n * @param meta.timeout - The timeout to use for the snapshot.\n *\n * @example\n *\n * ```ts\n * beforeAll(() => setAutoSnapshotOptions(...))\n * beforeEach(() => setAutoSnapshotOptions(...))\n *\n * it('...', () => {\n *   setAutoSnapshotOptions(...)\n * })\n * ```\n */\nexport function setAutoSnapshotOptions<M extends ComparisonMethod>(meta: boolean | SnapshotMeta<M>): void {\n\tif (typeof meta === 'object') {\n\t\tassertSnapshotKeyWithoutDash(meta.snapshotKey)\n\t}\n\n\tconst task = getTask()\n\tif (!task) return\n\n\ttask.meta[NAME] = {\n\t\t...task.meta[NAME],\n\t\t...parseMeta(meta),\n\t}\n}\n\nfunction getTask(): MetaTask | undefined {\n\treturn ctx.getCurrentTest() ?? (ctx.getCurrentSuite()?.tasks?.[0] as any)?.file\n}\n\nfunction parseMeta<M extends ComparisonMethod>(meta: boolean | SnapshotMeta<M>): SnapshotMeta<M> {\n\treturn typeof meta === 'boolean' ? ({ enable: meta } as any) : { enable: true, ...meta }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,SAAgB,uBAAmD,MAAuC;AACzG,KAAI,OAAO,SAAS,SACnB,8BAA6B,KAAK,YAAY;CAG/C,MAAM,OAAO,SAAS;AACtB,KAAI,CAAC,KAAM;AAEX,MAAK,KAAK,QAAQ;EACjB,GAAG,KAAK,KAAK;EACb,GAAG,UAAU,KAAK;EAClB;;AAGF,SAAS,UAAgC;AACxC,QAAO,IAAI,gBAAgB,KAAK,IAAI,iBAAiB,EAAE,QAAQ,KAAY;;AAG5E,SAAS,UAAsC,MAAkD;AAChG,QAAO,OAAO,SAAS,YAAa,EAAE,QAAQ,MAAM,GAAW;EAAE,QAAQ;EAAM,GAAG;EAAM"}