Skip to content

Commit

Permalink
Merge pull request #18673 from storybookjs/tom/sb-468-add-step-functi…
Browse files Browse the repository at this point in the history
…on-to-play-context-and

Add step function to play context
  • Loading branch information
tmeasday committed Jul 29, 2022
2 parents 2582c2f + f95cb6e commit 428a768
Show file tree
Hide file tree
Showing 44 changed files with 220 additions and 76 deletions.
2 changes: 1 addition & 1 deletion code/addons/a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/theming": "7.0.0-alpha.17",
"axe-core": "^4.2.0",
"core-js": "^3.8.2",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/theming": "7.0.0-alpha.17",
"core-js": "^3.8.2",
"dequal": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/backgrounds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/theming": "7.0.0-alpha.17",
"core-js": "^3.8.2",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/controls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-common": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/node-logger": "7.0.0-alpha.17",
"@storybook/store": "7.0.0-alpha.17",
"@storybook/theming": "7.0.0-alpha.17",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-common": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/csf-tools": "7.0.0-alpha.17",
"@storybook/docs-tools": "7.0.0-alpha.17",
"@storybook/mdx1-csf": "0.0.5-canary.13.9ce928a.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/interactions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-common": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/instrumenter": "7.0.0-alpha.17",
"@storybook/theming": "7.0.0-alpha.17",
"core-js": "^3.8.2",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/links/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@storybook/addons": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/router": "7.0.0-alpha.17",
"core-js": "^3.8.2",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/addons/measure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"core-js": "^3.8.2",
"global": "^4.4.0"
},
Expand Down
2 changes: 1 addition & 1 deletion code/addons/outline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/components": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"core-js": "^3.8.2",
"global": "^4.4.0",
"ts-dedent": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion code/addons/storyshots/storyshots-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@storybook/core-client": "7.0.0-alpha.17",
"@storybook/core-common": "7.0.0-alpha.17",
"@storybook/core-webpack": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@types/glob": "^7.1.3",
"@types/jest": "^26.0.16",
"@types/jest-specific-snapshot": "^0.5.3",
Expand Down
3 changes: 1 addition & 2 deletions code/addons/storyshots/storyshots-puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@
},
"dependencies": {
"@axe-core/puppeteer": "^4.2.0",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/node-logger": "7.0.0-alpha.17",
"@types/jest-image-snapshot": "^4.1.3",
"core-js": "^3.8.2",
"jest-image-snapshot": "^4.3.0"
},
"devDependencies": {
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@types/puppeteer": "^5.4.0",
"puppeteer": "^2.0.0 || ^3.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion code/examples/external-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@storybook/addon-essentials": "7.0.0-alpha.17",
"@storybook/blocks": "7.0.0-alpha.17",
"@storybook/components": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/preview-web": "7.0.0-alpha.17",
"@storybook/react": "7.0.0-alpha.17",
"@storybook/react-webpack5": "7.0.0-alpha.17",
Expand Down
2 changes: 1 addition & 1 deletion code/examples/web-components-kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@storybook/core-events": "link:../../lib/core-events",
"@storybook/core-server": "link:../../lib/core-server",
"@storybook/core-webpack": "link:../../lib/core-webpack",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/csf-tools": "link:../../lib/csf-tools",
"@storybook/docs-tools": "link:../../lib/docs-tools",
"@storybook/jest": "^0.0.10",
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@storybook/core-common": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/core-server": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/docs-tools": "7.0.0-alpha.17",
"@storybook/node-logger": "7.0.0-alpha.17",
"@storybook/semver": "^7.3.2",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/addons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@storybook/channels": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/router": "7.0.0-alpha.17",
"@storybook/theming": "7.0.0-alpha.17",
"@types/webpack-env": "^1.16.4",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@storybook/channels": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/router": "7.0.0-alpha.17",
"@storybook/semver": "^7.3.2",
"@storybook/theming": "7.0.0-alpha.17",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@storybook/channels": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/store": "7.0.0-alpha.17",
"@types/qs": "^6.9.5",
"@types/webpack-env": "^1.16.4",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dependencies": {
"@babel/types": "^7.12.11",
"@mdx-js/mdx": "^1.6.22",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/csf-tools": "7.0.0-alpha.17",
"@storybook/node-logger": "7.0.0-alpha.17",
"core-js": "^3.8.2",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"dependencies": {
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/theming": "7.0.0-alpha.17",
"core-js": "^3.8.2",
"memoizerific": "^1.11.3",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@storybook/client-api": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/preview-web": "7.0.0-alpha.17",
"@storybook/store": "7.0.0-alpha.17",
"@storybook/ui": "7.0.0-alpha.17",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@babel/preset-react": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@babel/register": "^7.12.1",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/node-logger": "7.0.0-alpha.17",
"@storybook/semver": "^7.3.2",
"@types/babel__core": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/core-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@storybook/core-client": "7.0.0-alpha.17",
"@storybook/core-common": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/csf-tools": "7.0.0-alpha.17",
"@storybook/docs-mdx": "0.0.1-canary.12433cf.0",
"@storybook/node-logger": "7.0.0-alpha.17",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/csf-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@babel/preset-env": "^7.12.11",
"@babel/traverse": "^7.12.11",
"@babel/types": "^7.12.11",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"core-js": "^3.8.2",
"fs-extra": "^9.0.1",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/docs-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"dependencies": {
"@babel/core": "^7.12.10",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/store": "7.0.0-alpha.17",
"core-js": "^3.8.2",
"doctrine": "^3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/preview-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@storybook/channels": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"@storybook/store": "7.0.0-alpha.17",
"ansi-to-html": "^0.6.11",
"core-js": "^3.8.2",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/source-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"@storybook/addons": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"core-js": "^3.8.2",
"estraverse": "^5.2.0",
"global": "^4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion code/lib/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@storybook/addons": "7.0.0-alpha.17",
"@storybook/client-logger": "7.0.0-alpha.17",
"@storybook/core-events": "7.0.0-alpha.17",
"@storybook/csf": "0.0.2--canary.4566f4d.1",
"@storybook/csf": "0.0.2--canary.0899bb7.0",
"core-js": "^3.8.2",
"dequal": "^2.0.2",
"global": "^4.4.0",
Expand Down
6 changes: 6 additions & 0 deletions code/lib/store/src/csf/composeConfigs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('composeConfigs', () => {
globals: {},
globalTypes: {},
loaders: [],
runStep: expect.any(Function),
});
});

Expand All @@ -37,6 +38,7 @@ describe('composeConfigs', () => {
globals: {},
globalTypes: {},
loaders: [],
runStep: expect.any(Function),
});
});

