@cronn/lib-file-snapshots 0.19.1 → 1.0.1

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/dist/index.d.mts CHANGED
@@ -4,12 +4,6 @@ interface SnapshotSerializer {
4
4
  * The file extension associated with the serialized value
5
5
  */
6
6
  readonly fileExtension: string;
7
- /**
8
- * Returns true when value can be serialized
9
- *
10
- * @param value The value to be serialized
11
- */
12
- canSerialize(value: unknown): boolean;
13
7
  /**
14
8
  * Serializes value
15
9
  *
@@ -50,7 +44,6 @@ declare class JsonSerializer implements SnapshotSerializer {
50
44
  private readonly normalizers;
51
45
  private readonly indentSize;
52
46
  constructor(options?: JsonSerializerOptions);
53
- canSerialize(_value: unknown): boolean;
54
47
  serialize(value: unknown): string;
55
48
  private normalizeValueRecursive;
56
49
  private normalizeNumber;
@@ -82,7 +75,6 @@ declare class TextSerializer implements SnapshotSerializer {
82
75
  readonly fileExtension: string;
83
76
  private readonly normalizers;
84
77
  constructor(options?: TextSerializerOptions);
85
- canSerialize(value: unknown): value is string;
86
78
  serialize(value: unknown): string;
87
79
  private normalizeValue;
88
80
  }
package/dist/index.mjs CHANGED
@@ -10,17 +10,17 @@ const EMOJI_REGEXP = /(?!(\*|#|\d))[\p{Extended_Pictographic}\p{Emoji_Component}
10
10
  function normalizeFileName(testName) {
11
11
  return testName.replaceAll(EMOJI_REGEXP, "").replaceAll(/[+*%~<>?!$#'"`|\\/()[\]{}]/g, "").replaceAll(/[\s.:,;]+/g, "_").replaceAll(/_{2,}/g, "_");
12
12
  }
13
- function readSnapshotFile(path) {
14
- const contents = fs.readFileSync(path, { encoding: "utf8" });
13
+ function readSnapshotFile(filePath) {
14
+ const contents = fs.readFileSync(filePath, { encoding: "utf8" });
15
15
  if (os.EOL === NEW_LINE_SEPARATOR) return contents;
16
16
  return contents.replace(new RegExp(os.EOL, "g"), NEW_LINE_SEPARATOR);
17
17
  }
18
- function writeSnapshotFile(file, data) {
19
- mkdirRecursive(path.dirname(file));
20
- fs.writeFileSync(file, data, { encoding: "utf8" });
18
+ function writeSnapshotFile(filePath, data) {
19
+ mkdirRecursive(path.dirname(filePath));
20
+ fs.writeFileSync(filePath, data, { encoding: "utf8" });
21
21
  }
22
- function mkdirRecursive(path) {
23
- fs.mkdirSync(path, { recursive: true });
22
+ function mkdirRecursive(dirPath) {
23
+ fs.mkdirSync(dirPath, { recursive: true });
24
24
  }
25
25
  function addTrailingNewLine(data) {
26
26
  return `${data}${NEW_LINE_SEPARATOR}`;
@@ -65,9 +65,6 @@ var JsonSerializer = class {
65
65
  this.normalizers = options.normalizers ?? [];
66
66
  this.indentSize = options.indentSize ?? 2;
67
67
  }
68
- canSerialize(_value) {
69
- return true;
70
- }
71
68
  serialize(value) {
72
69
  const jsonValue = this.normalizeValueRecursive(value);
73
70
  return addTrailingNewLine(JSON.stringify(jsonValue, void 0, this.indentSize));
@@ -124,9 +121,9 @@ var JsonSerializer = class {
124
121
  return normalizedObject;
125
122
  }
126
123
  normalizeMap(value) {
127
- return Array.from(value.entries()).reduce((object, [key, value]) => {
124
+ return Array.from(value.entries()).reduce((object, [key, propertyValue]) => {
128
125
  this.assertKeyType(key);
129
- object[key] = value;
126
+ object[key] = propertyValue;
130
127
  return object;
131
128
  }, {});
132
129
  }
@@ -155,11 +152,8 @@ var TextSerializer = class {
155
152
  this.normalizers = options.normalizers ?? [];
156
153
  this.fileExtension = options.fileExtension ?? "txt";
157
154
  }
158
- canSerialize(value) {
159
- return isString(value);
160
- }
161
155
  serialize(value) {
162
- if (!this.canSerialize(value)) throw new Error(`Missing text serialization for value of type ${typeof value}.`);
156
+ if (!isString(value)) throw new Error(`Value of type ${typeof value} cannot be serialized as text. Only strings are supported.`);
163
157
  return addTrailingNewLine(this.normalizeValue(value));
164
158
  }
165
159
  normalizeValue(value) {
@@ -189,7 +183,6 @@ var ValidationFileMatcher = class {
189
183
  return this.updateSnapshots === "all" || this.isValidationFileMissing && this.updateSnapshots === "missing";
190
184
  }
191
185
  matchFileSnapshot(actual) {
192
- if (!this.serializer.canSerialize(actual)) throw new Error(`Cannot serialize value of type ${typeof actual}`);
193
186
  const serializedActual = this.serializer.serialize(actual);
194
187
  const expected = this.resolveExpected(serializedActual);
195
188
  return this.createMatcherResult({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cronn/lib-file-snapshots",
3
- "version": "0.19.1",
3
+ "version": "1.0.1",
4
4
  "description": "The library agnostic core for testing file snapshots",
5
5
  "keywords": [
6
6
  "file snapshots"
@@ -12,7 +12,7 @@
12
12
  "license": "Apache-2.0",
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/cronn/file-snapshots.git",
15
+ "url": "git+https://github.com/cronn/file-snapshots.git",
16
16
  "directory": "packages/lib-file-snapshots"
17
17
  },
18
18
  "homepage": "https://github.com/cronn/file-snapshots",
@@ -43,16 +43,19 @@
43
43
  "dist"
44
44
  ],
45
45
  "devDependencies": {
46
+ "@arethetypeswrong/core": "0.18.2",
46
47
  "@trivago/prettier-plugin-sort-imports": "6.0.2",
47
- "@types/node": "24.10.12",
48
+ "@types/node": "24.11.0",
49
+ "@typescript/native-preview": "7.0.0-dev.20260302.1",
48
50
  "@vitest/coverage-v8": "4.0.18",
49
- "eslint": "9.39.2",
51
+ "eslint": "10.0.2",
50
52
  "eslint-config-prettier": "10.1.8",
51
- "eslint-plugin-unused-imports": "4.3.0",
53
+ "eslint-plugin-check-file": "3.3.1",
54
+ "eslint-plugin-unused-imports": "4.4.1",
52
55
  "prettier": "3.8.1",
56
+ "publint": "0.3.18",
53
57
  "tsdown": "0.20.3",
54
- "typescript": "5.9.3",
55
- "typescript-eslint": "8.54.0",
58
+ "typescript-eslint": "8.56.1",
56
59
  "vitest": "4.0.18",
57
60
  "@cronn/shared-configs": "0.0.0"
58
61
  },
@@ -61,7 +64,7 @@
61
64
  "lint:fix": "eslint src/ --max-warnings=0 --fix",
62
65
  "test": "vitest run",
63
66
  "test:coverage": "vitest run --coverage",
64
- "compile": "tsc",
67
+ "compile": "tsgo",
65
68
  "build": "tsdown"
66
69
  }
67
70
  }