vitest-plugin-vis
Version:
Vitest visual testing plugin
1 lines • 3.13 kB
Source Map (JSON)
{"version":3,"file":"snapshot_path-7GliOSH_.mjs","names":[],"sources":["../src/shared/trim_common_folder.ts","../src/server/snapshot_path.ts"],"sourcesContent":["/**\n * Trim off common folder such as `src` or `tests` from the test file path.\n * This is used to generate the default snapshot sub-path.\n */\nexport function trimCommonFolder(suiteName: string) {\n\tsuiteName = suiteName.replaceAll('..', '__')\n\tconst suiteDir = suiteName.split('/', 1)[0]!\n\tif (['tests', 'test', 'src', 'source', 'js', 'ts', 'lib'].includes(suiteDir))\n\t\treturn suiteName.slice(suiteDir.length + 1)\n\treturn suiteName\n}\n","import ci from 'is-ci'\nimport { platform } from 'node:process'\nimport type { VisOptions } from '../config/types.ts'\nimport { SNAPSHOT_ROOT_DIR } from '../shared/constants.ts'\nimport { trimCommonFolder } from '../shared/trim_common_folder.ts'\nimport type { ExtendedBrowserCommandContext } from './vis_server_context.types.ts'\n\nexport function resolveSnapshotRootDir(browserCommandContext: ExtendedBrowserCommandContext, options: VisOptions) {\n\tif (!options.snapshotRootDir) return getSnapshotRootDir(SNAPSHOT_ROOT_DIR)\n\tconst snapshotRootDir = options.snapshotRootDir\n\tif (typeof snapshotRootDir === 'string') return getSnapshotRootDir(snapshotRootDir)\n\tconst { config } = browserCommandContext.project.browser\n\treturn snapshotRootDir({\n\t\tci,\n\t\tbrowserName: config.browser.name,\n\t\tproviderName: browserCommandContext.provider.name,\n\t\tplatform,\n\t\tscreenshotFailures: config.browser.screenshotFailures,\n\t\tscreenshotDirectory: config.browser.screenshotDirectory,\n\t})\n}\n\n/**\n * Gets the root directory for storing snapshots.\n *\n * @param snapshotRootDir - Base directory for snapshots. Defaults to `__vis__`.\n * @returns The full snapshot root directory path, which includes a platform-specific subdirectory:\n * - When running in CI: `<snapshotRootDir>/<platform>` (e.g. `__vis__/linux`)\n * - When running locally: `<snapshotRootDir>/local`\n */\nexport function getSnapshotRootDir(snapshotRootDir = SNAPSHOT_ROOT_DIR) {\n\treturn `${snapshotRootDir}/${ci ? platform : 'local'}`\n}\n\nexport function getSnapshotSubpath(suiteName: string, options: Pick<VisOptions, 'snapshotSubpath'>) {\n\tconst snapshotSubpath = options.snapshotSubpath ?? (({ subpath }) => trimCommonFolder(subpath))\n\treturn snapshotSubpath({ subpath: suiteName })\n}\n"],"mappings":";;;;;;;;;AAIA,SAAgB,iBAAiB,WAAmB;AACnD,aAAY,UAAU,WAAW,MAAM,KAAK;CAC5C,MAAM,WAAW,UAAU,MAAM,KAAK,EAAE,CAAC;AACzC,KAAI;EAAC;EAAS;EAAQ;EAAO;EAAU;EAAM;EAAM;EAAM,CAAC,SAAS,SAAS,CAC3E,QAAO,UAAU,MAAM,SAAS,SAAS,EAAE;AAC5C,QAAO;;;;;ACFR,SAAgB,uBAAuB,uBAAsD,SAAqB;AACjH,KAAI,CAAC,QAAQ,gBAAiB,QAAO,mBAAmB,kBAAkB;CAC1E,MAAM,kBAAkB,QAAQ;AAChC,KAAI,OAAO,oBAAoB,SAAU,QAAO,mBAAmB,gBAAgB;CACnF,MAAM,EAAE,WAAW,sBAAsB,QAAQ;AACjD,QAAO,gBAAgB;EACtB;EACA,aAAa,OAAO,QAAQ;EAC5B,cAAc,sBAAsB,SAAS;EAC7C;EACA,oBAAoB,OAAO,QAAQ;EACnC,qBAAqB,OAAO,QAAQ;EACpC,CAAC;;;;;;;;;;AAWH,SAAgB,mBAAmB,kBAAkB,mBAAmB;AACvE,QAAO,GAAG,gBAAgB,GAAG,KAAK,WAAW;;AAG9C,SAAgB,mBAAmB,WAAmB,SAA8C;AAEnG,SADwB,QAAQ,qBAAqB,EAAE,cAAc,iBAAiB,QAAQ,GACvE,EAAE,SAAS,WAAW,CAAC"}