{"version":3,"file":"prepare_image_snapshot_comparison.mjs","names":[],"sources":["../../../src/server/commands/prepare_image_snapshot_comparison.ts"],"sourcesContent":["import { resolve } from 'pathe'\nimport { isBase64String } from '../../shared/base64.ts'\nimport type { PrepareImageSnapshotComparisonCommand } from '../../shared/commands.types.ts'\nimport type { ImageSnapshotComparisonInfo } from '../../shared/types.ts'\nimport { file } from '../externals/file.ts'\nimport { getProjectRoot } from '../project.ts'\nimport { takeSnapshot } from '../snapshot.ts'\nimport { snapshotWriter } from '../snapshot_writer.ts'\nimport { visServerContext } from '../vis_server_context.ts'\nimport type { ExtendedBrowserCommand } from '../vis_server_context.types.ts'\nimport { assertTestPathDefined } from './_assertions.ts'\n\nexport const prepareImageSnapshotComparison: ExtendedBrowserCommand<\n\tParameters<PrepareImageSnapshotComparisonCommand['prepareImageSnapshotComparison']>\n> = async (context, taskId, subject, options): Promise<ImageSnapshotComparisonInfo | undefined> => {\n\tassertTestPathDefined(context, 'prepareImageSnapshotComparison')\n\t// vitest:browser passes in `null` when not defined\n\tif (!options) options = {}\n\toptions.timeout = options.timeout ?? 30000\n\n\tconst projectRoot = getProjectRoot(context)\n\tconst info = await visServerContext.getSnapshotInfo(context, taskId, options)\n\n\tconst baselineBuffer = await file.tryReadFile(resolve(projectRoot, info.baselinePath))\n\tif (!baselineBuffer && isBase64String(subject)) {\n\t\tawait snapshotWriter.writeBase64(resolve(projectRoot, info.resultPath), subject)\n\t\treturn {\n\t\t\t...info,\n\t\t\tprojectRoot,\n\t\t\tresult: subject,\n\t\t} as ImageSnapshotComparisonInfo\n\t}\n\n\tconst resultBuffer = await takeSnapshot(context, projectRoot, info.resultPath, subject, options)\n\treturn {\n\t\t...info,\n\t\tprojectRoot,\n\t\tbaseline: baselineBuffer?.toString('base64'),\n\t\tresult: resultBuffer.toString('base64'),\n\t} as ImageSnapshotComparisonInfo\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAa,iCAET,OAAO,SAAS,QAAQ,SAAS,YAA8D;AAClG,uBAAsB,SAAS,iCAAiC;AAEhE,KAAI,CAAC,QAAS,WAAU,EAAE;AAC1B,SAAQ,UAAU,QAAQ,WAAW;CAErC,MAAM,cAAc,eAAe,QAAQ;CAC3C,MAAM,OAAO,MAAM,iBAAiB,gBAAgB,SAAS,QAAQ,QAAQ;CAE7E,MAAM,iBAAiB,MAAM,KAAK,YAAY,QAAQ,aAAa,KAAK,aAAa,CAAC;AACtF,KAAI,CAAC,kBAAkB,eAAe,QAAQ,EAAE;AAC/C,QAAM,eAAe,YAAY,QAAQ,aAAa,KAAK,WAAW,EAAE,QAAQ;AAChF,SAAO;GACN,GAAG;GACH;GACA,QAAQ;GACR;;CAGF,MAAM,eAAe,MAAM,aAAa,SAAS,aAAa,KAAK,YAAY,SAAS,QAAQ;AAChG,QAAO;EACN,GAAG;EACH;EACA,UAAU,gBAAgB,SAAS,SAAS;EAC5C,QAAQ,aAAa,SAAS,SAAS;EACvC"}