CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-storybook--addon-backgrounds

Deprecated Storybook addon that throws migration errors directing users to the new package structure in Storybook 9.0

86

1.08x
Overview
Eval results
Files

task.mdevals/scenario-5/

Story Event Monitor

Build a monitoring utility that listens to and tracks specific Storybook events during story lifecycle and displays statistics about story rendering activity.

Requirements

Your solution should:

  1. Create an event monitor that connects to the Storybook channel
  2. Listen for story rendering events and track their occurrences
  3. Implement a function that registers event listeners for multiple event types
  4. Maintain counters for how many times each event type has been triggered
  5. Provide a function to retrieve the current statistics as a map of event types to counts
  6. Include proper cleanup functionality to remove event listeners

The monitor should track at least the following event types:

  • Story rendering started
  • Story rendering completed
  • Story arguments changed
  • Story errors occurred

Test Cases

The following test cases should pass:

  • When a story render starts event is emitted, the counter for that event type increases @test
  • When multiple different events are emitted, each counter tracks its respective event type correctly @test
  • The statistics retrieval function returns accurate counts for all tracked events @test
  • After cleanup is called, no further events are tracked @test

Implementation

@generates

API

/**
 * Creates and initializes a story event monitor
 * @param channel - The Storybook channel to listen on
 * @returns An object with methods to get statistics and cleanup
 */
export function createEventMonitor(channel: any): {
  getStatistics: () => Record<string, number>;
  cleanup: () => void;
};

Dependencies { .dependencies }

@storybook/core-events { .dependency }

Provides event type definitions and constants for Storybook events.

@storybook/channels { .dependency }

Provides the channel abstraction for event communication in Storybook.

Install with Tessl CLI

npx tessl i tessl/npm-storybook--addon-backgrounds

tile.json