forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding web-component storyshot support based on html support
- Loading branch information
Showing
4 changed files
with
72 additions
and
19 deletions.
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ export type SupportedFramework = | |
| 'react-native' | ||
| 'svelte' | ||
| 'vue' | ||
| 'web-components' | ||
| 'rax'; |
32 changes: 32 additions & 0 deletions
32
addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import global from 'global'; | ||
import configure from '../configure'; | ||
import { Loader } from '../Loader'; | ||
import { StoryshotsOptions } from '../../api/StoryshotsOptions'; | ||
|
||
function test(options: StoryshotsOptions): boolean { | ||
return options.framework === 'web-components'; | ||
} | ||
|
||
function load(options: StoryshotsOptions) { | ||
global.STORYBOOK_ENV = 'web-components'; | ||
|
||
const storybook = jest.requireActual('@storybook/web-components'); | ||
|
||
configure({ ...options, storybook }); | ||
|
||
return { | ||
framework: 'web-components' as const, | ||
renderTree: jest.requireActual('./renderTree').default, | ||
renderShallowTree: () => { | ||
throw new Error('Shallow renderer is not supported for HTML'); | ||
}, | ||
storybook, | ||
}; | ||
} | ||
|
||
const webComponentsoader: Loader = { | ||
load, | ||
test, | ||
}; | ||
|
||
export default webComponentsoader; |
20 changes: 20 additions & 0 deletions
20
addons/storyshots/storyshots-core/src/frameworks/web-components/renderTree.ts
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { document, Node } from 'global'; | ||
|
||
function getRenderedTree(story: { render: () => any }) { | ||
const component = story.render(); | ||
|
||
if (component instanceof Node) { | ||
return component; | ||
} | ||
|
||
const section: HTMLElement = document.createElement('section'); | ||
section.innerHTML = component; | ||
|
||
if (section.childElementCount > 1) { | ||
return section; | ||
} | ||
|
||
return section.firstChild; | ||
} | ||
|
||
export default getRenderedTree; |