-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Migrate addon storyshots to TS #7674
Changes from all commits
76b672e
a22f903
017729c
f1fd558
83e9b5f
892ab2c
1169a74
001315f
3f782db
54a7e9b
aff52bb
a8262f9
5a7bb14
ce76410
a1680b9
6127e38
bc8f5bd
f821891
8cbabb5
5352afb
7dc87d7
2f13904
de01450
16170f2
aad29ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IOptions } from 'glob'; | ||
import { Stories2SnapsConverter } from '../Stories2SnapsConverter'; | ||
import { SupportedFramework } from '../frameworks'; | ||
import { RenderTree } from '../frameworks/Loader'; | ||
|
||
export interface StoryshotsOptions { | ||
asyncJest?: boolean; | ||
config?: (options: any) => void; | ||
integrityOptions?: IOptions | false; | ||
configPath?: string; | ||
suite?: string; | ||
storyKindRegex?: RegExp | string; | ||
storyNameRegex?: RegExp | string; | ||
framework?: SupportedFramework; | ||
test?: (story: any, context: any, renderTree: RenderTree, options?: any) => any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ndelangen @kroeder are there already existing types somewhere for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in lib/addons |
||
renderer?: Function; | ||
snapshotSerializers?: jest.SnapshotSerializerPlugin[]; | ||
/** | ||
* @Deprecated The functionality of this option is completely covered by snapshotSerializers which should be used instead. | ||
*/ | ||
serializer?: any; | ||
stories2snapsConverter?: Stories2SnapsConverter; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ClientApi } from '@storybook/client-api'; | ||
import { StoryshotsOptions } from '../api/StoryshotsOptions'; | ||
import { SupportedFramework } from './SupportedFramework'; | ||
|
||
export type RenderTree = (story: any, context?: any, options?: any) => any; | ||
|
||
export interface Loader { | ||
load: ( | ||
options: StoryshotsOptions | ||
) => { | ||
framework: SupportedFramework; | ||
renderTree: RenderTree; | ||
renderShallowTree: any; | ||
storybook: ClientApi; | ||
}; | ||
test: (options: StoryshotsOptions) => boolean; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type SupportedFramework = | ||
| 'angular' | ||
| 'html' | ||
| 'preact' | ||
| 'react' | ||
| 'riot' | ||
| 'react-native' | ||
| 'svelte' | ||
| 'vue'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import 'core-js'; | |
import 'core-js/es/reflect'; | ||
import hasDependency from '../hasDependency'; | ||
import configure from '../configure'; | ||
import { Loader } from '../Loader'; | ||
import { StoryshotsOptions } from '../../api/StoryshotsOptions'; | ||
|
||
function setupAngularJestPreset() { | ||
// Needed to prevent "Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten." | ||
|
@@ -18,13 +20,13 @@ function setupAngularJestPreset() { | |
require.requireActual('jest-preset-angular/setupJest'); | ||
} | ||
|
||
function test(options) { | ||
function test(options: StoryshotsOptions): boolean { | ||
return ( | ||
options.framework === 'angular' || (!options.framework && hasDependency('@storybook/angular')) | ||
); | ||
} | ||
|
||
function load(options) { | ||
function load(options: StoryshotsOptions) { | ||
setupAngularJestPreset(); | ||
|
||
const { configPath, config } = options; | ||
|
@@ -33,7 +35,7 @@ function load(options) { | |
configure({ configPath, config, storybook }); | ||
|
||
return { | ||
framework: 'angular', | ||
framework: 'angular' as const, | ||
renderTree: require.requireActual('./renderTree').default, | ||
renderShallowTree: () => { | ||
throw new Error('Shallow renderer is not supported for angular'); | ||
|
@@ -42,7 +44,9 @@ function load(options) { | |
}; | ||
} | ||
|
||
export default { | ||
const angularLoader: Loader = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the way I found to have type-check according to |
||
load, | ||
test, | ||
}; | ||
|
||
export default angularLoader; |
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.
@emilio-martinez @kroeder @ndelangen what's the best practice about
@types
in SB codebase? I added them independencies
because some of the types I exported in this addon are based onjest
(and other libs) ones. So if a SB user want to use SB type it should install@types/jest
too... 🤷♂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.
We'll talk about this later today, but I think the preliminary agreement is to add the types of a regular dependency also as a regular dependency.