@vitest/snapshot 0.30.0 → 0.31.0

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,7 @@ interface SnapshotEnvironment {
3
3
  getHeader(): string;
4
4
  resolvePath(filepath: string): Promise<string>;
5
5
  resolveRawPath(testPath: string, rawPath: string): Promise<string>;
6
- prepareDirectory(filepath: string): Promise<void>;
6
+ prepareDirectory(dirPath: string): Promise<void>;
7
7
  saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
8
8
  readSnapshotFile(filepath: string): Promise<string | null>;
9
9
  removeSnapshotFile(filepath: string): Promise<void>;
@@ -1,11 +1,11 @@
1
- import { S as SnapshotEnvironment } from './environment-8fbbf71b.js';
1
+ import { S as SnapshotEnvironment } from './environment-38cdead3.js';
2
2
 
3
3
  declare class NodeSnapshotEnvironment implements SnapshotEnvironment {
4
4
  getVersion(): string;
5
5
  getHeader(): string;
6
6
  resolveRawPath(testPath: string, rawPath: string): Promise<string>;
7
7
  resolvePath(filepath: string): Promise<string>;
8
- prepareDirectory(filepath: string): Promise<void>;
8
+ prepareDirectory(dirPath: string): Promise<void>;
9
9
  saveSnapshotFile(filepath: string, snapshot: string): Promise<void>;
10
10
  readSnapshotFile(filepath: string): Promise<string | null>;
11
11
  removeSnapshotFile(filepath: string): Promise<void>;
@@ -20,10 +20,11 @@ class NodeSnapshotEnvironment {
20
20
  `${basename(filepath)}.snap`
21
21
  );
22
22
  }
23
- async prepareDirectory(filepath) {
24
- await promises.mkdir(filepath, { recursive: true });
23
+ async prepareDirectory(dirPath) {
24
+ await promises.mkdir(dirPath, { recursive: true });
25
25
  }
26
26
  async saveSnapshotFile(filepath, snapshot) {
27
+ await promises.mkdir(dirname(filepath), { recursive: true });
27
28
  await promises.writeFile(filepath, snapshot, "utf-8");
28
29
  }
29
30
  async readSnapshotFile(filepath) {
@@ -1,5 +1,5 @@
1
1
  import { OptionsReceived } from 'pretty-format';
2
- import { S as SnapshotEnvironment } from './environment-8fbbf71b.js';
2
+ import { S as SnapshotEnvironment } from './environment-38cdead3.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-2c775746.js';
2
- export { c as SnapshotData, e as SnapshotSummary, d as SnapshotUpdateState, U as UncheckedSnapshot } from './index-2c775746.js';
3
- import { S as SnapshotEnvironment } from './environment-8fbbf71b.js';
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';
4
4
  import { Plugin, Plugins } from 'pretty-format';
5
5
 
6
6
  interface ParsedStack {
package/dist/index.js CHANGED
@@ -424,7 +424,7 @@ async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
424
424
  ${snapshots.join("\n\n")}
425
425
  `;
426
426
  const oldContent = await environment.readSnapshotFile(snapshotPath);
427
- const skipWriting = oldContent && oldContent === content;
427
+ const skipWriting = oldContent != null && oldContent === content;
428
428
  if (skipWriting)
429
429
  return;
430
430
  await ensureDirectoryExists(environment, snapshotPath);
@@ -726,6 +726,10 @@ ${JSON.stringify(stacks)}`
726
726
  let receivedSerialized = rawSnapshot && typeof received === "string" ? received : serialize(received, void 0, this._snapshotFormat);
727
727
  if (!rawSnapshot)
728
728
  receivedSerialized = addExtraLineBreaks(receivedSerialized);
729
+ if (rawSnapshot) {
730
+ if (rawSnapshot.content && rawSnapshot.content.match(/\r\n/) && !receivedSerialized.match(/\r\n/))
731
+ rawSnapshot.content = normalizeNewlines(rawSnapshot.content);
732
+ }
729
733
  const expected = isInline ? inlineSnapshot : rawSnapshot ? rawSnapshot.content : this._snapshotData[key];
730
734
  const expectedTrimmed = prepareExpected(expected);
731
735
  const pass = expectedTrimmed === prepareExpected(receivedSerialized);
package/dist/manager.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './index-2c775746.js';
1
+ import { S as SnapshotStateOptions, e as SnapshotSummary, b as SnapshotResult } from './index-6461367c.js';
2
2
  import 'pretty-format';
3
- import './environment-8fbbf71b.js';
3
+ import './environment-38cdead3.js';
4
4
 
5
5
  declare class SnapshotManager {
6
6
  options: Omit<SnapshotStateOptions, 'snapshotEnvironment'>;
@@ -0,0 +1 @@
1
+ export * from './dist/environment.js'
package/manager.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/manager.js'
package/package.json CHANGED
@@ -1,14 +1,19 @@
1
1
  {
2
2
  "name": "@vitest/snapshot",
3
3
  "type": "module",
4
- "version": "0.30.0",
5
- "description": "Vitest Snapshot Resolver",
4
+ "version": "0.31.0",
5
+ "description": "Vitest snapshot manager",
6
6
  "license": "MIT",
7
+ "funding": "https://opencollective.com/vitest",
8
+ "homepage": "https://github.com/vitest-dev/vitest/tree/main/packages/snapshot#readme",
7
9
  "repository": {
8
10
  "type": "git",
9
11
  "url": "git+https://github.com/vitest-dev/vitest.git",
10
12
  "directory": "packages/snapshot"
11
13
  },
14
+ "bugs": {
15
+ "url": "https://github.com/vitest-dev/vitest/issues"
16
+ },
12
17
  "sideEffects": false,
13
18
  "exports": {
14
19
  ".": {
@@ -40,7 +45,7 @@
40
45
  "devDependencies": {
41
46
  "@types/natural-compare": "^1.4.1",
42
47
  "natural-compare": "^1.4.0",
43
- "@vitest/utils": "0.30.0"
48
+ "@vitest/utils": "0.31.0"
44
49
  },
45
50
  "scripts": {
46
51
  "build": "rimraf dist && rollup -c",