Expand Down Expand Up @@ -66,6 +68,7 @@ describe('composeConfigs', () => {
globals: { x: '2', y: '1', z: '2', obj: { a: '2', c: '2' } },
globalTypes: { x: '2', y: '1', z: '2', obj: { a: '2', c: '2' } },
loaders: [],
runStep: expect.any(Function),
});
});

Expand Down Expand Up @@ -95,6 +98,7 @@ describe('composeConfigs', () => {
globals: {},
globalTypes: {},
loaders: ['1', '2', '3', '4'],
runStep: expect.any(Function),
});
});

Expand All @@ -119,6 +123,7 @@ describe('composeConfigs', () => {
globals: {},
globalTypes: {},
loaders: [],
runStep: expect.any(Function),
});
});

Expand Down Expand Up @@ -149,6 +154,7 @@ describe('composeConfigs', () => {
render: 'render-2',
renderToDOM: 'renderToDOM-2',
applyDecorators: 'applyDecorators-2',
runStep: expect.any(Function),
});
});
});
4 changes: 3 additions & 1 deletion code/lib/store/src/csf/composeConfigs.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { AnyFramework } from '@storybook/csf';

import { combineParameters } from '../parameters';
import type { ModuleExports, WebProjectAnnotations } from '../types';
import { combineParameters } from '../parameters';
import { composeStepRunners } from './stepRunners';

export function getField<TFieldType = any>(
moduleExportList: ModuleExports[],
Expand Down Expand Up @@ -52,5 +53,6 @@ export function composeConfigs<TFramework extends AnyFramework>(
render: getSingletonField(moduleExportList, 'render'),
renderToDOM: getSingletonField(moduleExportList, 'renderToDOM'),
applyDecorators: getSingletonField(moduleExportList, 'applyDecorators'),
runStep: composeStepRunners<TFramework>(getArrayField(moduleExportList, 'runStep')),
};
}
25 changes: 23 additions & 2 deletions code/lib/store/src/csf/prepareStory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { addons, HooksContext } from '@storybook/addons';
import type {
AnyFramework,
ArgsEnhancer,
PlayFunctionContext,
SBObjectType,
SBScalarType,
StoryContext,
} from '@storybook/csf';

import { NO_TARGET_NAME } from '../args';
Expand Down Expand Up @@ -630,10 +630,31 @@ describe('playFunction', () => {
{ render }
);

await playFunction({} as StoryContext<AnyFramework>);
await playFunction!({} as PlayFunctionContext);
expect(play).toHaveBeenCalled();
expect(inner).toHaveBeenCalled();
});

it('provides step via runStep', async () => {
const stepPlay = jest.fn((context) => {
expect(context).not.toBeUndefined();
expect(context.step).toEqual(expect.any(Function));
});
const play = jest.fn(async ({ step }) => {
step('label', stepPlay);
});
const runStep = jest.fn((label, p, c) => p(c));
const { playFunction } = prepareStory(
{ id, name, play, moduleExport },
{ id, title },
{ render, runStep }
);

await playFunction!({} as PlayFunctionContext);
expect(play).toHaveBeenCalled();
expect(stepPlay).toHaveBeenCalled();
expect(runStep).toBeCalledWith('label', stepPlay, expect.any(Object));
});
});

describe('moduleExport', () => {
Expand Down
17 changes: 16 additions & 1 deletion code/lib/store/src/csf/prepareStory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import type {
AnyFramework,
StrictArgTypes,
StoryContextForLoaders,
PlayFunctionContext,
StepLabel,
PlayFunction,
} from '@storybook/csf';
import { includeConditionalArg } from '@storybook/csf';

Expand Down Expand Up @@ -69,6 +72,7 @@ export function prepareStory<TFramework extends AnyFramework>(
applyDecorators = defaultDecorateStory,
argTypesEnhancers = [],
argsEnhancers = [],
runStep,
} = projectAnnotations;

const loaders = [
Expand Down Expand Up @@ -197,7 +201,18 @@ export function prepareStory<TFramework extends AnyFramework>(

return decoratedStoryFn(finalContext);
};
const playFunction = storyAnnotations.play;
const { play } = storyAnnotations;
const playFunction =
play &&
(async (storyContext: StoryContext<TFramework>) => {
const playFunctionContext: PlayFunctionContext<TFramework> = {
...storyContext,
step: (label: StepLabel, play: PlayFunction<TFramework>) =>
// TODO: We know runStep is defined, we need a proper normalized annotations type
runStep!(label, play, playFunctionContext),
};
return play(playFunctionContext);
});

return Object.freeze({
...contextForEnhancers,
Expand Down

0 comments on commit 428a768

Please sign in to comment.