mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
[storybook__addon-storyshots-puppeteer] new types definition (#37207)
* refactor: remove separated package definition relate: https://github.com/storybookjs/storybook/pull/3742 * feat: add new definition
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// Type definitions for @storybook/addon-storyshots-puppeteer 5.1
|
||||
// Project: https://github.com/storybookjs/storybook/tree/master/addons/storyshots, https://github.com/storybookjs/storybook/tree/master/addons/storyshots/storyshots-puppeteer
|
||||
// Definitions by: Yama-Tomo <https://github.com/Yama-Tomo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.1
|
||||
|
||||
import { StoryContext } from '@storybook/addon-storyshots';
|
||||
import { MatchImageSnapshotOptions } from 'jest-image-snapshot';
|
||||
import { ScreenshotOptions, Page, DirectNavigationOptions, Browser } from 'puppeteer';
|
||||
|
||||
export interface Context {
|
||||
context: StoryContext;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface CustomConfig {
|
||||
storybookUrl?: string;
|
||||
chromeExecutablePath?: string;
|
||||
getMatchOptions?: (ctx: Context) => MatchImageSnapshotOptions;
|
||||
getScreenshotOptions?: (ctx: Context) => ScreenshotOptions;
|
||||
beforeScreenshot?: (page: Page, ctx: Context) => Promise<void>;
|
||||
getGotoOptions?: (ctx: Context) => DirectNavigationOptions;
|
||||
customizePage?: (page: Page) => Promise<void>;
|
||||
getCustomBrowser?: () => Promise<Browser>;
|
||||
}
|
||||
|
||||
export function imageSnapshot(customConfig?: CustomConfig): ({ context }: { context: StoryContext }) =>
|
||||
Promise<void>;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
import initStoryshots from '@storybook/addon-storyshots';
|
||||
import { imageSnapshot } from '@storybook/addon-storyshots-puppeteer';
|
||||
import { connect } from 'puppeteer';
|
||||
|
||||
initStoryshots({
|
||||
test: imageSnapshot(),
|
||||
});
|
||||
|
||||
initStoryshots({
|
||||
test: imageSnapshot({
|
||||
storybookUrl: 'http://localhost:9002',
|
||||
chromeExecutablePath: '/usr/local/bin/chrome',
|
||||
getMatchOptions: context => ({
|
||||
failureThreshold: 0.2,
|
||||
failureThresholdType: 'percent',
|
||||
}),
|
||||
getScreenshotOptions: ({ context, url }) => ({ path: '/foo' }),
|
||||
beforeScreenshot: (page, context) => page.setViewport({ width: 300, height: 100 }),
|
||||
getGotoOptions: ({ context, url }) => ({ timeout: 10 }),
|
||||
customizePage: page => page.setViewport({ width: 300, height: 100 }),
|
||||
getCustomBrowser: () => connect({ browserWSEndpoint: 'ws://yourUrl' }),
|
||||
}),
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@storybook/addon-storyshots-puppeteer": [
|
||||
"storybook__addon-storyshots-puppeteer"
|
||||
],
|
||||
"@storybook/react": [
|
||||
"storybook__react"
|
||||
],
|
||||
"@storybook/addon-storyshots": [
|
||||
"storybook__addon-storyshots"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"storybook__addon-storyshots-puppeteer-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
+2
-18
@@ -1,6 +1,7 @@
|
||||
// Type definitions for @storybook/addon-storyshots 4.0
|
||||
// Type definitions for @storybook/addon-storyshots 5.1
|
||||
// Project: https://github.com/storybookjs/storybook/tree/master/addons/storyshots, https://github.com/storybookjs/storybook/tree/master/addons/storyshots/storyshots-core
|
||||
// Definitions by: Bradley Ayers <https://github.com/bradleyayers>
|
||||
// Yama-Tomo <https://github.com/Yama-Tomo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.1
|
||||
|
||||
@@ -37,23 +38,6 @@ export interface StoryContext {
|
||||
story: string;
|
||||
}
|
||||
|
||||
export interface ImageSnapshotOptions {
|
||||
context: {
|
||||
kind: any;
|
||||
story: string
|
||||
};
|
||||
url: string;
|
||||
}
|
||||
|
||||
export function imageSnapshot(options?: {
|
||||
storybookUrl?: string;
|
||||
getMatchOptions?: (options: ImageSnapshotOptions) => { failureThreshold: number, failureThresholdType: 'percent' };
|
||||
getScreenshotOptions?: (options: ImageSnapshotOptions) => ScreenshotOptions;
|
||||
beforeScreenshot?: (page: Page, options: ImageSnapshotOptions) => Promise<void>;
|
||||
getGotoOptions?: (options: ImageSnapshotOptions) => NavigationOptions;
|
||||
chromeExecutablePath?: string;
|
||||
}): Test;
|
||||
|
||||
export function multiSnapshotWithOptions(options: SnapshotOptions): Test;
|
||||
|
||||
export const shallowSnapshot: Test;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import initStoryshots, {
|
||||
getSnapshotFileName,
|
||||
imageSnapshot,
|
||||
multiSnapshotWithOptions,
|
||||
renderOnly,
|
||||
renderWithOptions,
|
||||
@@ -55,23 +54,6 @@ initStoryshots({
|
||||
})),
|
||||
});
|
||||
|
||||
initStoryshots({
|
||||
configPath: "",
|
||||
test: imageSnapshot({
|
||||
storybookUrl: "http://localhost:9002"
|
||||
})
|
||||
});
|
||||
|
||||
initStoryshots({
|
||||
configPath: "",
|
||||
test: imageSnapshot({
|
||||
storybookUrl: "http://localhost:9002",
|
||||
getScreenshotOptions: ({ context, url }) => ({ path: "/foo" }),
|
||||
getGotoOptions: ({ context, url }) => ({ timeout: 10 }),
|
||||
chromeExecutablePath: "/usr/local/bin/chrome"
|
||||
})
|
||||
});
|
||||
|
||||
initStoryshots({
|
||||
framework: 'react',
|
||||
configPath: '',
|
||||
|
||||
Reference in New Issue
Block a user