@jsenv/snapshot 2.17.11 → 2.18.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.
package/package.json CHANGED
@@ -1,53 +1,53 @@
1
1
  {
2
2
  "name": "@jsenv/snapshot",
3
- "version": "2.17.11",
3
+ "version": "2.18.0",
4
+ "type": "module",
4
5
  "description": "Snapshot testing",
5
6
  "repository": {
6
7
  "type": "git",
7
8
  "url": "https://github.com/jsenv/core",
8
9
  "directory": "packages/tooling/snapshot"
9
10
  },
10
- "license": "MIT",
11
11
  "author": {
12
12
  "name": "dmail",
13
13
  "email": "dmaillard06@gmail.com"
14
14
  },
15
- "sideEffects": false,
16
- "type": "module",
15
+ "license": "MIT",
16
+ "engines": {
17
+ "node": ">=20.0.0"
18
+ },
19
+ "main": "./src/main.js",
17
20
  "exports": {
18
21
  ".": {
19
22
  "import": "./src/main.js"
20
23
  },
21
24
  "./*": "./*"
22
25
  },
23
- "main": "./src/main.js",
24
26
  "files": [
25
27
  "/src/"
26
28
  ],
27
29
  "dependencies": {
28
- "@jsenv/assert": "4.5.5",
30
+ "@jsenv/assert": "4.5.6",
29
31
  "@jsenv/ast": "6.8.0",
30
32
  "@jsenv/exception": "1.2.1",
31
33
  "@jsenv/filesystem": "4.15.15",
32
34
  "@jsenv/humanize": "1.7.6",
33
- "@jsenv/terminal-recorder": "1.5.44",
35
+ "@jsenv/terminal-recorder": "1.5.46",
34
36
  "@jsenv/url-meta": "8.5.7",
35
37
  "@jsenv/urls": "2.9.8",
36
38
  "@jsenv/utils": "2.3.1",
37
39
  "ansi-regex": "6.2.2",
38
- "pixelmatch": "7.1.0",
40
+ "pixelmatch": "7.2.0",
39
41
  "pngjs": "7.0.0",
40
- "prettier": "3.8.1",
42
+ "prettier": "3.8.3",
41
43
  "strip-ansi": "7.2.0"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@jsenv/assert": "../assert",
45
47
  "@jsenv/snapshot": "./"
46
48
  },
47
- "engines": {
48
- "node": ">=20.0.0"
49
- },
50
49
  "publishConfig": {
51
50
  "access": "public"
52
- }
51
+ },
52
+ "sideEffects": false
53
53
  }
@@ -24,6 +24,7 @@ export const replaceFluctuatingValues = (
24
24
  rootDirectoryUrl,
25
25
  fileUrl,
26
26
  preserveAnsi,
27
+ preserveDurations = false,
27
28
  // for unit test
28
29
  replaceFilesystemWellKnownValues = createReplaceFilesystemWellKnownValues({
29
30
  rootDirectoryUrl,
@@ -84,7 +85,10 @@ export const replaceFluctuatingValues = (
84
85
  // // string = string.replaceAll("‼", "⚠");
85
86
  // return string;
86
87
  // };
87
- const replaceThings = (string, { shouldReplaceDurations } = {}) => {
88
+ const replaceThings = (
89
+ string,
90
+ { preserveDurations: preserveDurationsLocal = false } = {},
91
+ ) => {
88
92
  if (stringType === "filesystem") {
89
93
  return replaceFilesystemWellKnownValues(string);
90
94
  }
@@ -96,7 +100,7 @@ export const replaceFluctuatingValues = (
96
100
  willBeWrittenOnFilesystem: false,
97
101
  });
98
102
  string = replaceHttpUrls(string);
99
- if (shouldReplaceDurations !== false) {
103
+ if (!preserveDurationsLocal && !preserveDurations) {
100
104
  string = replaceDurations(string);
101
105
  }
102
106
  // string = replaceUnicodeFallbacks(string);
@@ -143,7 +147,7 @@ export const replaceFluctuatingValues = (
143
147
  newValue = "[time]";
144
148
  } else {
145
149
  newValue = replaceThings(attributeValue, {
146
- shouldReplaceDurations: name !== "style",
150
+ preserveDurations: name === "style",
147
151
  });
148
152
  }
149
153
  attributes[name] = newValue;
@@ -52,6 +52,7 @@ export const renderSideEffects = (
52
52
  }),
53
53
  sourceLocation = false,
54
54
  errorTransform,
55
+ preserveDurations = false,
55
56
  } = {},
56
57
  ) => {
57
58
  const { rootDirectoryUrl, replaceFilesystemWellKnownValues } =
@@ -61,6 +62,7 @@ export const renderSideEffects = (
61
62
  return replaceFluctuatingValues(value, {
62
63
  replaceFilesystemWellKnownValues,
63
64
  rootDirectoryUrl,
65
+ preserveDurations,
64
66
  ...options,
65
67
  });
66
68
  };
@@ -35,6 +35,10 @@ import { renderSideEffects, renderSmallLink } from "./render_side_effects.js";
35
35
  * @param {url} [snapshotTestsOptions.filesystemEffects.baseDirectory]
36
36
  * Urls of filesystem side effects will be relative to this base directory
37
37
  * Default to the directory containing @sourceFileUrl
38
+ * @param {boolean} [snapshotTestsOptions.preserveDurations=false]
39
+ * When true, duration-like values (e.g. "30s", "1.2 seconds") are kept as-is
40
+ * in the snapshot instead of being replaced with "<X>s". Useful when the
41
+ * test output intentionally contains duration strings.
38
42
  */
39
43
  let preconfiguredOptions = null;
40
44
  export const snapshotTests = async (
@@ -62,6 +66,7 @@ export const snapshotTests = async (
62
66
  filesystemEffects,
63
67
  throwWhenDiff = process.env.CI,
64
68
  sourceLocation = false,
69
+ preserveDurations = false,
65
70
  } = options;
66
71
  filesystemActions = {
67
72
  "**": "compare",
@@ -203,6 +208,7 @@ export const snapshotTests = async (
203
208
  generateOutFileUrl: generateScenarioOutFileUrl,
204
209
  title: scenario,
205
210
  sourceLocation,
211
+ preserveDurations,
206
212
  });
207
213
  writeFileSync(scenarioMdFileUrl, sideEffectsMarkdown);
208
214
  }