@vitest/snapshot 3.0.9 → 3.1.0-beta.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.
@@ -2,42 +2,39 @@ import { promises, existsSync } from 'node:fs';
2
2
  import { resolve, isAbsolute, dirname, join, basename } from 'pathe';
3
3
 
4
4
  class NodeSnapshotEnvironment {
5
- constructor(options = {}) {
6
- this.options = options;
7
- }
8
- getVersion() {
9
- return "1";
10
- }
11
- getHeader() {
12
- return `// Snapshot v${this.getVersion()}`;
13
- }
14
- async resolveRawPath(testPath, rawPath) {
15
- return isAbsolute(rawPath) ? rawPath : resolve(dirname(testPath), rawPath);
16
- }
17
- async resolvePath(filepath) {
18
- return join(
19
- join(dirname(filepath), this.options.snapshotsDirName ?? "__snapshots__"),
20
- `${basename(filepath)}.snap`
21
- );
22
- }
23
- async prepareDirectory(dirPath) {
24
- await promises.mkdir(dirPath, { recursive: true });
25
- }
26
- async saveSnapshotFile(filepath, snapshot) {
27
- await promises.mkdir(dirname(filepath), { recursive: true });
28
- await promises.writeFile(filepath, snapshot, "utf-8");
29
- }
30
- async readSnapshotFile(filepath) {
31
- if (!existsSync(filepath)) {
32
- return null;
33
- }
34
- return promises.readFile(filepath, "utf-8");
35
- }
36
- async removeSnapshotFile(filepath) {
37
- if (existsSync(filepath)) {
38
- await promises.unlink(filepath);
39
- }
40
- }
5
+ constructor(options = {}) {
6
+ this.options = options;
7
+ }
8
+ getVersion() {
9
+ return "1";
10
+ }
11
+ getHeader() {
12
+ return `// Snapshot v${this.getVersion()}`;
13
+ }
14
+ async resolveRawPath(testPath, rawPath) {
15
+ return isAbsolute(rawPath) ? rawPath : resolve(dirname(testPath), rawPath);
16
+ }
17
+ async resolvePath(filepath) {
18
+ return join(join(dirname(filepath), this.options.snapshotsDirName ?? "__snapshots__"), `${basename(filepath)}.snap`);
19
+ }
20
+ async prepareDirectory(dirPath) {
21
+ await promises.mkdir(dirPath, { recursive: true });
22
+ }
23
+ async saveSnapshotFile(filepath, snapshot) {
24
+ await promises.mkdir(dirname(filepath), { recursive: true });
25
+ await promises.writeFile(filepath, snapshot, "utf-8");
26
+ }
27
+ async readSnapshotFile(filepath) {
28
+ if (!existsSync(filepath)) {
29
+ return null;
30
+ }
31
+ return promises.readFile(filepath, "utf-8");
32
+ }
33
+ async removeSnapshotFile(filepath) {
34
+ if (existsSync(filepath)) {
35
+ await promises.unlink(filepath);
36
+ }
37
+ }
41
38
  }
42
39
 
43
40
  export { NodeSnapshotEnvironment };