/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/@vitest/snapshot@5.0.0/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{parseErrorStacktrace}from"@vitest/utils/source-map";import{getCallLastIndex}from"@vitest/utils/helpers";import{positionToOffset,offsetToLineNumber,lineSplitRE}from"@vitest/utils/offset";import{m as memo,C as CounterMap,D as DefaultMap,e as evaluateSnapshotFile,k as keyToTestName,s as saveSnapshotFile,t as testNameToKey,a as serialize,b as addExtraLineBreaks,n as normalizeNewlines,r as removeExtraLineBreaks,d as deepMergeSnapshot}from"./chunk-utils.js";export{c as addSerializer,g as getSerializers}from"./chunk-utils.js";import"@vitest/pretty-format";async function saveInlineSnapshots(t,e){const s=(await import("magic-string")).default,a=new Set(e.map(t=>t.file));await Promise.all(Array.from(a).map(async a=>{const n=e.filter(t=>t.file===a),i=await t.readSnapshotFile(a);if(null==i)throw new Error(`cannot read ${a} when saving inline snapshot`);const o=new s(i);for(const t of n){replaceInlineSnap(i,o,positionToOffset(i,t.line,t.column),t.snapshot,t.assertionName)}const r=o.toString();r!==i&&await t.saveSnapshotFile(a,r)}))}const defaultStartObjectRegex=/(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*\{/;function escapeRegExp(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const buildStartObjectRegex=memo(t=>{const e=defaultStartObjectRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot",escapeRegExp(t));return new RegExp(e)});function replaceObjectSnap(t,e,s,a,n){let i=t.slice(s);const o=(n?buildStartObjectRegex(n):defaultStartObjectRegex).exec(i);if(!o)return!1;i=i.slice(o.index);let r=getCallLastIndex(i);if(null===r)return!1;r+=s+o.index;const h=getObjectShapeEndIndex(t,s+o.index+o[0].length),c=`, ${prepareSnapString(a,t,s)}`;return h===r?e.appendLeft(r,c):e.overwrite(h,r,c),!0}function getObjectShapeEndIndex(t,e){let s=1,a=0;for(;s!==a&&e<t.length;){const n=t[e++];"{"===n?s++:"}"===n&&a++}return e}function prepareSnapString(t,e,s){const a=offsetToLineNumber(e,s),n=e.split(lineSplitRE)[a-1].match(/^\s*/)[0]||"",i=n.includes("\t")?`${n}\t`:`${n}  `,o=t.trim().replace(/\\/g,"\\\\").split(/\n/g),r="`";return o.length<=1?`${r}${o.join("\n").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}${r}`:`${r}\n${o.map(t=>t?i+t:"").join("\n").replace(/`/g,"\\`").replace(/\$\{/g,"\\${")}\n${n}${r}`}const defaultMethodNames=["toMatchInlineSnapshot","toThrowErrorMatchingInlineSnapshot"];function getCodeStartingAtIndex(t,e,s){for(const a of s){const s=e-a.length;if(s>=0&&t.slice(s,e)===a)return{code:t.slice(s),index:s}}return{code:t.slice(e),index:e}}const defaultStartRegex=/(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\s\S]*\*\/\s*|\/\/.*(?:[\n\r\u2028\u2029]\s*|[\t\v\f \xA0\u1680\u2000-\u200A\u202F\u205F\u3000\uFEFF]))*[\w$]*(['"`)])/,buildStartRegex=memo(t=>{const e=defaultStartRegex.source.replace("toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot",escapeRegExp(t));return new RegExp(e)});function replaceInlineSnap(t,e,s,a,n){const i=n?[n]:defaultMethodNames,{code:o,index:r}=getCodeStartingAtIndex(t,s,i),h=(n?buildStartRegex(n):defaultStartRegex).exec(o),c=(n?new RegExp(escapeRegExp(n)):/toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot/).exec(o);if(!h||h.index!==c?.index)return replaceObjectSnap(t,e,r,a,n);const p=h[1],d=r+h.index+h[0].length,l=prepareSnapString(a,t,r);if(")"===p)return e.appendRight(d-1,l),!0;const u=new RegExp(`(?:^|[^\\\\])${p}`).exec(t.slice(d));if(!u)return!1;const S=d+u.index+u[0].length;return e.overwrite(d-1,S,l),!0}const INDENTATION_REGEX=/^([^\S\n]*)\S/m;function stripSnapshotIndentation(t){const e=t.match(INDENTATION_REGEX);if(!e||!e[1])return t;const s=e[1],a=t.split(/\n/g);if(a.length<=2)return t;if(""!==a[0].trim()||""!==a.at(-1)?.trim())return t;for(let e=1;e<a.length-1;e++)if(""!==a[e]){if(0!==a[e].indexOf(s))return t;a[e]=a[e].substring(s.length)}return a[a.length-1]="",t=a.join("\n")}async function saveRawSnapshots(t,e){await Promise.all(e.map(async e=>{e.readonly||await t.saveSnapshotFile(e.file,e.snapshot)}))}function isSameStackPosition(t,e){return t.file===e.file&&t.column===e.column&&t.line===e.line}class SnapshotState{testFilePath;snapshotPath;_counters=new CounterMap;_dirty;_updateSnapshot;_snapshotData;_initialData;_inlineSnapshots;_inlineSnapshotStacks;_testIdToKeys=new DefaultMap(()=>[]);_rawSnapshots;_uncheckedKeys;_snapshotFormat;_environment;_fileExists;expand;_added=new CounterMap;_matched=new CounterMap;_unmatched=new CounterMap;_updated=new CounterMap;get added(){return this._added}set added(t){this._added._total=t}get matched(){return this._matched}set matched(t){this._matched._total=t}get unmatched(){return this._unmatched}set unmatched(t){this._unmatched._total=t}get updated(){return this._updated}set updated(t){this._updated._total=t}constructor(t,e,s,a){this.testFilePath=t,this.snapshotPath=e;const n=s??Object.create(null);this._fileExists=null!=s;const i=a.updateSnapshot,o=("all"===i||"new"===i)&&null!=s;this._initialData={...n},this._snapshotData={...n},this._dirty=o,this._inlineSnapshots=[],this._inlineSnapshotStacks=[],this._rawSnapshots=[],this._uncheckedKeys=new Set(Object.keys(this._snapshotData)),this.expand=a.expand||!1,this._updateSnapshot=a.updateSnapshot,this._snapshotFormat={printBasicPrototype:!1,escapeString:!1,maxOutputLength:2**27,...a.snapshotFormat},this._environment=a.snapshotEnvironment}static async create(t,e){const s=e.snapshotEnvironment,a=await s.resolvePath(t);let n;if(s.readSnapshotFileData)n=await s.readSnapshotFileData(a);else{const t=await s.readSnapshotFile(a);n=null!=t?evaluateSnapshotFile(a,t):null}return new SnapshotState(t,a,n,e)}get snapshotUpdateState(){return this._updateSnapshot}get environment(){return this._environment}markSnapshotsAsCheckedForTest(t){this._uncheckedKeys.forEach(e=>{/ \d+$| > /.test(e.slice(t.length))&&this._uncheckedKeys.delete(e)})}clearTest(t){this._inlineSnapshots=this._inlineSnapshots.filter(e=>e.testId!==t),this._inlineSnapshotStacks=this._inlineSnapshotStacks.filter(e=>e.testId!==t);for(const e of this._testIdToKeys.get(t)){const t=keyToTestName(e),s=this._counters.get(t);s>0&&((e in this._snapshotData||e in this._initialData)&&(this._snapshotData[e]=this._initialData[e]),this._counters.set(t,s-1))}this._testIdToKeys.delete(t),this.added.delete(t),this.updated.delete(t),this.matched.delete(t),this.unmatched.delete(t)}_inferInlineSnapshotStack(t){const e=t.findIndex(t=>t.method.match(/__VITEST_(RESOLVES|REJECTS)__/));if(-1!==e)return t[e+3];const s=t.findIndex(t=>t.method.match(/__VITEST_POLL_CHAIN__/));if(-1!==s)return t[s+1];for(let e=0;e<t.length;e++){const s=t[e].method.match(/__INLINE_SNAPSHOT_OFFSET_(\d+)__/);if(s)return t[e+Number(s[1])]??null}const a=t.findIndex(t=>t.method.includes("__VITEST_EXTEND_ASSERTION__"));if(-1!==a)return t[a+3]??null;const n=t.findIndex(t=>t.method.includes("__INLINE_SNAPSHOT__"));return-1!==n?t[n+2]:null}_addSnapshot(t,e,s){this._dirty=!0,s.stack?this._inlineSnapshots.push({...s.stack,snapshot:e,testId:s.testId,assertionName:s.assertionName}):s.rawSnapshot?this._rawSnapshots.push({...s.rawSnapshot,snapshot:e}):this._snapshotData[t]=e}_resolveKey(t,e,s){this._counters.increment(e);const a=this._counters.get(e);return s||(s=testNameToKey(e,a)),this._testIdToKeys.get(t).push(s),{key:s,count:a}}_resolveInlineStack(t){const{testId:e,snapshot:s,assertionName:a,error:n}=t,i=parseErrorStacktrace(n,{ignoreStackEntries:[]}),o=this._inferInlineSnapshotStack(i);if(!o){const t=i.map(t=>`  ${t.file}:${t.line}:${t.column}${t.method?` (${t.method})`:""}`).join("\n");throw new Error(`@vitest/snapshot: Couldn't infer stack frame for inline snapshot.\n${t}`)}const r=this.environment.processStackTrace?.(o)||o;r.column--;const h=this._inlineSnapshotStacks.filter(t=>isSameStackPosition(t,r));if(h.length>0){this._inlineSnapshots=this._inlineSnapshots.filter(t=>!isSameStackPosition(t,r));const t=h.find(t=>t.snapshot!==s);if(t)throw Object.assign(new Error(`${a} with different snapshots cannot be called at the same location`),{actual:s,expected:t.snapshot})}return this._inlineSnapshotStacks.push({...r,testId:e,snapshot:s}),r}_reconcile(t){return t.hasSnapshot&&"all"===this._updateSnapshot||!(t.hasSnapshot&&t.snapshotIsPersisted||"new"!==this._updateSnapshot&&"all"!==this._updateSnapshot)?("all"===this._updateSnapshot?t.pass?this.matched.increment(t.testId):(t.hasSnapshot?this.updated.increment(t.testId):this.added.increment(t.testId),this._addSnapshot(t.key,t.addValue,{stack:t.stack,testId:t.testId,rawSnapshot:t.rawSnapshot,assertionName:t.assertionName})):(this._addSnapshot(t.key,t.addValue,{stack:t.stack,testId:t.testId,rawSnapshot:t.rawSnapshot,assertionName:t.assertionName}),this.added.increment(t.testId)),{actual:"",count:t.count,expected:"",key:t.key,pass:!0}):t.pass?(this.matched.increment(t.testId),{actual:"",count:t.count,expected:"",key:t.key,pass:!0}):(this.unmatched.increment(t.testId),{actual:t.actualDisplay,count:t.count,expected:t.expectedDisplay,key:t.key,pass:!1})}async save(){const t=Object.keys(this._snapshotData).length,e=this._inlineSnapshots.length,s=this._rawSnapshots.length,a=!t&&!e&&!s,n={deleted:!1,saved:!1};return!this._dirty&&!this._uncheckedKeys.size||a?!t&&this._fileExists&&("all"===this._updateSnapshot&&(await this._environment.removeSnapshotFile(this.snapshotPath),this._fileExists=!1),n.deleted=!0):(t&&(await saveSnapshotFile(this._environment,this._snapshotData,this.snapshotPath),this._fileExists=!0),e&&await saveInlineSnapshots(this._environment,this._inlineSnapshots),s&&await saveRawSnapshots(this._environment,this._rawSnapshots),n.saved=!0),n}getUncheckedCount(){return this._uncheckedKeys.size||0}getUncheckedKeys(){return Array.from(this._uncheckedKeys)}removeUncheckedKeys(){"all"===this._updateSnapshot&&this._uncheckedKeys.size&&(this._dirty=!0,this._uncheckedKeys.forEach(t=>delete this._snapshotData[t]),this._uncheckedKeys.clear())}probeExpectedSnapshot(t){const e=this._counters.get(t.testName)+1,s=testNameToKey(t.testName,e);return{key:s,count:e,data:t?.isInline?t.inlineSnapshot:this._snapshotData[s],markAsChecked:()=>{this._counters.increment(t.testName),this._testIdToKeys.get(t.testId).push(s),this._uncheckedKeys.delete(s)}}}match({testId:t,testName:e,received:s,key:a,inlineSnapshot:n,isInline:i,error:o,rawSnapshot:r,assertionName:h}){const c=this._resolveKey(t,e,a);a=c.key;const p=c.count;i&&void 0!==this._snapshotData[a]||this._uncheckedKeys.delete(a);let d=r&&"string"==typeof s?s:serialize(s,void 0,this._snapshotFormat);r||(d=addExtraLineBreaks(d)),r&&r.content&&/\r\n/.test(r.content)&&!/\r\n/.test(d)&&(r.content=normalizeNewlines(r.content));const l=i?n:r?r.content:this._snapshotData[a],u=r?l:l?.trim(),S=u===(r?d:d.trim()),m=void 0!==l,f=i||this._fileExists||r&&null!=r.content;!S||i||r||(this._snapshotData[a]=d);const _=i?this._resolveInlineStack({testId:t,snapshot:d,assertionName:h||"toMatchInlineSnapshot",error:o||new Error("snapshot")}):void 0;return this._reconcile({testId:t,key:a,count:p,pass:S,hasSnapshot:m,snapshotIsPersisted:!!f,addValue:d,actualDisplay:r?d:removeExtraLineBreaks(d),expectedDisplay:void 0!==u?r?u:removeExtraLineBreaks(u):void 0,stack:_,rawSnapshot:r,assertionName:h})}processDomainSnapshot({testId:t,received:e,expectedSnapshot:s,matchResult:a,isInline:n,error:i,assertionName:o}){const r=n?this._resolveInlineStack({testId:t,snapshot:e,assertionName:o,error:i||new Error("STACK_TRACE_ERROR")}):void 0,h=a?.resolved??e,c=a?.expected??s.data;return this._reconcile({testId:t,key:s.key,count:s.count,pass:a?.pass??!1,hasSnapshot:void 0!==s.data,snapshotIsPersisted:!!n||this._fileExists,addValue:h,actualDisplay:removeExtraLineBreaks(h),expectedDisplay:void 0!==c?removeExtraLineBreaks(c):void 0,stack:r,assertionName:o})}async pack(){const t={filepath:this.testFilePath,added:0,fileDeleted:!1,matched:0,unchecked:0,uncheckedKeys:[],unmatched:0,updated:0},e=this.getUncheckedCount(),s=this.getUncheckedKeys();e&&this.removeUncheckedKeys();const a=await this.save();return t.fileDeleted=a.deleted,t.added=this.added.total(),t.matched=this.matched.total(),t.unmatched=this.unmatched.total(),t.updated=this.updated.total(),t.unchecked=a.deleted?0:e,t.uncheckedKeys=Array.from(s),t}}function createMismatchError(t,e,s,a){const n=new Error(t);return Object.defineProperty(n,"actual",{value:s,enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(n,"expected",{value:a,enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(n,"diffOptions",{value:{expand:e}}),n}class SnapshotClient{options;snapshotStateMap=new Map;constructor(t={}){this.options=t}async setup(t,e){this.snapshotStateMap.has(t)||this.snapshotStateMap.set(t,await SnapshotState.create(t,e))}async finish(t){const e=this.getSnapshotState(t),s=await e.pack();return this.snapshotStateMap.delete(t),s}skipTest(t,e){this.getSnapshotState(t).markSnapshotsAsCheckedForTest(e)}clearTest(t,e){this.getSnapshotState(t).clearTest(e)}getSnapshotState(t){const e=this.snapshotStateMap.get(t);if(!e)throw new Error(`The snapshot state for '${t}' is not found. Did you call 'SnapshotClient.setup()'?`);return e}match(t){const{filepath:e,name:s,testId:a=s,message:n,isInline:i=!1,properties:o,inlineSnapshot:r,error:h,errorMessage:c,rawSnapshot:p,assertionName:d}=t;let{received:l}=t;if(!e)throw new Error("Snapshot cannot be used outside of test");const u=this.getSnapshotState(e);if(p?.file===u.snapshotPath)throw new Error(`File snapshot cannot use the same path as the test snapshot file: ${p.file}`);const S=[s,...n?[n]:[]].join(" > "),m=u.probeExpectedSnapshot({testName:S,testId:a,isInline:i,inlineSnapshot:r});if("object"==typeof o){if("object"!=typeof l||!l)throw m.markAsChecked(),new Error("Received value must be an object when the matcher has properties");let t;try{t=this.options.isEqual?.(l,o)??!1}catch(t){throw m.markAsChecked(),t}if(!t)return m.markAsChecked(),{pass:!1,message:()=>c||"Snapshot properties mismatched",actual:l,expected:o};l=deepMergeSnapshot(l,o)}const{actual:f,expected:_,key:g,pass:w}=u.match({testId:a,testName:S,received:l,isInline:i,error:h,inlineSnapshot:r,rawSnapshot:p,assertionName:d});return{pass:w,message:()=>`Snapshot \`${g||"unknown"}\` mismatched`,actual:p?f:f?.trim(),expected:p?_:_?.trim()}}assert(t){const e=this.match(t);if(!e.pass){const s=this.getSnapshotState(t.filepath);throw createMismatchError(e.message(),s.expand,e.actual,e.expected)}}matchDomain(t){const{received:e,filepath:s,name:a,testId:n=a,message:i,adapter:o,isInline:r=!1,inlineSnapshot:h,error:c}=t;if(!s)throw new Error("Snapshot cannot be used outside of test");const p=o.capture(e),d=o.render(p),l=this.getSnapshotState(s),u=[a,...i?[i]:[]].join(" > "),S=l.probeExpectedSnapshot({testName:u,testId:n,isInline:r,inlineSnapshot:h});S.markAsChecked();const m=void 0!==S.data?o.match(p,o.parseExpected(S.data)):void 0,{actual:f,expected:_,key:g,pass:w}=l.processDomainSnapshot({testId:n,received:d,expectedSnapshot:S,matchResult:m,isInline:r,error:c,assertionName:t.assertionName});return{pass:w,message:()=>`Snapshot \`${g}\` mismatched`,actual:f?.trim(),expected:_?.trim()}}async pollMatchDomain(t){const{poll:e,filepath:s,name:a,testId:n=a,message:i,adapter:o,isInline:r=!1,inlineSnapshot:h,error:c,timeout:p=1e3,interval:d=50}=t;if(!s)throw new Error("Snapshot cannot be used outside of test");const l=this.getSnapshotState(s),u=[a,...i?[i]:[]].join(" > "),S=l.probeExpectedSnapshot({testName:u,testId:n,isInline:r,inlineSnapshot:h}),m=void 0!==S.data&&"all"!==l.snapshotUpdateState?o.parseExpected(S.data):void 0,f=new AbortController,_=p>0?new Promise(t=>setTimeout(()=>{f.abort(),t()},p)):void 0,g=await getStableSnapshot({adapter:o,poll:()=>e({signal:f.signal}),interval:d,timedOut:_,match:m?t=>o.match(t,m).pass:void 0});if(S.markAsChecked(),void 0===g?.rendered){if(g?.lastPollError)throw g.lastPollError;return{pass:!1,message:()=>"poll() did not produce a stable snapshot within the timeout"}}const w=void 0!==S.data?o.match(g.captured,o.parseExpected(S.data)):void 0,{actual:k,expected:I,key:v,pass:x}=l.processDomainSnapshot({testId:n,received:g.rendered,expectedSnapshot:S,matchResult:w,isInline:r,error:c,assertionName:t.assertionName});return{pass:x,message:()=>`Snapshot \`${v}\` mismatched`,actual:k?.trim(),expected:I?.trim()}}async assertRaw(t){if(!t.rawSnapshot)throw new Error("Raw snapshot is required");const{filepath:e,rawSnapshot:s}=t;if(null==s.content){if(!e)throw new Error("Snapshot cannot be used outside of test");const a=this.getSnapshotState(e);t.filepath||=e,s.file=await a.environment.resolveRawPath(e,s.file),s.content=await a.environment.readSnapshotFile(s.file)??void 0}return this.assert(t)}clear(){this.snapshotStateMap.clear()}}async function getStableSnapshot({adapter:t,poll:e,interval:s,timedOut:a,match:n}){let i,o,r;for(;;){try{const s=await raceWith(Promise.resolve(e()),a);if(!s.ok)break;const o=t.capture(s.value),h=t.render(o);if(void 0!==i&&h===i){if(r={captured:o,rendered:h},!n||n(o))break}else i=h,r=void 0}catch(t){i=void 0,r=void 0,o=t}if(!(await raceWith(new Promise(t=>setTimeout(t,s)),a)).ok)break}return{...r,lastPollError:o}}function raceWith(t,e){const s=t.then(t=>({ok:!0,value:t}));return e?Promise.race([s,e.then(t=>({ok:!1,value:t}))]):s}export{SnapshotClient,SnapshotState,stripSnapshotIndentation};
//# sourceMappingURL=/sm/803fa61b5dce0b817351a31c9d1e6d286a91062af793c04db4e91351ffb649ce.map