ava 8.0.0 → 8.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.
@@ -6,7 +6,9 @@ import path from 'node:path';
6
6
  import {fileURLToPath} from 'node:url';
7
7
  import zlib from 'node:zlib';
8
8
 
9
- import cbor from 'cbor';
9
+ import {decode as decodeCbor, encode as encodeCbor, TypeEncoderMap} from 'cbor2';
10
+ import {writeArray, writeUint8Array} from 'cbor2/encoder';
11
+ import {sortLengthFirstDeterministic} from 'cbor2/sorts';
10
12
  import concordance from 'concordance';
11
13
  import indentString from 'indent-string';
12
14
  import memoize from 'memoize';
@@ -92,7 +94,7 @@ function formatEntry(snapshot, index) {
92
94
  } = snapshot;
93
95
 
94
96
  const description = data
95
- ? concordance.formatDescriptor(concordance.deserialize(data), concordanceOptions)
97
+ ? concordance.formatDescriptor(concordance.deserialize(Buffer.from(data.buffer, data.byteOffset, data.byteLength)), concordanceOptions)
96
98
  : '<No Data>';
97
99
 
98
100
  const blockquote = label.split(/\n/).map(line => '> ' + line).join('\n');
@@ -180,10 +182,36 @@ function sortBlocks(blocksByTitle, blockIndices) {
180
182
  });
181
183
  }
182
184
 
183
- async function encodeSnapshots(snapshotData) {
184
- const encoded = await cbor.encodeAsync(snapshotData, {
185
- omitUndefinedProperties: true,
186
- canonical: true,
185
+ function normalizeBeforeEncoding(value) {
186
+ if (Array.isArray(value)) {
187
+ return value.map(v => normalizeBeforeEncoding(v));
188
+ }
189
+
190
+ // FIXME: The decode code path unexpectedly returns Buffers not Uint8Arrays.
191
+ if (Buffer.isBuffer(value)) {
192
+ return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
193
+ }
194
+
195
+ if (value !== null && typeof value === 'object' && !(value instanceof Uint8Array)) {
196
+ return Object.fromEntries(Object.entries(value)
197
+ .filter(([, v]) => v !== undefined)
198
+ .map(([k, v]) => [k, normalizeBeforeEncoding(v)]));
199
+ }
200
+
201
+ return value;
202
+ }
203
+
204
+ // FIXME: This seems to be a bug in cbor2, ignoreGlobalTags shouldn't break (Uint8)Array encoding.
205
+ const types = new TypeEncoderMap();
206
+ types.registerEncoder(Array, writeArray);
207
+ types.registerEncoder(Uint8Array, writeUint8Array);
208
+
209
+ function encodeSnapshots(snapshotData) {
210
+ const encoded = encodeCbor(normalizeBeforeEncoding(snapshotData), {
211
+ ignoreGlobalTags: true,
212
+ rejectUndefined: true,
213
+ sortKeys: sortLengthFirstDeterministic,
214
+ types,
187
215
  });
188
216
  const compressed = zlib.gzipSync(encoded);
189
217
  compressed[9] = 0x03; // Override the GZip header containing the OS to always be Linux
@@ -233,7 +261,9 @@ function decodeSnapshots(buffer, snapPath) {
233
261
  }
234
262
 
235
263
  const decompressed = zlib.gunzipSync(compressed);
236
- return cbor.decode(decompressed);
264
+ return decodeCbor(decompressed, {
265
+ ignoreGlobalTags: true,
266
+ });
237
267
  }
238
268
 
239
269
  class Manager {
@@ -282,7 +312,7 @@ class Manager {
282
312
  return {pass: true};
283
313
  }
284
314
 
285
- const actual = concordance.deserialize(data, concordanceOptions);
315
+ const actual = concordance.deserialize(Buffer.from(data.buffer, data.byteOffset, data.byteLength), concordanceOptions);
286
316
  const expected = concordance.describe(options.expected, concordanceOptions);
287
317
  const pass = concordance.compareDescriptors(actual, expected);
288
318
 
@@ -311,7 +341,8 @@ class Manager {
311
341
  deferRecord(options) {
312
342
  const {expected, belongsTo, label, index} = options;
313
343
  const descriptor = concordance.describe(expected, concordanceOptions);
314
- const data = concordance.serialize(descriptor);
344
+ const buffer = concordance.serialize(descriptor);
345
+ const data = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
315
346
 
316
347
  return () => { // Must be called in order!
317
348
  this.hasChanges = true;
@@ -369,7 +400,7 @@ class Manager {
369
400
  blocks: sortBlocks(this.newBlocksByTitle, this.blockIndices).map(([title, block]) => ({title, ...block})),
370
401
  };
371
402
 
372
- const buffer = await encodeSnapshots(snapshots);
403
+ const buffer = encodeSnapshots(snapshots);
373
404
  const reportBuffer = generateReport(relFile, snapFile, snapshots);
374
405
 
375
406
  await fs.promises.mkdir(dir, {recursive: true});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ava",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "Node.js test runner that lets you develop with confidence.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "type": "module",
29
29
  "engines": {
30
- "node": "^22.20 || ^24.12 || >=25"
30
+ "node": "^22.20 || ^24.12 || >=26"
31
31
  },
32
32
  "scripts": {
33
33
  "test": "./scripts/test.sh"
@@ -81,7 +81,7 @@
81
81
  "arrgv": "^1.0.2",
82
82
  "arrify": "^3.0.0",
83
83
  "callsites": "^4.2.0",
84
- "cbor": "^10.0.12",
84
+ "cbor2": "^2.3.0",
85
85
  "chalk": "^5.6.2",
86
86
  "chunkd": "^2.0.1",
87
87
  "ci-info": "^4.4.0",
@@ -119,16 +119,16 @@
119
119
  "@ava/test": "github:avajs/test",
120
120
  "@ava/typescript": "^7.0.0",
121
121
  "@sindresorhus/tsconfig": "^8.1.0",
122
- "@types/node": "^24.12.2",
122
+ "@types/node": "^24.12.4",
123
123
  "ansi-escapes": "^7.3.0",
124
124
  "c8": "^11.0.0",
125
125
  "execa": "^9.6.1",
126
- "expect": "^30.3.0",
127
- "sinon": "^21.0.3",
128
- "tap": "^21.6.3",
126
+ "expect": "^30.4.1",
127
+ "sinon": "^22.0.0",
128
+ "tap": "^21.7.4",
129
129
  "tempy": "^3.2.0",
130
130
  "tsd": "^0.33.0",
131
- "typescript": "~6.0.2",
131
+ "typescript": "~6.0.3",
132
132
  "xo": "^2.0.2",
133
133
  "zen-observable": "^0.10.0"
134
134
  },
@@ -149,7 +149,7 @@
149
149
  }
150
150
  },
151
151
  "volta": {
152
- "node": "24.14.0",
153
- "npm": "11.11.0"
152
+ "node": "24.15.0",
153
+ "npm": "11.14.1"
154
154
  }
155
155
  }