@stream44.studio/t44 0.4.0-rc.26 → 0.4.0-rc.27
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/caps/ProjectTest.ts +34 -10
- package/package.json +1 -1
package/caps/ProjectTest.ts
CHANGED
|
@@ -192,7 +192,7 @@ export async function capsule({
|
|
|
192
192
|
value: async function (this: any, actual: any, opts?: { strict?: boolean }): Promise<void> {
|
|
193
193
|
const strict = opts?.strict === true
|
|
194
194
|
|
|
195
|
-
const isUpdate = process.env.UPDATE_SNAPSHOTS === '1' || process.argv.includes('--update-snapshots') || process.argv.includes('-u')
|
|
195
|
+
const isUpdate = process.env.UPDATE_SNAPSHOTS === '1' || process.env.BUN_UPDATE_SNAPSHOTS === '1' || process.argv.includes('--update-snapshots') || process.argv.includes('-u')
|
|
196
196
|
const expect = this.bunTest.expect
|
|
197
197
|
|
|
198
198
|
// Build the snapshot key from describe stack + current it name
|
|
@@ -205,15 +205,37 @@ export async function capsule({
|
|
|
205
205
|
this._snapshotCounters.set(baseKey, count)
|
|
206
206
|
const snapshotKey = `${baseKey} #${count}`
|
|
207
207
|
|
|
208
|
-
// Stabilize
|
|
209
|
-
const
|
|
210
|
-
|
|
208
|
+
// Stabilize for storage: sort object keys only (preserves array order in snapshots)
|
|
209
|
+
const stabilizeForStorage = (obj: any): any => JSON.parse(stringify(obj) || 'null')
|
|
210
|
+
|
|
211
|
+
// Deep sort for comparison: sort both object keys AND array elements recursively
|
|
212
|
+
const deepSortForComparison = (obj: any): any => {
|
|
213
|
+
if (obj === null || obj === undefined) return obj
|
|
214
|
+
if (Array.isArray(obj)) {
|
|
215
|
+
// Recursively sort array elements, then sort the array itself
|
|
216
|
+
const sorted = obj.map(deepSortForComparison)
|
|
217
|
+
// Sort arrays by their JSON representation for deterministic ordering
|
|
218
|
+
return sorted.sort((a, b) => {
|
|
219
|
+
const aStr = JSON.stringify(a) ?? ''
|
|
220
|
+
const bStr = JSON.stringify(b) ?? ''
|
|
221
|
+
return aStr.localeCompare(bStr)
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
if (typeof obj === 'object') {
|
|
225
|
+
const sorted: Record<string, any> = {}
|
|
226
|
+
for (const key of Object.keys(obj).sort()) {
|
|
227
|
+
sorted[key] = deepSortForComparison(obj[key])
|
|
228
|
+
}
|
|
229
|
+
return sorted
|
|
230
|
+
}
|
|
231
|
+
return obj
|
|
232
|
+
}
|
|
211
233
|
|
|
212
234
|
const snapshots = await this._loadSnapshots()
|
|
213
235
|
|
|
214
236
|
if (isUpdate || !(snapshotKey in snapshots)) {
|
|
215
|
-
// Write mode: store
|
|
216
|
-
snapshots[snapshotKey] =
|
|
237
|
+
// Write mode: store with sorted keys but preserve array order
|
|
238
|
+
snapshots[snapshotKey] = stabilizeForStorage(actual)
|
|
217
239
|
this._snapshotDirty = true
|
|
218
240
|
return
|
|
219
241
|
}
|
|
@@ -222,13 +244,15 @@ export async function capsule({
|
|
|
222
244
|
const stored = snapshots[snapshotKey]
|
|
223
245
|
|
|
224
246
|
if (strict) {
|
|
225
|
-
// Strict mode: exact deep equality (order matters)
|
|
247
|
+
// Strict mode: exact deep equality (order matters for both keys and arrays)
|
|
248
|
+
const stabilized = stabilizeForStorage(actual)
|
|
226
249
|
expect(stabilized).toEqual(stored)
|
|
227
250
|
} else {
|
|
228
251
|
// Default mode: sort-order-ignorant deep comparison
|
|
229
|
-
// Both sides are
|
|
230
|
-
const
|
|
231
|
-
|
|
252
|
+
// Both sides are deeply sorted (keys AND arrays)
|
|
253
|
+
const actualSorted = deepSortForComparison(actual)
|
|
254
|
+
const storedSorted = deepSortForComparison(stored)
|
|
255
|
+
expect(actualSorted).toEqual(storedSorted)
|
|
232
256
|
}
|
|
233
257
|
}
|
|
234
258
|
},
|