mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-04 23:11:23 +08:00
refactor: move react loader of addon-storyshots framework part to TS
This commit is contained in:
parent
001315ff0e
commit
3f782db307
@ -1,6 +1,6 @@
|
||||
import { StoryshotsOptions } from '../api/StoryshotsOptions';
|
||||
|
||||
type SupportedFramework = 'angular' | 'html' | 'preact';
|
||||
type SupportedFramework = 'angular' | 'html' | 'preact' | 'react';
|
||||
|
||||
export type RenderTree = (story: any) => any;
|
||||
|
||||
|
@ -1,25 +1,29 @@
|
||||
import configure from '../configure';
|
||||
import hasDependency from '../hasDependency';
|
||||
import { Loader } from '../Loader';
|
||||
import { StoryshotsOptions } from '../../api/StoryshotsOptions';
|
||||
|
||||
function test(options) {
|
||||
function test(options: StoryshotsOptions): boolean {
|
||||
return options.framework === 'react' || (!options.framework && hasDependency('@storybook/react'));
|
||||
}
|
||||
|
||||
function load(options) {
|
||||
function load(options: StoryshotsOptions) {
|
||||
const { configPath, config } = options;
|
||||
const storybook = require.requireActual('@storybook/react');
|
||||
|
||||
configure({ configPath, config, storybook });
|
||||
|
||||
return {
|
||||
framework: 'react',
|
||||
framework: 'react' as const,
|
||||
renderTree: require.requireActual('./renderTree').default,
|
||||
renderShallowTree: require.requireActual('./renderShallowTree').default,
|
||||
storybook,
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
const reactLoader: Loader = {
|
||||
load,
|
||||
test,
|
||||
};
|
||||
|
||||
export default reactLoader;
|
@ -1,7 +1,7 @@
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import shallow from 'react-test-renderer/shallow';
|
||||
|
||||
function getRenderedTree(story, context, { renderer, serializer }) {
|
||||
function getRenderedTree(story: any, context: any, { renderer, serializer }: any) {
|
||||
const storyElement = story.render();
|
||||
const shallowRenderer = renderer || shallow.createRenderer();
|
||||
const tree = shallowRenderer.render(storyElement);
|
@ -1,7 +1,7 @@
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import reactTestRenderer from 'react-test-renderer';
|
||||
|
||||
function getRenderedTree(story, context, { renderer, ...rendererOptions }) {
|
||||
function getRenderedTree(story: any, context: any, { renderer, ...rendererOptions }: any) {
|
||||
const storyElement = story.render();
|
||||
const currentRenderer = renderer || reactTestRenderer.create;
|
||||
const tree = currentRenderer(storyElement, rendererOptions);
|
@ -1,3 +1,4 @@
|
||||
declare module 'global';
|
||||
declare module 'jest-preset-angular/*';
|
||||
declare module 'preact-render-to-json';
|
||||
declare module 'react-test-renderer*';
|
||||
|
Loading…
x
Reference in New Issue
Block a user