Skip to content

Commit

Permalink
[storybook__addon-storyshots-puppeteer] new types definition (Definit…
Browse files Browse the repository at this point in the history
…elyTyped#37207)

* refactor: remove separated package definition

relate: storybookjs/storybook#3742

* feat: add new definition
  • Loading branch information
Yama-Tomo authored and Konch Roman committed Aug 13, 2019
1 parent baa0aea commit 1424132
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 36 deletions.
28 changes: 28 additions & 0 deletions types/storybook__addon-storyshots-puppeteer/index.d.ts
Original file line number Diff line number Diff line change
@@ -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>;
Original file line number Diff line number Diff line change
@@ -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' }),
}),
});
34 changes: 34 additions & 0 deletions types/storybook__addon-storyshots-puppeteer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions types/storybook__addon-storyshots-puppeteer/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
20 changes: 2 additions & 18 deletions types/storybook__addon-storyshots/index.d.ts
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import initStoryshots, {
getSnapshotFileName,
imageSnapshot,
multiSnapshotWithOptions,
renderOnly,
renderWithOptions,
Expand Down Expand Up @@ -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: '',
Expand Down

0 comments on commit 1424132

Please sign in to comment.