refactor: move svelte loader of addon-storyshots framework part to TS

This commit is contained in:
Gaëtan Maisse 2019-08-06 20:50:00 +02:00
parent a8262f9b2a
commit 5a7bb142a4
3 changed files with 10 additions and 6 deletions

View File

@ -1,6 +1,6 @@
import { StoryshotsOptions } from '../api/StoryshotsOptions';
type SupportedFramework = 'angular' | 'html' | 'preact' | 'react' | 'riot' | 'react-native';
type SupportedFramework = 'angular' | 'html' | 'preact' | 'react' | 'riot' | 'react-native' | 'svelte';
export type RenderTree = (story: any) => any;

View File

@ -1,14 +1,16 @@
import global from 'global';
import hasDependency from '../hasDependency';
import configure from '../configure';
import { Loader } from '../Loader';
import { StoryshotsOptions } from '../../api/StoryshotsOptions';
function test(options) {
function test(options: StoryshotsOptions): boolean {
return (
options.framework === 'svelte' || (!options.framework && hasDependency('@storybook/svelte'))
);
}
function load(options) {
function load(options: StoryshotsOptions) {
global.STORYBOOK_ENV = 'svelte';
const { configPath, config } = options;
@ -17,7 +19,7 @@ function load(options) {
configure({ configPath, config, storybook });
return {
framework: 'svelte',
framework: 'svelte' as const,
renderTree: require.requireActual('./renderTree').default,
renderShallowTree: () => {
throw new Error('Shallow renderer is not supported for svelte');
@ -26,7 +28,9 @@ function load(options) {
};
}
export default {
const svelteLoader: Loader = {
load,
test,
};
export default svelteLoader;

View File

@ -11,7 +11,7 @@ import { document } from 'global';
* If we don't render to HTML, we will get a snapshot of the raw story
* i.e. ({ Component, data }).
*/
function getRenderedTree(story) {
function getRenderedTree(story: any) {
const { Component, props } = story.render();
const DefaultCompatComponent = Component.default || Component;