-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclude unnecessarily tracked coverage files #30639
Open
kpowkitty
wants to merge
2
commits into
storybookjs:next
Choose a base branch
from
kpowkitty:exclude-coverage
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+67
−45
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,70 @@ | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import React, { useMemo, useState } from 'react'; | ||
|
||
import { type API_LeafEntry, Addon_TypesEnum } from '@storybook/core/types'; | ||
import { Addon_TypesEnum } from '@storybook/core/types'; | ||
|
||
import { Consumer } from '@storybook/core/manager-api'; | ||
import type { API, Combo } from '@storybook/core/manager-api'; | ||
|
||
import memoize from 'memoizerific'; | ||
import { useChannel, useStorybookApi, useStorybookState } from '@storybook/core/manager-api'; | ||
|
||
import { STORY_PREPARED } from '../../core-events'; | ||
import { AddonPanel } from '../components/panel/Panel'; | ||
|
||
const createPanelActions = memoize(1)((api) => ({ | ||
onSelect: (panel: string) => api.setSelectedPanel(panel), | ||
toggleVisibility: () => api.togglePanel(), | ||
togglePosition: () => api.togglePanelPosition(), | ||
})); | ||
const Panel: FC<any> = (props) => { | ||
const api = useStorybookApi(); | ||
const state = useStorybookState(); | ||
const [story, setStory] = useState(api.getCurrentStoryData()); | ||
|
||
const getPanels = memoize(1)((api: API, story: API_LeafEntry) => { | ||
const allPanels = api.getElements(Addon_TypesEnum.PANEL); | ||
useChannel( | ||
{ | ||
[STORY_PREPARED]: () => { | ||
setStory(api.getCurrentStoryData()); | ||
}, | ||
}, | ||
[] | ||
); | ||
|
||
if (!allPanels || !story || story.type !== 'story') { | ||
return allPanels; | ||
} | ||
const { parameters, type } = story ?? {}; | ||
|
||
const { parameters } = story; | ||
const panelActions = useMemo( | ||
() => ({ | ||
onSelect: (panel: string) => api.setSelectedPanel(panel), | ||
toggleVisibility: () => api.togglePanel(), | ||
togglePosition: () => api.togglePanelPosition(), | ||
}), | ||
[api] | ||
); | ||
|
||
const filteredPanels: typeof allPanels = {}; | ||
Object.entries(allPanels).forEach(([id, panel]) => { | ||
const { paramKey }: any = panel; | ||
if (paramKey && parameters && parameters[paramKey] && parameters[paramKey].disable) { | ||
return; | ||
} | ||
if ( | ||
panel.disabled === true || | ||
(typeof panel.disabled === 'function' && panel.disabled(parameters)) | ||
) { | ||
return; | ||
const panels = useMemo(() => { | ||
const allPanels = api.getElements(Addon_TypesEnum.PANEL); | ||
|
||
if (!allPanels || type !== 'story') { | ||
return allPanels; | ||
} | ||
filteredPanels[id] = panel; | ||
}); | ||
|
||
return filteredPanels; | ||
}); | ||
|
||
const mapper = ({ state, api }: Combo) => ({ | ||
panels: getPanels(api, api.getCurrentStoryData()), | ||
selectedPanel: api.getSelectedPanel(), | ||
panelPosition: state.layout.panelPosition, | ||
actions: createPanelActions(api), | ||
shortcuts: api.getShortcutKeys(), | ||
}); | ||
|
||
const Panel: FC<any> = (props) => ( | ||
<Consumer filter={mapper}>{(customProps) => <AddonPanel {...props} {...customProps} />}</Consumer> | ||
); | ||
|
||
const filteredPanels: typeof allPanels = {}; | ||
Object.entries(allPanels).forEach(([id, p]) => { | ||
const { paramKey }: any = p; | ||
if (paramKey && parameters && parameters[paramKey] && parameters[paramKey].disable) { | ||
return; | ||
} | ||
if (p.disabled === true || (typeof p.disabled === 'function' && p.disabled(parameters))) { | ||
return; | ||
} | ||
filteredPanels[id] = p; | ||
}); | ||
|
||
return filteredPanels; | ||
}, [api, type, parameters]); | ||
|
||
return ( | ||
<AddonPanel | ||
panels={panels} | ||
selectedPanel={api.getSelectedPanel()} | ||
panelPosition={state.layout.panelPosition} | ||
actions={panelActions} | ||
shortcuts={api.getShortcutKeys()} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default Panel; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The pattern
**/src/**/!(stories)/**
may be too aggressive - it excludes all source code except stories directories which could hide actual coverage gapsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure how to get around this. It is including src/ top level directory, which is artificially lowering the coverage test. I want it to exclude src/ but include everything inside src/ (that pertains to testing). Should we have a set directory that these files are expected to go into and have that in documentation, or is there a better way to approach this?