BUPKIS
    Preparing search index...

    Interface SnapshotAdapter

    Adapter for framework-specific snapshot operations.

    Each test framework (node:test, Jest, Vitest, Mocha, etc.) has its own way of providing test context and storing snapshots. Adapters abstract these differences and provide a unified interface.

    class NodeTestAdapter implements SnapshotAdapter {
    readonly name = 'node:test';

    canHandle(context: unknown): boolean {
    return (
    typeof context === 'object' &&
    context !== null &&
    'assert' in context &&
    typeof (context as any).assert?.snapshot === 'function'
    );
    }

    getContext(context: unknown): SnapshotContext {
    // Extract test name, file path, update mode from node:test context
    }

    assertSnapshot(
    value: unknown,
    context: unknown,
    options?: SnapshotOptions,
    ): void {
    // Delegate to context.assert.snapshot()
    }
    }
    interface SnapshotAdapter {
        name: string;
        canHandle(context: unknown): boolean;
        getContext(context: unknown): SnapshotContext;
        validateSnapshot(
            value: unknown,
            context: unknown,
            options?: SnapshotOptions,
        ): void | AssertionFailure;
    }
    Index

    Methods

    • Check if this adapter can handle the given test context.

      This is used for adapter selection. Adapters are checked in priority order, and the first adapter that returns true is used.

      Parameters

      • context: unknown

        Test context object from the test framework

      Returns boolean

      true if this adapter can handle the context

      canHandle(context: unknown): boolean {
      // Check for node:test-specific properties
      return typeof context === 'object' &&
      context !== null &&
      'assert' in context &&
      typeof (context as any).assert?.snapshot === 'function';
      }
    • Extract normalized snapshot context from framework-specific context.

      This method should extract the test name/path, file path, and update mode from the framework's test context object.

      Parameters

      • context: unknown

        Test context object from the test framework

      Returns SnapshotContext

      Normalized snapshot context

      getContext(context: unknown): SnapshotContext {
      const ctx = context as NodeTestContext;
      return {
      testPath: ctx.name,
      filePath: getFilePathFromStack(),
      isUpdateMode: process.argv.includes('--test-update-snapshots')
      };
      }

      If the context is invalid for this adapter

    • Perform the snapshot assertion.

      This method should either:

      • Compare the value against the existing snapshot and throw if different
      • Create/update the snapshot if in update mode

      Parameters

      • value: unknown

        The value to snapshot

      • context: unknown

        Test context object from the test framework

      • Optionaloptions: SnapshotOptions

        Optional serialization and naming options

      Returns void | AssertionFailure

      AssertionFailure If the snapshot doesn't match, void otherwise

      assertSnapshot(value: unknown, context: unknown, options?: SnapshotOptions): void {
      const ctx = this.getContext(context);
      const serialized = options?.serializer?.(value) ?? defaultSerializer(value);

      if (ctx.isUpdateMode) {
      saveSnapshot(ctx.testPath, serialized);
      } else {
      const expected = loadSnapshot(ctx.testPath);
      if (serialized !== expected) {
      throw new AssertionError('Snapshot mismatch');
      }
      }
      }

    Properties

    name: string

    Adapter name for debugging and logging.

    'node:test';
    'jest';
    'fallback';