bupkis 0.18.0 → 0.18.2
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/CHANGELOG.md +14 -0
- package/package.json +1 -4
- package/src/assertion/assertion-types.ts +4 -4
- package/src/assertion/impl/async-parametric.ts +4 -21
- package/src/assertion/impl/sync-parametric.ts +5 -17
- package/src/expect.ts +0 -4
- package/src/guards.ts +24 -24
- package/src/internal-schema.ts +16 -32
- package/src/value-to-schema.ts +1 -1
- package/dist/assertion/assertion-async.cjs +0 -268
- package/dist/assertion/assertion-async.cjs.map +0 -1
- package/dist/assertion/assertion-async.d.cts +0 -40
- package/dist/assertion/assertion-async.d.cts.map +0 -1
- package/dist/assertion/assertion-async.d.ts +0 -40
- package/dist/assertion/assertion-async.d.ts.map +0 -1
- package/dist/assertion/assertion-async.js +0 -259
- package/dist/assertion/assertion-async.js.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.cjs +0 -132
- package/dist/assertion/assertion-standard-schema-async.cjs.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.d.cts +0 -52
- package/dist/assertion/assertion-standard-schema-async.d.cts.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.d.ts +0 -52
- package/dist/assertion/assertion-standard-schema-async.d.ts.map +0 -1
- package/dist/assertion/assertion-standard-schema-async.js +0 -128
- package/dist/assertion/assertion-standard-schema-async.js.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.cjs +0 -141
- package/dist/assertion/assertion-standard-schema-sync.cjs.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.d.cts +0 -52
- package/dist/assertion/assertion-standard-schema-sync.d.cts.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.d.ts +0 -52
- package/dist/assertion/assertion-standard-schema-sync.d.ts.map +0 -1
- package/dist/assertion/assertion-standard-schema-sync.js +0 -137
- package/dist/assertion/assertion-standard-schema-sync.js.map +0 -1
- package/dist/assertion/assertion-sync.cjs +0 -284
- package/dist/assertion/assertion-sync.cjs.map +0 -1
- package/dist/assertion/assertion-sync.d.cts +0 -60
- package/dist/assertion/assertion-sync.d.cts.map +0 -1
- package/dist/assertion/assertion-sync.d.ts +0 -60
- package/dist/assertion/assertion-sync.d.ts.map +0 -1
- package/dist/assertion/assertion-sync.js +0 -275
- package/dist/assertion/assertion-sync.js.map +0 -1
- package/dist/assertion/assertion-types.cjs +0 -20
- package/dist/assertion/assertion-types.cjs.map +0 -1
- package/dist/assertion/assertion-types.d.cts +0 -1086
- package/dist/assertion/assertion-types.d.cts.map +0 -1
- package/dist/assertion/assertion-types.d.ts +0 -1086
- package/dist/assertion/assertion-types.d.ts.map +0 -1
- package/dist/assertion/assertion-types.js +0 -19
- package/dist/assertion/assertion-types.js.map +0 -1
- package/dist/assertion/assertion.cjs +0 -382
- package/dist/assertion/assertion.cjs.map +0 -1
- package/dist/assertion/assertion.d.cts +0 -109
- package/dist/assertion/assertion.d.cts.map +0 -1
- package/dist/assertion/assertion.d.ts +0 -109
- package/dist/assertion/assertion.d.ts.map +0 -1
- package/dist/assertion/assertion.js +0 -375
- package/dist/assertion/assertion.js.map +0 -1
- package/dist/assertion/create.cjs +0 -148
- package/dist/assertion/create.cjs.map +0 -1
- package/dist/assertion/create.d.cts +0 -85
- package/dist/assertion/create.d.cts.map +0 -1
- package/dist/assertion/create.d.ts +0 -85
- package/dist/assertion/create.d.ts.map +0 -1
- package/dist/assertion/create.js +0 -143
- package/dist/assertion/create.js.map +0 -1
- package/dist/assertion/format-assertion-failure.cjs +0 -63
- package/dist/assertion/format-assertion-failure.cjs.map +0 -1
- package/dist/assertion/format-assertion-failure.d.cts +0 -21
- package/dist/assertion/format-assertion-failure.d.cts.map +0 -1
- package/dist/assertion/format-assertion-failure.d.ts +0 -21
- package/dist/assertion/format-assertion-failure.d.ts.map +0 -1
- package/dist/assertion/format-assertion-failure.js +0 -59
- package/dist/assertion/format-assertion-failure.js.map +0 -1
- package/dist/assertion/impl/assertion-util.cjs +0 -68
- package/dist/assertion/impl/assertion-util.cjs.map +0 -1
- package/dist/assertion/impl/assertion-util.d.cts +0 -36
- package/dist/assertion/impl/assertion-util.d.cts.map +0 -1
- package/dist/assertion/impl/assertion-util.d.ts +0 -36
- package/dist/assertion/impl/assertion-util.d.ts.map +0 -1
- package/dist/assertion/impl/assertion-util.js +0 -62
- package/dist/assertion/impl/assertion-util.js.map +0 -1
- package/dist/assertion/impl/async-iterable.cjs +0 -627
- package/dist/assertion/impl/async-iterable.cjs.map +0 -1
- package/dist/assertion/impl/async-iterable.d.cts +0 -406
- package/dist/assertion/impl/async-iterable.d.cts.map +0 -1
- package/dist/assertion/impl/async-iterable.d.ts +0 -406
- package/dist/assertion/impl/async-iterable.d.ts.map +0 -1
- package/dist/assertion/impl/async-iterable.js +0 -624
- package/dist/assertion/impl/async-iterable.js.map +0 -1
- package/dist/assertion/impl/async-parametric.cjs +0 -423
- package/dist/assertion/impl/async-parametric.cjs.map +0 -1
- package/dist/assertion/impl/async-parametric.d.cts +0 -278
- package/dist/assertion/impl/async-parametric.d.cts.map +0 -1
- package/dist/assertion/impl/async-parametric.d.ts +0 -278
- package/dist/assertion/impl/async-parametric.d.ts.map +0 -1
- package/dist/assertion/impl/async-parametric.js +0 -420
- package/dist/assertion/impl/async-parametric.js.map +0 -1
- package/dist/assertion/impl/async.cjs +0 -56
- package/dist/assertion/impl/async.cjs.map +0 -1
- package/dist/assertion/impl/async.d.cts +0 -179
- package/dist/assertion/impl/async.d.cts.map +0 -1
- package/dist/assertion/impl/async.d.ts +0 -179
- package/dist/assertion/impl/async.d.ts.map +0 -1
- package/dist/assertion/impl/async.js +0 -39
- package/dist/assertion/impl/async.js.map +0 -1
- package/dist/assertion/impl/index.cjs +0 -37
- package/dist/assertion/impl/index.cjs.map +0 -1
- package/dist/assertion/impl/index.d.cts +0 -21
- package/dist/assertion/impl/index.d.cts.map +0 -1
- package/dist/assertion/impl/index.d.ts +0 -21
- package/dist/assertion/impl/index.d.ts.map +0 -1
- package/dist/assertion/impl/index.js +0 -21
- package/dist/assertion/impl/index.js.map +0 -1
- package/dist/assertion/impl/iteration-util.cjs +0 -297
- package/dist/assertion/impl/iteration-util.cjs.map +0 -1
- package/dist/assertion/impl/iteration-util.d.cts +0 -12
- package/dist/assertion/impl/iteration-util.d.cts.map +0 -1
- package/dist/assertion/impl/iteration-util.d.ts +0 -12
- package/dist/assertion/impl/iteration-util.d.ts.map +0 -1
- package/dist/assertion/impl/iteration-util.js +0 -282
- package/dist/assertion/impl/iteration-util.js.map +0 -1
- package/dist/assertion/impl/snapshot.cjs +0 -276
- package/dist/assertion/impl/snapshot.cjs.map +0 -1
- package/dist/assertion/impl/snapshot.d.cts +0 -278
- package/dist/assertion/impl/snapshot.d.cts.map +0 -1
- package/dist/assertion/impl/snapshot.d.ts +0 -278
- package/dist/assertion/impl/snapshot.d.ts.map +0 -1
- package/dist/assertion/impl/snapshot.js +0 -273
- package/dist/assertion/impl/snapshot.js.map +0 -1
- package/dist/assertion/impl/sync-basic.cjs +0 -553
- package/dist/assertion/impl/sync-basic.cjs.map +0 -1
- package/dist/assertion/impl/sync-basic.d.cts +0 -528
- package/dist/assertion/impl/sync-basic.d.cts.map +0 -1
- package/dist/assertion/impl/sync-basic.d.ts +0 -528
- package/dist/assertion/impl/sync-basic.d.ts.map +0 -1
- package/dist/assertion/impl/sync-basic.js +0 -550
- package/dist/assertion/impl/sync-basic.js.map +0 -1
- package/dist/assertion/impl/sync-collection.cjs +0 -856
- package/dist/assertion/impl/sync-collection.cjs.map +0 -1
- package/dist/assertion/impl/sync-collection.d.cts +0 -607
- package/dist/assertion/impl/sync-collection.d.cts.map +0 -1
- package/dist/assertion/impl/sync-collection.d.ts +0 -607
- package/dist/assertion/impl/sync-collection.d.ts.map +0 -1
- package/dist/assertion/impl/sync-collection.js +0 -850
- package/dist/assertion/impl/sync-collection.js.map +0 -1
- package/dist/assertion/impl/sync-date.cjs +0 -341
- package/dist/assertion/impl/sync-date.cjs.map +0 -1
- package/dist/assertion/impl/sync-date.d.cts +0 -209
- package/dist/assertion/impl/sync-date.d.cts.map +0 -1
- package/dist/assertion/impl/sync-date.d.ts +0 -209
- package/dist/assertion/impl/sync-date.d.ts.map +0 -1
- package/dist/assertion/impl/sync-date.js +0 -338
- package/dist/assertion/impl/sync-date.js.map +0 -1
- package/dist/assertion/impl/sync-esoteric.cjs +0 -214
- package/dist/assertion/impl/sync-esoteric.cjs.map +0 -1
- package/dist/assertion/impl/sync-esoteric.d.cts +0 -191
- package/dist/assertion/impl/sync-esoteric.d.cts.map +0 -1
- package/dist/assertion/impl/sync-esoteric.d.ts +0 -191
- package/dist/assertion/impl/sync-esoteric.d.ts.map +0 -1
- package/dist/assertion/impl/sync-esoteric.js +0 -211
- package/dist/assertion/impl/sync-esoteric.js.map +0 -1
- package/dist/assertion/impl/sync-iterable.cjs +0 -512
- package/dist/assertion/impl/sync-iterable.cjs.map +0 -1
- package/dist/assertion/impl/sync-iterable.d.cts +0 -334
- package/dist/assertion/impl/sync-iterable.d.cts.map +0 -1
- package/dist/assertion/impl/sync-iterable.d.ts +0 -334
- package/dist/assertion/impl/sync-iterable.d.ts.map +0 -1
- package/dist/assertion/impl/sync-iterable.js +0 -509
- package/dist/assertion/impl/sync-iterable.js.map +0 -1
- package/dist/assertion/impl/sync-parametric.cjs +0 -812
- package/dist/assertion/impl/sync-parametric.cjs.map +0 -1
- package/dist/assertion/impl/sync-parametric.d.cts +0 -560
- package/dist/assertion/impl/sync-parametric.d.cts.map +0 -1
- package/dist/assertion/impl/sync-parametric.d.ts +0 -560
- package/dist/assertion/impl/sync-parametric.d.ts.map +0 -1
- package/dist/assertion/impl/sync-parametric.js +0 -809
- package/dist/assertion/impl/sync-parametric.js.map +0 -1
- package/dist/assertion/impl/sync.cjs +0 -214
- package/dist/assertion/impl/sync.cjs.map +0 -1
- package/dist/assertion/impl/sync.d.cts +0 -512
- package/dist/assertion/impl/sync.d.cts.map +0 -1
- package/dist/assertion/impl/sync.d.ts +0 -512
- package/dist/assertion/impl/sync.d.ts.map +0 -1
- package/dist/assertion/impl/sync.js +0 -197
- package/dist/assertion/impl/sync.js.map +0 -1
- package/dist/assertion/index.cjs +0 -38
- package/dist/assertion/index.cjs.map +0 -1
- package/dist/assertion/index.d.cts +0 -18
- package/dist/assertion/index.d.cts.map +0 -1
- package/dist/assertion/index.d.ts +0 -18
- package/dist/assertion/index.d.ts.map +0 -1
- package/dist/assertion/index.js +0 -17
- package/dist/assertion/index.js.map +0 -1
- package/dist/assertion/slotify.cjs +0 -165
- package/dist/assertion/slotify.cjs.map +0 -1
- package/dist/assertion/slotify.d.cts +0 -11
- package/dist/assertion/slotify.d.cts.map +0 -1
- package/dist/assertion/slotify.d.ts +0 -11
- package/dist/assertion/slotify.d.ts.map +0 -1
- package/dist/assertion/slotify.js +0 -161
- package/dist/assertion/slotify.js.map +0 -1
- package/dist/bootstrap.cjs +0 -43
- package/dist/bootstrap.cjs.map +0 -1
- package/dist/bootstrap.d.cts +0 -27
- package/dist/bootstrap.d.cts.map +0 -1
- package/dist/bootstrap.d.ts +0 -27
- package/dist/bootstrap.d.ts.map +0 -1
- package/dist/bootstrap.js +0 -40
- package/dist/bootstrap.js.map +0 -1
- package/dist/constant.cjs +0 -82
- package/dist/constant.cjs.map +0 -1
- package/dist/constant.d.cts +0 -69
- package/dist/constant.d.cts.map +0 -1
- package/dist/constant.d.ts +0 -69
- package/dist/constant.d.ts.map +0 -1
- package/dist/constant.js +0 -79
- package/dist/constant.js.map +0 -1
- package/dist/diff.cjs +0 -340
- package/dist/diff.cjs.map +0 -1
- package/dist/diff.d.cts +0 -51
- package/dist/diff.d.cts.map +0 -1
- package/dist/diff.d.ts +0 -51
- package/dist/diff.d.ts.map +0 -1
- package/dist/diff.js +0 -334
- package/dist/diff.js.map +0 -1
- package/dist/error.cjs +0 -204
- package/dist/error.cjs.map +0 -1
- package/dist/error.d.cts +0 -212
- package/dist/error.d.cts.map +0 -1
- package/dist/error.d.ts +0 -212
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -191
- package/dist/error.js.map +0 -1
- package/dist/expect.cjs +0 -590
- package/dist/expect.cjs.map +0 -1
- package/dist/expect.d.cts +0 -138
- package/dist/expect.d.cts.map +0 -1
- package/dist/expect.d.ts +0 -138
- package/dist/expect.d.ts.map +0 -1
- package/dist/expect.js +0 -582
- package/dist/expect.js.map +0 -1
- package/dist/guards.cjs +0 -297
- package/dist/guards.cjs.map +0 -1
- package/dist/guards.d.cts +0 -231
- package/dist/guards.d.cts.map +0 -1
- package/dist/guards.d.ts +0 -231
- package/dist/guards.d.ts.map +0 -1
- package/dist/guards.js +0 -277
- package/dist/guards.js.map +0 -1
- package/dist/index.cjs +0 -111
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -448
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts +0 -448
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -71
- package/dist/index.js.map +0 -1
- package/dist/internal-schema.cjs +0 -253
- package/dist/internal-schema.cjs.map +0 -1
- package/dist/internal-schema.d.cts +0 -8
- package/dist/internal-schema.d.cts.map +0 -1
- package/dist/internal-schema.d.ts +0 -8
- package/dist/internal-schema.d.ts.map +0 -1
- package/dist/internal-schema.js +0 -248
- package/dist/internal-schema.js.map +0 -1
- package/dist/metadata.cjs +0 -57
- package/dist/metadata.cjs.map +0 -1
- package/dist/metadata.d.cts +0 -27
- package/dist/metadata.d.cts.map +0 -1
- package/dist/metadata.d.ts +0 -27
- package/dist/metadata.d.ts.map +0 -1
- package/dist/metadata.js +0 -54
- package/dist/metadata.js.map +0 -1
- package/dist/schema.cjs +0 -1522
- package/dist/schema.cjs.map +0 -1
- package/dist/schema.d.cts +0 -1196
- package/dist/schema.d.cts.map +0 -1
- package/dist/schema.d.ts +0 -1196
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -1516
- package/dist/schema.js.map +0 -1
- package/dist/snapshot/adapter.cjs +0 -31
- package/dist/snapshot/adapter.cjs.map +0 -1
- package/dist/snapshot/adapter.d.cts +0 -258
- package/dist/snapshot/adapter.d.cts.map +0 -1
- package/dist/snapshot/adapter.d.ts +0 -258
- package/dist/snapshot/adapter.d.ts.map +0 -1
- package/dist/snapshot/adapter.js +0 -27
- package/dist/snapshot/adapter.js.map +0 -1
- package/dist/snapshot/adapters/fallback.cjs +0 -453
- package/dist/snapshot/adapters/fallback.cjs.map +0 -1
- package/dist/snapshot/adapters/fallback.d.cts +0 -185
- package/dist/snapshot/adapters/fallback.d.cts.map +0 -1
- package/dist/snapshot/adapters/fallback.d.ts +0 -185
- package/dist/snapshot/adapters/fallback.d.ts.map +0 -1
- package/dist/snapshot/adapters/fallback.js +0 -446
- package/dist/snapshot/adapters/fallback.js.map +0 -1
- package/dist/snapshot/adapters/node-test.cjs +0 -301
- package/dist/snapshot/adapters/node-test.cjs.map +0 -1
- package/dist/snapshot/adapters/node-test.d.cts +0 -131
- package/dist/snapshot/adapters/node-test.d.cts.map +0 -1
- package/dist/snapshot/adapters/node-test.d.ts +0 -131
- package/dist/snapshot/adapters/node-test.d.ts.map +0 -1
- package/dist/snapshot/adapters/node-test.js +0 -297
- package/dist/snapshot/adapters/node-test.js.map +0 -1
- package/dist/snapshot/index.cjs +0 -61
- package/dist/snapshot/index.cjs.map +0 -1
- package/dist/snapshot/index.d.cts +0 -40
- package/dist/snapshot/index.d.cts.map +0 -1
- package/dist/snapshot/index.d.ts +0 -40
- package/dist/snapshot/index.d.ts.map +0 -1
- package/dist/snapshot/index.js +0 -44
- package/dist/snapshot/index.js.map +0 -1
- package/dist/snapshot/node-version.cjs +0 -49
- package/dist/snapshot/node-version.cjs.map +0 -1
- package/dist/snapshot/node-version.d.cts +0 -34
- package/dist/snapshot/node-version.d.cts.map +0 -1
- package/dist/snapshot/node-version.d.ts +0 -34
- package/dist/snapshot/node-version.d.ts.map +0 -1
- package/dist/snapshot/node-version.js +0 -44
- package/dist/snapshot/node-version.js.map +0 -1
- package/dist/snapshot/select-adapter.cjs +0 -170
- package/dist/snapshot/select-adapter.cjs.map +0 -1
- package/dist/snapshot/select-adapter.d.cts +0 -128
- package/dist/snapshot/select-adapter.d.cts.map +0 -1
- package/dist/snapshot/select-adapter.d.ts +0 -128
- package/dist/snapshot/select-adapter.d.ts.map +0 -1
- package/dist/snapshot/select-adapter.js +0 -164
- package/dist/snapshot/select-adapter.js.map +0 -1
- package/dist/snapshot/serializer.cjs +0 -246
- package/dist/snapshot/serializer.cjs.map +0 -1
- package/dist/snapshot/serializer.d.cts +0 -126
- package/dist/snapshot/serializer.d.cts.map +0 -1
- package/dist/snapshot/serializer.d.ts +0 -126
- package/dist/snapshot/serializer.d.ts.map +0 -1
- package/dist/snapshot/serializer.js +0 -238
- package/dist/snapshot/serializer.js.map +0 -1
- package/dist/standard-schema.cjs +0 -13
- package/dist/standard-schema.cjs.map +0 -1
- package/dist/standard-schema.d.cts +0 -192
- package/dist/standard-schema.d.cts.map +0 -1
- package/dist/standard-schema.d.ts +0 -192
- package/dist/standard-schema.d.ts.map +0 -1
- package/dist/standard-schema.js +0 -12
- package/dist/standard-schema.js.map +0 -1
- package/dist/types.cjs +0 -22
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -905
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts +0 -905
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -21
- package/dist/types.js.map +0 -1
- package/dist/use.cjs +0 -240
- package/dist/use.cjs.map +0 -1
- package/dist/use.d.cts +0 -8
- package/dist/use.d.cts.map +0 -1
- package/dist/use.d.ts +0 -8
- package/dist/use.d.ts.map +0 -1
- package/dist/use.js +0 -236
- package/dist/use.js.map +0 -1
- package/dist/util.cjs +0 -255
- package/dist/util.cjs.map +0 -1
- package/dist/util.d.cts +0 -141
- package/dist/util.d.cts.map +0 -1
- package/dist/util.d.ts +0 -141
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -234
- package/dist/util.js.map +0 -1
- package/dist/value-to-schema.cjs +0 -537
- package/dist/value-to-schema.cjs.map +0 -1
- package/dist/value-to-schema.d.cts +0 -144
- package/dist/value-to-schema.d.cts.map +0 -1
- package/dist/value-to-schema.d.ts +0 -144
- package/dist/value-to-schema.d.ts.map +0 -1
- package/dist/value-to-schema.js +0 -533
- package/dist/value-to-schema.js.map +0 -1
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fallback adapter for frameworks without native snapshot support.
|
|
3
|
-
*
|
|
4
|
-
* This adapter provides custom snapshot storage for test frameworks that don't
|
|
5
|
-
* have built-in snapshot functionality (e.g., Mocha, Tap, custom test
|
|
6
|
-
* runners).
|
|
7
|
-
*
|
|
8
|
-
* **Storage Format:** Snapshots are stored as CommonJS modules in
|
|
9
|
-
* `__snapshots__/` directories:
|
|
10
|
-
*
|
|
11
|
-
* ```javascript
|
|
12
|
-
* // __snapshots__/my-test.test.js.snap.cjs
|
|
13
|
-
* module.exports = {
|
|
14
|
-
* 'test name': '{\n "value": 42\n}',
|
|
15
|
-
* 'test name 2': '"another snapshot"',
|
|
16
|
-
* };
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @packageDocumentation
|
|
20
|
-
*/
|
|
21
|
-
import type { AssertionFailure } from "../../types.js";
|
|
22
|
-
import type { SnapshotAdapter, SnapshotContext, SnapshotOptions } from "../adapter.js";
|
|
23
|
-
/**
|
|
24
|
-
* Fallback adapter for frameworks without native snapshot support.
|
|
25
|
-
*
|
|
26
|
-
* This adapter provides custom snapshot storage and management for test
|
|
27
|
-
* frameworks that don't have built-in snapshot functionality.
|
|
28
|
-
*
|
|
29
|
-
* **Supported Contexts:**
|
|
30
|
-
*
|
|
31
|
-
* - **Mocha**: Pass `this` from test callback
|
|
32
|
-
* - **Explicit names**: Pass a string snapshot name
|
|
33
|
-
*
|
|
34
|
-
* **Storage:**
|
|
35
|
-
*
|
|
36
|
-
* - Snapshots stored in `__snapshots__/*.snap.cjs` files
|
|
37
|
-
* - CommonJS format for compatibility with both CJS and ESM projects
|
|
38
|
-
* - Sorted entries for consistent diffs
|
|
39
|
-
*
|
|
40
|
-
* **Update Mode:**
|
|
41
|
-
*
|
|
42
|
-
* - Controlled by `BUPKIS_UPDATE_SNAPSHOTS=1` environment variable
|
|
43
|
-
*
|
|
44
|
-
* **Features:**
|
|
45
|
-
*
|
|
46
|
-
* - Multiple snapshots per test (automatic counters)
|
|
47
|
-
* - Named snapshots via `hint` option
|
|
48
|
-
* - Circular reference detection
|
|
49
|
-
* - Non-JSON type handling
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
*
|
|
53
|
-
* ```typescript
|
|
54
|
-
* // Mocha usage
|
|
55
|
-
* describe('MyComponent', function() {
|
|
56
|
-
* it('renders', function() {
|
|
57
|
-
* const output = render(<MyComponent />);
|
|
58
|
-
* expect(output, 'to match snapshot', this);
|
|
59
|
-
* });
|
|
60
|
-
* });
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
*
|
|
65
|
-
* ```typescript
|
|
66
|
-
* // Explicit name (any framework)
|
|
67
|
-
* test('renders component', () => {
|
|
68
|
-
* const output = render(<MyComponent />);
|
|
69
|
-
* expect(output, 'to match snapshot', 'component-default-state');
|
|
70
|
-
* });
|
|
71
|
-
* ```
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
*
|
|
75
|
-
* ```typescript
|
|
76
|
-
* // Multiple snapshots with hints
|
|
77
|
-
* test('multi-step process', () => {
|
|
78
|
-
* expect(step1(), 'to match snapshot', 'step-1', { hint: 'initial' });
|
|
79
|
-
* expect(step2(), 'to match snapshot', 'step-2', { hint: 'processing' });
|
|
80
|
-
* expect(step3(), 'to match snapshot', 'step-3', { hint: 'complete' });
|
|
81
|
-
* });
|
|
82
|
-
* ```
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
*
|
|
86
|
-
* ```sh
|
|
87
|
-
* # Update snapshots
|
|
88
|
-
* BUPKIS_UPDATE_SNAPSHOTS=1 npm test
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
export declare class FallbackAdapter implements SnapshotAdapter {
|
|
92
|
-
/**
|
|
93
|
-
* Adapter name for identification and debugging.
|
|
94
|
-
*/
|
|
95
|
-
readonly name = "fallback";
|
|
96
|
-
/**
|
|
97
|
-
* Check if this adapter can handle the given context.
|
|
98
|
-
*
|
|
99
|
-
* The fallback adapter accepts both strings (explicit snapshot names) and
|
|
100
|
-
* objects (potential Mocha contexts). It's designed to be the last adapter in
|
|
101
|
-
* the selection chain and will accept most inputs.
|
|
102
|
-
*
|
|
103
|
-
* @param context - Test context or snapshot name
|
|
104
|
-
* @returns `true` for strings or objects
|
|
105
|
-
*/
|
|
106
|
-
canHandle(context: unknown): boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Extract snapshot context from Mocha context or string name.
|
|
109
|
-
*
|
|
110
|
-
* **For Mocha contexts:**
|
|
111
|
-
*
|
|
112
|
-
* - Extracts test name from `this.test.fullTitle()`
|
|
113
|
-
* - Gets file path from `this.test.file` or stack trace
|
|
114
|
-
*
|
|
115
|
-
* **For string contexts:**
|
|
116
|
-
*
|
|
117
|
-
* - Uses the string as the test name
|
|
118
|
-
* - Extracts file path from stack trace
|
|
119
|
-
*
|
|
120
|
-
* **Update mode:**
|
|
121
|
-
*
|
|
122
|
-
* - Checks `process.env.BUPKIS_UPDATE_SNAPSHOTS === '1'`
|
|
123
|
-
*
|
|
124
|
-
* @param context - Mocha context or string snapshot name
|
|
125
|
-
* @returns Normalized snapshot context
|
|
126
|
-
* @throws {TypeError} If context is neither a valid Mocha context nor a
|
|
127
|
-
* string
|
|
128
|
-
*/
|
|
129
|
-
getContext(context: unknown): SnapshotContext;
|
|
130
|
-
/**
|
|
131
|
-
* Perform snapshot assertion using custom storage.
|
|
132
|
-
*
|
|
133
|
-
* **Behavior:**
|
|
134
|
-
*
|
|
135
|
-
* - **Update mode**: Creates or updates the snapshot
|
|
136
|
-
* - **Comparison mode**: Loads existing snapshot and compares
|
|
137
|
-
*
|
|
138
|
-
* **Process:**
|
|
139
|
-
*
|
|
140
|
-
* 1. Serialize the value using provided serializer or default
|
|
141
|
-
* 2. Generate unique snapshot name (with counter if needed)
|
|
142
|
-
* 3. Load existing snapshot store from disk
|
|
143
|
-
* 4. Either update snapshot or compare and throw on mismatch
|
|
144
|
-
*
|
|
145
|
-
* @example
|
|
146
|
-
*
|
|
147
|
-
* ```typescript
|
|
148
|
-
* const adapter = new FallbackAdapter();
|
|
149
|
-
*
|
|
150
|
-
* // With Mocha context
|
|
151
|
-
* adapter.assertSnapshot({ foo: 'bar' }, mochaThis);
|
|
152
|
-
*
|
|
153
|
-
* // With explicit name
|
|
154
|
-
* adapter.assertSnapshot({ foo: 'bar' }, 'my-snapshot');
|
|
155
|
-
*
|
|
156
|
-
* // With custom serializer
|
|
157
|
-
* adapter.assertSnapshot(data, 'test', {
|
|
158
|
-
* serializer: (v) => JSON.stringify(v, null, 2),
|
|
159
|
-
* });
|
|
160
|
-
* ```
|
|
161
|
-
*
|
|
162
|
-
* @param value - Value to snapshot
|
|
163
|
-
* @param context - Mocha context or string name
|
|
164
|
-
* @param options - Optional serializer and hint
|
|
165
|
-
* @throws {TypeError} If context is invalid
|
|
166
|
-
* @throws {AssertionError} If snapshot doesn't match (in comparison mode)
|
|
167
|
-
*/
|
|
168
|
-
validateSnapshot(value: unknown, context: unknown, options?: SnapshotOptions): AssertionFailure | void;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Singleton instance of the fallback adapter.
|
|
172
|
-
*
|
|
173
|
-
* This is the primary export and should be used for adapter registration.
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
*
|
|
177
|
-
* ```typescript
|
|
178
|
-
* import { fallbackAdapter } from 'bupkis/snapshot';
|
|
179
|
-
* import { registerAdapter } from 'bupkis/snapshot';
|
|
180
|
-
*
|
|
181
|
-
* registerAdapter(fallbackAdapter);
|
|
182
|
-
* ```
|
|
183
|
-
*/
|
|
184
|
-
export declare const fallbackAdapter: FallbackAdapter;
|
|
185
|
-
//# sourceMappingURL=fallback.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.d.ts","sourceRoot":"","sources":["../../../src/snapshot/adapters/fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB;AACvD,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,eAAe,EAChB,sBAAsB;AAwPvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,qBAAa,eAAgB,YAAW,eAAe;IACrD;;OAEG;IACH,QAAQ,CAAC,IAAI,cAAc;IAE3B;;;;;;;;;OASG;IACH,SAAS,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAKpC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;IAsB7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,gBAAgB,CACd,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,eAAe,GACxB,gBAAgB,GAAG,IAAI;CA2B3B;AAoCD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,iBAAwB,CAAC"}
|
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fallback adapter for frameworks without native snapshot support.
|
|
3
|
-
*
|
|
4
|
-
* This adapter provides custom snapshot storage for test frameworks that don't
|
|
5
|
-
* have built-in snapshot functionality (e.g., Mocha, Tap, custom test
|
|
6
|
-
* runners).
|
|
7
|
-
*
|
|
8
|
-
* **Storage Format:** Snapshots are stored as CommonJS modules in
|
|
9
|
-
* `__snapshots__/` directories:
|
|
10
|
-
*
|
|
11
|
-
* ```javascript
|
|
12
|
-
* // __snapshots__/my-test.test.js.snap.cjs
|
|
13
|
-
* module.exports = {
|
|
14
|
-
* 'test name': '{\n "value": 42\n}',
|
|
15
|
-
* 'test name 2': '"another snapshot"',
|
|
16
|
-
* };
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @packageDocumentation
|
|
20
|
-
*/
|
|
21
|
-
import stringify from 'json-stable-stringify';
|
|
22
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
23
|
-
import { dirname, join, relative, resolve } from 'node:path';
|
|
24
|
-
import { defaultSerializer } from "../serializer.js";
|
|
25
|
-
const { entries } = Object;
|
|
26
|
-
/**
|
|
27
|
-
* Extract snapshot context from Mocha's `this` context.
|
|
28
|
-
*
|
|
29
|
-
* Mocha provides test information through `this.test` in test callbacks. This
|
|
30
|
-
* function attempts to extract the test name and file path from that
|
|
31
|
-
* structure.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
*
|
|
35
|
-
* ```typescript
|
|
36
|
-
* describe('suite', function () {
|
|
37
|
-
* it('test', function () {
|
|
38
|
-
* const ctx = extractMochaContext(this);
|
|
39
|
-
* // ctx = {
|
|
40
|
-
* // testPath: 'suite test',
|
|
41
|
-
* // filePath: '/path/to/test.js',
|
|
42
|
-
* // isUpdateMode: false
|
|
43
|
-
* // }
|
|
44
|
-
* });
|
|
45
|
-
* });
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @function
|
|
49
|
-
* @param context - Potential Mocha context object
|
|
50
|
-
* @returns Snapshot context if Mocha context detected, null otherwise
|
|
51
|
-
*/
|
|
52
|
-
const extractMochaContext = (context) => {
|
|
53
|
-
const mochaCtx = context;
|
|
54
|
-
if (mochaCtx?.test?.fullTitle) {
|
|
55
|
-
return {
|
|
56
|
-
filePath: mochaCtx.test.file || getTestFilePathFromStack(),
|
|
57
|
-
isUpdateMode: process.env.BUPKIS_UPDATE_SNAPSHOTS === '1',
|
|
58
|
-
testPath: mochaCtx.test.fullTitle(),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Get snapshot file path for a test file.
|
|
65
|
-
*
|
|
66
|
-
* Snapshots are stored in a `__snapshots__/` directory next to the test file.
|
|
67
|
-
* The snapshot filename is based on the test file path, with slashes replaced
|
|
68
|
-
* by dashes to create a flat structure.
|
|
69
|
-
*
|
|
70
|
-
* Uses `.cjs` extension for CommonJS compatibility in both CJS and ESM
|
|
71
|
-
* projects.
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
*
|
|
75
|
-
* ```typescript
|
|
76
|
-
* getSnapshotFilePath('/project/test/unit/foo.test.ts');
|
|
77
|
-
* // Returns: '/project/test/unit/__snapshots__/test-unit-foo.test.ts.snap.cjs'
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* @function
|
|
81
|
-
* @param testFilePath - Absolute path to the test file
|
|
82
|
-
* @returns Absolute path to the snapshot file
|
|
83
|
-
*/
|
|
84
|
-
const getSnapshotFilePath = (testFilePath) => {
|
|
85
|
-
const dir = dirname(testFilePath);
|
|
86
|
-
const snapshotDir = join(dir, '__snapshots__');
|
|
87
|
-
const filename = relative(process.cwd(), testFilePath).replace(/\//g, '-');
|
|
88
|
-
return join(snapshotDir, `${filename}.snap.cjs`);
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Get test file path from stack trace.
|
|
92
|
-
*
|
|
93
|
-
* Searches the stack trace for lines containing test file paths. Looks for
|
|
94
|
-
* files matching patterns like `*.test.js`, `*.spec.ts`, etc.
|
|
95
|
-
*
|
|
96
|
-
* @function
|
|
97
|
-
* @returns Absolute path to test file, or 'unknown.test.js' if not found
|
|
98
|
-
*/
|
|
99
|
-
const getTestFilePathFromStack = () => {
|
|
100
|
-
const stack = new Error().stack || '';
|
|
101
|
-
const lines = stack.split('\n');
|
|
102
|
-
for (const line of lines) {
|
|
103
|
-
// Match file paths in stack traces
|
|
104
|
-
const match = line.match(/\((.+\.(?:test|spec)\.[jt]s):\d+:\d+\)/);
|
|
105
|
-
if (match && match[1]) {
|
|
106
|
-
return resolve(match[1]);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return resolve('unknown.test.js');
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Load snapshots from a snapshot file.
|
|
113
|
-
*
|
|
114
|
-
* Reads and parses the CommonJS format snapshot file. If the file doesn't exist
|
|
115
|
-
* or can't be parsed, returns an empty store.
|
|
116
|
-
*
|
|
117
|
-
* **Expected format:**
|
|
118
|
-
*
|
|
119
|
-
* ```javascript
|
|
120
|
-
* module.exports = {
|
|
121
|
-
* 'test name': '{"value": 42}',
|
|
122
|
-
* 'another test': '"string"',
|
|
123
|
-
* };
|
|
124
|
-
* ```
|
|
125
|
-
*
|
|
126
|
-
* @example
|
|
127
|
-
*
|
|
128
|
-
* ```typescript
|
|
129
|
-
* const store = loadSnapshots('/path/to/__snapshots__/test.snap.cjs');
|
|
130
|
-
* console.log(store['my test']); // '{"foo": "bar"}'
|
|
131
|
-
* ```
|
|
132
|
-
*
|
|
133
|
-
* @function
|
|
134
|
-
* @param snapshotPath - Path to the snapshot file
|
|
135
|
-
* @returns Snapshot store (test name → serialized value)
|
|
136
|
-
*/
|
|
137
|
-
const loadSnapshots = (snapshotPath) => {
|
|
138
|
-
if (!existsSync(snapshotPath)) {
|
|
139
|
-
return {};
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
// Read as CommonJS module
|
|
143
|
-
const content = readFileSync(snapshotPath, 'utf-8');
|
|
144
|
-
// Parse the module.exports = { ... } format
|
|
145
|
-
const match = content.match(/module\.exports\s*=\s*(\{[\s\S]*\});?\s*$/);
|
|
146
|
-
if (match) {
|
|
147
|
-
// Use Function constructor to safely eval the object literal
|
|
148
|
-
// This is safe because we're only parsing the object structure,
|
|
149
|
-
// not executing arbitrary code
|
|
150
|
-
// eslint-disable-next-line @typescript-eslint/no-implied-eval, @typescript-eslint/no-unsafe-call
|
|
151
|
-
const store = new Function(`return ${match[1]}`)();
|
|
152
|
-
return store;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
catch {
|
|
156
|
-
// If parsing fails, return empty store
|
|
157
|
-
// This allows for snapshot regeneration
|
|
158
|
-
}
|
|
159
|
-
return {};
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Save snapshots to a snapshot file.
|
|
163
|
-
*
|
|
164
|
-
* Writes the snapshot store to disk in CommonJS format. Creates the
|
|
165
|
-
* `__snapshots__/` directory if it doesn't exist. Entries are sorted
|
|
166
|
-
* alphabetically by test name for consistency.
|
|
167
|
-
*
|
|
168
|
-
* **Output format:**
|
|
169
|
-
*
|
|
170
|
-
* ```javascript
|
|
171
|
-
* module.exports = {
|
|
172
|
-
* 'test 1': '{"value": 1}',
|
|
173
|
-
* 'test 2': '{"value": 2}',
|
|
174
|
-
* };
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
*
|
|
179
|
-
* ```typescript
|
|
180
|
-
* const store = {
|
|
181
|
-
* 'my test': '{"foo": "bar"}',
|
|
182
|
-
* 'another test': '"string"',
|
|
183
|
-
* };
|
|
184
|
-
* saveSnapshots('/path/to/__snapshots__/test.snap.cjs', store);
|
|
185
|
-
* ```
|
|
186
|
-
*
|
|
187
|
-
* @function
|
|
188
|
-
* @param snapshotPath - Path to the snapshot file
|
|
189
|
-
* @param store - Snapshot store to save
|
|
190
|
-
*/
|
|
191
|
-
const saveSnapshots = (snapshotPath, store) => {
|
|
192
|
-
const dir = dirname(snapshotPath);
|
|
193
|
-
// Ensure directory exists
|
|
194
|
-
if (!existsSync(dir)) {
|
|
195
|
-
mkdirSync(dir, { recursive: true });
|
|
196
|
-
}
|
|
197
|
-
// Generate CommonJS module format with sorted entries
|
|
198
|
-
const snapshotEntries = entries(store)
|
|
199
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
200
|
-
.map(([key, value]) => ` ${stringify(key)}: ${stringify(value)}`)
|
|
201
|
-
.join(',\n');
|
|
202
|
-
const content = `module.exports = {\n${snapshotEntries}\n};\n`;
|
|
203
|
-
writeFileSync(snapshotPath, content, 'utf-8');
|
|
204
|
-
};
|
|
205
|
-
/**
|
|
206
|
-
* Snapshot counters for multiple snapshots per test.
|
|
207
|
-
*
|
|
208
|
-
* Tracks how many snapshots have been taken for each test path to generate
|
|
209
|
-
* unique snapshot names when a test has multiple snapshots.
|
|
210
|
-
*/
|
|
211
|
-
const snapshotCounters = new Map();
|
|
212
|
-
/**
|
|
213
|
-
* Fallback adapter for frameworks without native snapshot support.
|
|
214
|
-
*
|
|
215
|
-
* This adapter provides custom snapshot storage and management for test
|
|
216
|
-
* frameworks that don't have built-in snapshot functionality.
|
|
217
|
-
*
|
|
218
|
-
* **Supported Contexts:**
|
|
219
|
-
*
|
|
220
|
-
* - **Mocha**: Pass `this` from test callback
|
|
221
|
-
* - **Explicit names**: Pass a string snapshot name
|
|
222
|
-
*
|
|
223
|
-
* **Storage:**
|
|
224
|
-
*
|
|
225
|
-
* - Snapshots stored in `__snapshots__/*.snap.cjs` files
|
|
226
|
-
* - CommonJS format for compatibility with both CJS and ESM projects
|
|
227
|
-
* - Sorted entries for consistent diffs
|
|
228
|
-
*
|
|
229
|
-
* **Update Mode:**
|
|
230
|
-
*
|
|
231
|
-
* - Controlled by `BUPKIS_UPDATE_SNAPSHOTS=1` environment variable
|
|
232
|
-
*
|
|
233
|
-
* **Features:**
|
|
234
|
-
*
|
|
235
|
-
* - Multiple snapshots per test (automatic counters)
|
|
236
|
-
* - Named snapshots via `hint` option
|
|
237
|
-
* - Circular reference detection
|
|
238
|
-
* - Non-JSON type handling
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
*
|
|
242
|
-
* ```typescript
|
|
243
|
-
* // Mocha usage
|
|
244
|
-
* describe('MyComponent', function() {
|
|
245
|
-
* it('renders', function() {
|
|
246
|
-
* const output = render(<MyComponent />);
|
|
247
|
-
* expect(output, 'to match snapshot', this);
|
|
248
|
-
* });
|
|
249
|
-
* });
|
|
250
|
-
* ```
|
|
251
|
-
*
|
|
252
|
-
* @example
|
|
253
|
-
*
|
|
254
|
-
* ```typescript
|
|
255
|
-
* // Explicit name (any framework)
|
|
256
|
-
* test('renders component', () => {
|
|
257
|
-
* const output = render(<MyComponent />);
|
|
258
|
-
* expect(output, 'to match snapshot', 'component-default-state');
|
|
259
|
-
* });
|
|
260
|
-
* ```
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
*
|
|
264
|
-
* ```typescript
|
|
265
|
-
* // Multiple snapshots with hints
|
|
266
|
-
* test('multi-step process', () => {
|
|
267
|
-
* expect(step1(), 'to match snapshot', 'step-1', { hint: 'initial' });
|
|
268
|
-
* expect(step2(), 'to match snapshot', 'step-2', { hint: 'processing' });
|
|
269
|
-
* expect(step3(), 'to match snapshot', 'step-3', { hint: 'complete' });
|
|
270
|
-
* });
|
|
271
|
-
* ```
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
*
|
|
275
|
-
* ```sh
|
|
276
|
-
* # Update snapshots
|
|
277
|
-
* BUPKIS_UPDATE_SNAPSHOTS=1 npm test
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
export class FallbackAdapter {
|
|
281
|
-
/**
|
|
282
|
-
* Adapter name for identification and debugging.
|
|
283
|
-
*/
|
|
284
|
-
name = 'fallback';
|
|
285
|
-
/**
|
|
286
|
-
* Check if this adapter can handle the given context.
|
|
287
|
-
*
|
|
288
|
-
* The fallback adapter accepts both strings (explicit snapshot names) and
|
|
289
|
-
* objects (potential Mocha contexts). It's designed to be the last adapter in
|
|
290
|
-
* the selection chain and will accept most inputs.
|
|
291
|
-
*
|
|
292
|
-
* @param context - Test context or snapshot name
|
|
293
|
-
* @returns `true` for strings or objects
|
|
294
|
-
*/
|
|
295
|
-
canHandle(context) {
|
|
296
|
-
// Fallback handles strings (explicit names) and objects (Mocha)
|
|
297
|
-
return typeof context === 'string' || typeof context === 'object';
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Extract snapshot context from Mocha context or string name.
|
|
301
|
-
*
|
|
302
|
-
* **For Mocha contexts:**
|
|
303
|
-
*
|
|
304
|
-
* - Extracts test name from `this.test.fullTitle()`
|
|
305
|
-
* - Gets file path from `this.test.file` or stack trace
|
|
306
|
-
*
|
|
307
|
-
* **For string contexts:**
|
|
308
|
-
*
|
|
309
|
-
* - Uses the string as the test name
|
|
310
|
-
* - Extracts file path from stack trace
|
|
311
|
-
*
|
|
312
|
-
* **Update mode:**
|
|
313
|
-
*
|
|
314
|
-
* - Checks `process.env.BUPKIS_UPDATE_SNAPSHOTS === '1'`
|
|
315
|
-
*
|
|
316
|
-
* @param context - Mocha context or string snapshot name
|
|
317
|
-
* @returns Normalized snapshot context
|
|
318
|
-
* @throws {TypeError} If context is neither a valid Mocha context nor a
|
|
319
|
-
* string
|
|
320
|
-
*/
|
|
321
|
-
getContext(context) {
|
|
322
|
-
// Try Mocha first
|
|
323
|
-
const mochaContext = extractMochaContext(context);
|
|
324
|
-
if (mochaContext) {
|
|
325
|
-
return mochaContext;
|
|
326
|
-
}
|
|
327
|
-
// String context (explicit snapshot name)
|
|
328
|
-
if (typeof context === 'string') {
|
|
329
|
-
return {
|
|
330
|
-
filePath: getTestFilePathFromStack(),
|
|
331
|
-
isUpdateMode: process.env.BUPKIS_UPDATE_SNAPSHOTS === '1',
|
|
332
|
-
testPath: context,
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
throw new TypeError('Fallback adapter requires either a string snapshot name or Mocha context. ' +
|
|
336
|
-
'Pass test name as string: expect(value, "to match snapshot", "my-test-name")');
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Perform snapshot assertion using custom storage.
|
|
340
|
-
*
|
|
341
|
-
* **Behavior:**
|
|
342
|
-
*
|
|
343
|
-
* - **Update mode**: Creates or updates the snapshot
|
|
344
|
-
* - **Comparison mode**: Loads existing snapshot and compares
|
|
345
|
-
*
|
|
346
|
-
* **Process:**
|
|
347
|
-
*
|
|
348
|
-
* 1. Serialize the value using provided serializer or default
|
|
349
|
-
* 2. Generate unique snapshot name (with counter if needed)
|
|
350
|
-
* 3. Load existing snapshot store from disk
|
|
351
|
-
* 4. Either update snapshot or compare and throw on mismatch
|
|
352
|
-
*
|
|
353
|
-
* @example
|
|
354
|
-
*
|
|
355
|
-
* ```typescript
|
|
356
|
-
* const adapter = new FallbackAdapter();
|
|
357
|
-
*
|
|
358
|
-
* // With Mocha context
|
|
359
|
-
* adapter.assertSnapshot({ foo: 'bar' }, mochaThis);
|
|
360
|
-
*
|
|
361
|
-
* // With explicit name
|
|
362
|
-
* adapter.assertSnapshot({ foo: 'bar' }, 'my-snapshot');
|
|
363
|
-
*
|
|
364
|
-
* // With custom serializer
|
|
365
|
-
* adapter.assertSnapshot(data, 'test', {
|
|
366
|
-
* serializer: (v) => JSON.stringify(v, null, 2),
|
|
367
|
-
* });
|
|
368
|
-
* ```
|
|
369
|
-
*
|
|
370
|
-
* @param value - Value to snapshot
|
|
371
|
-
* @param context - Mocha context or string name
|
|
372
|
-
* @param options - Optional serializer and hint
|
|
373
|
-
* @throws {TypeError} If context is invalid
|
|
374
|
-
* @throws {AssertionError} If snapshot doesn't match (in comparison mode)
|
|
375
|
-
*/
|
|
376
|
-
validateSnapshot(value, context, options) {
|
|
377
|
-
const ctx = this.getContext(context);
|
|
378
|
-
const serializer = options?.serializer || defaultSerializer;
|
|
379
|
-
const snapshotName = getSnapshotName(ctx.testPath, options?.hint);
|
|
380
|
-
const snapshotPath = getSnapshotFilePath(ctx.filePath);
|
|
381
|
-
const store = loadSnapshots(snapshotPath);
|
|
382
|
-
const actual = serializer(value);
|
|
383
|
-
const expected = store[snapshotName];
|
|
384
|
-
if (ctx.isUpdateMode || expected === undefined) {
|
|
385
|
-
// Update/create snapshot
|
|
386
|
-
store[snapshotName] = actual;
|
|
387
|
-
saveSnapshots(snapshotPath, store);
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
// Compare snapshots
|
|
391
|
-
if (actual !== expected) {
|
|
392
|
-
return {
|
|
393
|
-
actual,
|
|
394
|
-
expected,
|
|
395
|
-
message: `Snapshot mismatch for "${snapshotName}"\n\nExpected:\n${expected}\n\nActual:\n${actual}`,
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Get the next snapshot name for a test.
|
|
402
|
-
*
|
|
403
|
-
* For the first snapshot in a test, uses the test path as-is. For subsequent
|
|
404
|
-
* snapshots, appends a counter: `"test name 2"`, `"test name 3"`, etc.
|
|
405
|
-
*
|
|
406
|
-
* If a hint is provided, it's appended in brackets: `"test name [hint]"`.
|
|
407
|
-
*
|
|
408
|
-
* @example
|
|
409
|
-
*
|
|
410
|
-
* ```typescript
|
|
411
|
-
* getSnapshotName('MyComponent renders'); // 'MyComponent renders'
|
|
412
|
-
* getSnapshotName('MyComponent renders'); // 'MyComponent renders 2'
|
|
413
|
-
* getSnapshotName('MyComponent renders'); // 'MyComponent renders 3'
|
|
414
|
-
*
|
|
415
|
-
* getSnapshotName('test', 'initial state'); // 'test [initial state]'
|
|
416
|
-
* ```
|
|
417
|
-
*
|
|
418
|
-
* @function
|
|
419
|
-
* @param testPath - Full test path/name
|
|
420
|
-
* @param hint - Optional descriptive hint
|
|
421
|
-
* @returns Unique snapshot name
|
|
422
|
-
*/
|
|
423
|
-
const getSnapshotName = (testPath, hint) => {
|
|
424
|
-
if (hint) {
|
|
425
|
-
return `${testPath} [${hint}]`;
|
|
426
|
-
}
|
|
427
|
-
const counter = snapshotCounters.get(testPath) || 0;
|
|
428
|
-
snapshotCounters.set(testPath, counter + 1);
|
|
429
|
-
return counter === 0 ? testPath : `${testPath} ${counter + 1}`;
|
|
430
|
-
};
|
|
431
|
-
/**
|
|
432
|
-
* Singleton instance of the fallback adapter.
|
|
433
|
-
*
|
|
434
|
-
* This is the primary export and should be used for adapter registration.
|
|
435
|
-
*
|
|
436
|
-
* @example
|
|
437
|
-
*
|
|
438
|
-
* ```typescript
|
|
439
|
-
* import { fallbackAdapter } from 'bupkis/snapshot';
|
|
440
|
-
* import { registerAdapter } from 'bupkis/snapshot';
|
|
441
|
-
*
|
|
442
|
-
* registerAdapter(fallbackAdapter);
|
|
443
|
-
* ```
|
|
444
|
-
*/
|
|
445
|
-
export const fallbackAdapter = new FallbackAdapter();
|
|
446
|
-
//# sourceMappingURL=fallback.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.js","sourceRoot":"","sources":["../../../src/snapshot/adapters/fallback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,SAAS,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAS7D,OAAO,EAAE,iBAAiB,EAAE,yBAAyB;AAErD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;AA0C3B;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,mBAAmB,GAAG,CAAC,OAAgB,EAA0B,EAAE;IACvE,MAAM,QAAQ,GAAG,OAAuB,CAAC;IAEzC,IAAI,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC9B,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,wBAAwB,EAAE;YAC1D,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,GAAG;YACzD,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE;SACpC,CAAC;IAC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