@vitest/snapshot 0.34.1 → 0.34.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,6 @@ interface SnapshotEnvironment {
3
3
  getHeader(): string;
4
4
  resolvePath(filepath: string): Promise<string>;
5
5
  resolveRawPath(testPath: string, rawPath: string): Promise<string>;
6
- prepareDirectory(dirPath: string): Promise<void>;
7
6
  saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
8
7
  readSnapshotFile(filepath: string): Promise<string | null>;
9
8
  removeSnapshotFile(filepath: string): Promise<void>;
@@ -1,4 +1,4 @@
1
- import { S as SnapshotEnvironment } from './environment-38cdead3.js';
1
+ import { S as SnapshotEnvironment } from './environment-b0891b0a.js';
2
2
 
3
3
  declare class NodeSnapshotEnvironment implements SnapshotEnvironment {
4
4
  getVersion(): string;
@@ -1,5 +1,5 @@
1
1
  import { OptionsReceived } from 'pretty-format';
2
- import { S as SnapshotEnvironment } from './environment-38cdead3.js';
2
+ import { S as SnapshotEnvironment } from './environment-b0891b0a.js';
3
3
 
4
4
  interface RawSnapshotInfo {
5
5
  file: string;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as SnapshotStateOptions, a as SnapshotMatchOptions, b as SnapshotResult, R as RawSnapshotInfo } from './index-6461367c.js';
2
- export { c as SnapshotData, e as SnapshotSummary, d as SnapshotUpdateState, U as UncheckedSnapshot } from './index-6461367c.js';
3
- import { S as SnapshotEnvironment } from './environment-38cdead3.js';
1
+ import { S as SnapshotStateOptions, a as SnapshotMatchOptions, b as SnapshotResult, R as RawSnapshotInfo } from './index-69d272f6.js';
2
+ export { c as SnapshotData, e as SnapshotSummary, d as SnapshotUpdateState, U as UncheckedSnapshot } from './index-69d272f6.js';
3
+ import { S as SnapshotEnvironment } from './environment-b0891b0a.js';
4
4
  import { Plugin, Plugins } from 'pretty-format';
5
5
 
6
6
  interface ParsedStack {
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import { join, dirname } from 'pathe';
2
1
  import { plugins, format } from 'pretty-format';
3
2
 
4
3
  function getDefaultExportFromCjs (x) {
@@ -254,12 +253,6 @@ function escapeBacktickString(str) {
254
253
  function printBacktickString(str) {
255
254
  return `\`${escapeBacktickString(str)}\``;
256
255
  }
257
- async function ensureDirectoryExists(environment, filePath) {
258
- try {
259
- await environment.prepareDirectory(join(dirname(filePath)));
260
- } catch {
261
- }
262
- }
263
256
  function normalizeNewlines(string) {
264
257
  return string.replace(/\r\n|\r/g, "\n");
265
258
  }
@@ -275,7 +268,6 @@ ${snapshots.join("\n\n")}
275
268
  const skipWriting = oldContent != null && oldContent === content;
276
269
  if (skipWriting)
277
270
  return;
278
- await ensureDirectoryExists(environment, snapshotPath);
279
271
  await environment.saveSnapshotFile(
280
272
  snapshotPath,
281
273
  content
@@ -933,6 +925,8 @@ function parseSingleV8Stack(raw) {
933
925
  if (file.startsWith("file://"))
934
926
  file = file.slice(7);
935
927
  file = resolve$2(file);
928
+ if (method)
929
+ method = method.replace(/__vite_ssr_import_\d+__\./g, "");
936
930
  return {
937
931
  method,
938
932
  file,
@@ -992,17 +986,37 @@ async function saveInlineSnapshots(environment, snapshots) {
992
986
  }
993
987
  const startObjectRegex = /(?:toMatchInlineSnapshot|toThrowErrorMatchingInlineSnapshot)\s*\(\s*(?:\/\*[\S\s]*\*\/\s*|\/\/.*\s+)*\s*({)/m;
994
988
  function replaceObjectSnap(code, s, index, newSnap) {
995
- code = code.slice(index);
996
- const startMatch = startObjectRegex.exec(code);
989
+ let _code = code.slice(index);
990
+ const startMatch = startObjectRegex.exec(_code);
997
991
  if (!startMatch)
998
992
  return false;
999
- code = code.slice(startMatch.index);
1000
- const charIndex = getCallLastIndex(code);
1001
- if (charIndex === null)
993
+ _code = _code.slice(startMatch.index);
994
+ let callEnd = getCallLastIndex(_code);
995
+ if (callEnd === null)
1002
996
  return false;
1003
- s.appendLeft(index + startMatch.index + charIndex, `, ${prepareSnapString(newSnap, code, index)}`);
997
+ callEnd += index + startMatch.index;
998
+ const shapeStart = index + startMatch.index + startMatch[0].length;
999
+ const shapeEnd = getObjectShapeEndIndex(code, shapeStart);
1000
+ const snap = `, ${prepareSnapString(newSnap, code, index)}`;
1001
+ if (shapeEnd === callEnd) {
1002
+ s.appendLeft(callEnd, snap);
1003
+ } else {
1004
+ s.overwrite(shapeEnd, callEnd, snap);
1005
+ }
1004
1006
  return true;
1005
1007
  }
1008
+ function getObjectShapeEndIndex(code, index) {
1009
+ let startBraces = 1;
1010
+ let endBraces = 0;
1011
+ while (startBraces !== endBraces && index < code.length) {
1012
+ const s = code[index++];
1013
+ if (s === "{")
1014
+ startBraces++;
1015
+ else if (s === "}")
1016
+ endBraces++;
1017
+ }
1018
+ return index;
1019
+ }
1006
1020
  function prepareSnapString(snap, source, index) {
1007
1021
  const lineNumber = offsetToLineNumber(source, index);
1008
1022
  const line = source.split(lineSplitRE)[lineNumber - 1];
package/dist/manager.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './index-6461367c.js';
1
+ import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './index-69d272f6.js';
2
2
  import 'pretty-format';
3
- import './environment-38cdead3.js';
3
+ import './environment-b0891b0a.js';
4
4
 
5
5
  declare class SnapshotManager {
6
6
  options: Omit<SnapshotStateOptions, 'snapshotEnvironment'>;
7
7
  summary: SnapshotSummary;
8
+ resolvedPaths: Set<string>;
8
9
  extension: string;
9
10
  constructor(options: Omit<SnapshotStateOptions, 'snapshotEnvironment'>);
10
11
  clear(): void;
package/dist/manager.js CHANGED
@@ -6,6 +6,7 @@ class SnapshotManager {
6
6
  this.clear();
7
7
  }
8
8
  summary = void 0;
9
+ resolvedPaths = /* @__PURE__ */ new Set();
9
10
  extension = ".snap";
10
11
  clear() {
11
12
  this.summary = emptySummary(this.options);
@@ -23,7 +24,9 @@ class SnapshotManager {
23
24
  `${basename(testPath)}${this.extension}`
24
25
  );
25
26
  });
26
- return resolver(testPath, this.extension);
27
+ const path = resolver(testPath, this.extension);
28
+ this.resolvedPaths.add(path);
29
+ return path;
27
30
  }
28
31
  resolveRawPath(testPath, rawPath) {
29
32
  return isAbsolute(rawPath) ? rawPath : resolve(dirname(testPath), rawPath);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/snapshot",
3
3
  "type": "module",
4
- "version": "0.34.1",
4
+ "version": "0.34.2",
5
5
  "description": "Vitest snapshot manager",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -45,7 +45,7 @@
45
45
  "devDependencies": {
46
46
  "@types/natural-compare": "^1.4.1",
47
47
  "natural-compare": "^1.4.0",
48
- "@vitest/utils": "0.34.1"
48
+ "@vitest/utils": "0.34.2"
49
49
  },
50
50
  "scripts": {
51
51
  "build": "rimraf dist && rollup -c",