@jsenv/snapshot 2.2.4 → 2.2.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/snapshot",
3
- "version": "2.2.4",
3
+ "version": "2.2.6",
4
4
  "description": "Snapshot testing",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -35,9 +35,9 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@jsenv/assert": "4.1.5",
38
- "@jsenv/ast": "6.2.5",
39
- "@jsenv/filesystem": "4.9.1",
40
- "@jsenv/urls": "2.3.1",
38
+ "@jsenv/ast": "6.2.6",
39
+ "@jsenv/filesystem": "4.9.2",
40
+ "@jsenv/urls": "2.3.2",
41
41
  "@jsenv/utils": "2.1.1",
42
42
  "pixelmatch": "6.0.0",
43
43
  "prettier": "3.3.3",
@@ -8,7 +8,11 @@ import {
8
8
  writeFileSync,
9
9
  } from "@jsenv/filesystem";
10
10
  import { URL_META } from "@jsenv/url-meta";
11
- import { urlToFilename, urlToRelativeUrl } from "@jsenv/urls";
11
+ import {
12
+ ensurePathnameTrailingSlash,
13
+ urlToFilename,
14
+ urlToRelativeUrl,
15
+ } from "@jsenv/urls";
12
16
  import { CONTENT_TYPE } from "@jsenv/utils/src/content_type/content_type.js";
13
17
  import { readdirSync, readFileSync, statSync } from "node:fs";
14
18
  import { fileURLToPath } from "node:url";
@@ -357,20 +361,21 @@ ${extraUrls.join("\n")}`);
357
361
  }
358
362
  const relativeUrl = urlToRelativeUrl(directoryItemUrl, directoryUrl);
359
363
  if (directoryItemStat.isDirectory()) {
360
- if (!shouldIncludeFile(directoryUrl)) {
361
- continue;
362
- }
363
- if (!shouldVisitDirectory(directoryUrl)) {
364
+ ensurePathnameTrailingSlash(directoryItemUrl);
365
+ if (!shouldVisitDirectory(directoryItemUrl)) {
364
366
  continue;
365
367
  }
366
368
  contentSnapshotNaturalOrder[relativeUrl] = createDirectorySnapshot(
367
- new URL(`${directoryItemUrl}/`),
369
+ directoryItemUrl,
368
370
  {
369
371
  shouldVisitDirectory,
370
372
  shouldIncludeFile,
371
373
  clean,
372
374
  },
373
375
  );
376
+ if (clean) {
377
+ removeDirectorySync(directoryItemUrl);
378
+ }
374
379
  continue;
375
380
  }
376
381
  if (!shouldIncludeFile(directoryItemUrl)) {
@@ -4,7 +4,7 @@ import {
4
4
  removeFileSync,
5
5
  writeFileSync,
6
6
  } from "@jsenv/filesystem";
7
- import { urlToRelativeUrl } from "@jsenv/urls/src/url_to_relative_url.js";
7
+ import { urlToFilename, urlToRelativeUrl } from "@jsenv/urls";
8
8
  import { takeDirectorySnapshot } from "./filesystem_snapshot.js";
9
9
  import { replaceFluctuatingValues } from "./replace_fluctuating_values.js";
10
10
 
@@ -17,7 +17,7 @@ export const snapshotFunctionSideEffects = (
17
17
  captureConsole = true,
18
18
  filesystemEffects,
19
19
  filesystemEffectsInline,
20
- restoreFilesystem,
20
+ restoreFilesystem = true,
21
21
  } = {},
22
22
  ) => {
23
23
  const sideEffectDirectoryUrl = new URL(
@@ -27,10 +27,8 @@ export const snapshotFunctionSideEffects = (
27
27
  const sideEffectDirectorySnapshot = takeDirectorySnapshot(
28
28
  sideEffectDirectoryUrl,
29
29
  );
30
- const sideEffectFileUrl = new URL(
31
- "./side_effect.txt",
32
- sideEffectDirectoryUrl,
33
- );
30
+ const sideEffectFilename = `${urlToFilename(sideEffectDirectoryUrl)}_side_effects.txt`;
31
+ const sideEffectFileUrl = new URL(sideEffectFilename, sideEffectDirectoryUrl);
34
32
  const sideEffects = [];
35
33
  const finallyCallbackSet = new Set();
36
34
  const onError = (e) => {