storybookjs / storybook

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation
https://storybook.js.org
MIT License
83.94k stars 9.21k forks source link

Storybook Coverage Viewer Addon - Create UI for Displaying Coverage Data #28631

Closed valentinpalkovic closed 2 weeks ago

valentinpalkovic commented 1 month ago

To provide a seamless user experience, we need to develop a Storybook addon UI that can display the coverage data collected from Vitest. This UI should present comprehensive and detailed coverage information for each component, including all relevant files, in a user-friendly and interactive manner. The goal is to allow developers to quickly understand the test coverage of their components and identify areas that need more testing.

Tasks

Design UI Layout

Implement Coverage Summary Section

Implement Detailed File Coverage View

Real-Time Coverage Updates

Acceptance Criteria

greptile-apps[bot] commented 1 month ago

Disclaimer This information might be inaccurate, due to it being generated automatically

  1. In addons/coverage/src/index.ts, register the addon:
    
    import { addons, types } from '@storybook/addons';
    import { ADDON_ID, PANEL_ID } from './constants';
    import { CoveragePanel } from './CoveragePanel';

addons.register(ADDON_ID, () => { addons.add(PANEL_ID, { type: types.PANEL, title: 'Coverage', render: CoveragePanel, }); });


2. Create `addons/coverage/src/CoveragePanel.tsx` for the UI:
```typescript
import React from 'react';
import { useParameter } from '@storybook/api';
import { PARAM_KEY } from './constants';

export const CoveragePanel: React.FC = () => {
  const coverageData = useParameter(PARAM_KEY, null);
  return (
    <div>
      {coverageData ? (
        <pre>{JSON.stringify(coverageData, null, 2)}</pre>
      ) : (
        <p>No coverage data available</p>
      )}
    </div>
  );
};
  1. Update addons/coverage/src/constants.ts:

    export const ADDON_ID = 'storybook/coverage';
    export const PANEL_ID = `${ADDON_ID}/panel`;
    export const PARAM_KEY = 'coverage';
  2. Modify addons/coverage/src/preview.ts to set coverage data:

    
    import { addons } from '@storybook/addons';
    import { PARAM_KEY } from './constants';

addons.setConfig({ [PARAM_KEY]: window.coverage || null, });



<details>
<summary>

#### About Greptile
</summary>

This response provides a starting point for your research, not a precise solution.

Help us improve! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

[Edit Issue Bot Settings](https://app.greptile.com/apps/github)
</details>
valentinpalkovic commented 2 weeks ago

Completed