From 140e34e720ec41e15848bf7ba39e795b8e64e0f7 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Fri, 14 Oct 2022 18:08:22 +0200 Subject: [PATCH 1/6] remove the defaultValue feature for argTypes --- code/lib/store/src/csf/prepareStory.test.ts | 74 ++++++++++----------- code/lib/store/src/csf/prepareStory.ts | 21 +----- 2 files changed, 38 insertions(+), 57 deletions(-) diff --git a/code/lib/store/src/csf/prepareStory.test.ts b/code/lib/store/src/csf/prepareStory.test.ts index 81ae1314eab3..b287293722ae 100644 --- a/code/lib/store/src/csf/prepareStory.test.ts +++ b/code/lib/store/src/csf/prepareStory.test.ts @@ -155,43 +155,43 @@ describe('prepareStory', () => { expect(initialArgs).toEqual({}); }); - it('are initialized to argTypes[x].defaultValue if unset', () => { - const { initialArgs } = prepareStory( - { - id, - name, - args: { - arg2: 3, - arg4: 'foo', - arg7: false, - }, - argTypes: { - arg1: { name: 'arg1', type: stringType, defaultValue: 'arg1' }, - arg2: { name: 'arg2', type: numberType, defaultValue: 2 }, - arg3: { - name: 'arg3', - type: complexType, - defaultValue: { complex: { object: ['type'] } }, - }, - arg4: { name: 'arg4', type: stringType }, - arg5: { name: 'arg5', type: stringType }, - arg6: { name: 'arg6', type: numberType, defaultValue: 0 }, // See https://github.com/storybookjs/storybook/issues/12767 } - }, - moduleExport, - }, - { id, title }, - { render: () => {} } - ); - - expect(initialArgs).toEqual({ - arg1: 'arg1', - arg2: 3, - arg3: { complex: { object: ['type'] } }, - arg4: 'foo', - arg6: 0, - arg7: false, - }); - }); + // it('are initialized to argTypes[x].defaultValue if unset', () => { + // const { initialArgs } = prepareStory( + // { + // id, + // name, + // args: { + // arg2: 3, + // arg4: 'foo', + // arg7: false, + // }, + // argTypes: { + // arg1: { name: 'arg1', type: stringType, defaultValue: 'arg1' }, + // arg2: { name: 'arg2', type: numberType, defaultValue: 2 }, + // arg3: { + // name: 'arg3', + // type: complexType, + // defaultValue: { complex: { object: ['type'] } }, + // }, + // arg4: { name: 'arg4', type: stringType }, + // arg5: { name: 'arg5', type: stringType }, + // arg6: { name: 'arg6', type: numberType, defaultValue: 0 }, // See https://github.com/storybookjs/storybook/issues/12767 } + // }, + // moduleExport, + // }, + // { id, title }, + // { render: () => {} } + // ); + + // expect(initialArgs).toEqual({ + // arg1: 'arg1', + // arg2: 3, + // arg3: { complex: { object: ['type'] } }, + // arg4: 'foo', + // arg6: 0, + // arg7: false, + // }); + // }); describe('argsEnhancers', () => { it('are applied in the right order', () => { diff --git a/code/lib/store/src/csf/prepareStory.ts b/code/lib/store/src/csf/prepareStory.ts index 92f8ce6e3e71..77ed14d71777 100644 --- a/code/lib/store/src/csf/prepareStory.ts +++ b/code/lib/store/src/csf/prepareStory.ts @@ -1,5 +1,3 @@ -import { dedent } from 'ts-dedent'; -import deprecate from 'util-deprecate'; import global from 'global'; import type { @@ -28,15 +26,6 @@ import { combineParameters } from '../parameters'; import { applyHooks } from '../hooks'; import { defaultDecorateStory } from '../decorators'; import { groupArgsByTarget, NO_TARGET_NAME } from '../args'; -import { getValuesFromArgTypes } from './getValuesFromArgTypes'; - -const argTypeDefaultValueWarning = deprecate( - () => {}, - dedent` - \`argType.defaultValue\` is deprecated and will be removed in Storybook 7.0. - - https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#no-longer-inferring-default-values-of-args` -); // Combine all the metadata about a story (both direct and inherited from the component/global scope) // into a "renderable" story function, with all decorators applied, parameters passed as context etc @@ -128,15 +117,7 @@ export function prepareStory( contextForEnhancers.argTypes ); - // Add argTypes[X].defaultValue to initial args (note this deprecated) - // We need to do this *after* the argTypesEnhancers as they may add defaultValues - const defaultArgs = getValuesFromArgTypes(contextForEnhancers.argTypes); - - if (Object.keys(defaultArgs).length > 0) { - argTypeDefaultValueWarning(); - } - - const initialArgsBeforeEnhancers = { ...defaultArgs, ...passedArgs }; + const initialArgsBeforeEnhancers = { ...passedArgs }; contextForEnhancers.initialArgs = argsEnhancers.reduce( (accumulatedArgs: Args, enhancer) => ({ From 0d42987ffe5e3483624469ff20058566cb650fc5 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Fri, 14 Oct 2022 18:12:12 +0200 Subject: [PATCH 2/6] disable for now, might delete based on michael's feedback (or modify) --- code/lib/store/src/csf/prepareStory.test.ts | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/code/lib/store/src/csf/prepareStory.test.ts b/code/lib/store/src/csf/prepareStory.test.ts index b287293722ae..d6498486549c 100644 --- a/code/lib/store/src/csf/prepareStory.test.ts +++ b/code/lib/store/src/csf/prepareStory.test.ts @@ -28,20 +28,20 @@ const moduleExport = {}; const stringType: SBScalarType = { name: 'string' }; const numberType: SBScalarType = { name: 'number' }; const booleanType: SBScalarType = { name: 'boolean' }; -const complexType: SBObjectType = { - name: 'object', - value: { - complex: { - name: 'object', - value: { - object: { - name: 'array', - value: { name: 'string' }, - }, - }, - }, - }, -}; +// const complexType: SBObjectType = { +// name: 'object', +// value: { +// complex: { +// name: 'object', +// value: { +// object: { +// name: 'array', +// value: { name: 'string' }, +// }, +// }, +// }, +// }, +// }; beforeEach(() => { global.FEATURES = { breakingChangesV7: true }; From 13a147540c1b4bfa4c4e4e078d29823606926edc Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Fri, 14 Oct 2022 18:14:46 +0200 Subject: [PATCH 3/6] grrr --- code/lib/store/src/csf/prepareStory.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/lib/store/src/csf/prepareStory.test.ts b/code/lib/store/src/csf/prepareStory.test.ts index d6498486549c..caf069f35b2c 100644 --- a/code/lib/store/src/csf/prepareStory.test.ts +++ b/code/lib/store/src/csf/prepareStory.test.ts @@ -5,7 +5,7 @@ import type { AnyFramework, ArgsEnhancer, PlayFunctionContext, - SBObjectType, + // SBObjectType, SBScalarType, } from '@storybook/csf'; From 95b45cbe14a4ed10ce92b409b485f02c6a5fb165 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 5 Dec 2022 09:37:16 +0100 Subject: [PATCH 4/6] cleanup --- .../modules/store/csf/prepareStory.test.ts | 60 +------------------ 1 file changed, 1 insertion(+), 59 deletions(-) diff --git a/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts b/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts index ed6f5908fdb2..6ca0164dce48 100644 --- a/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts +++ b/code/lib/preview-api/src/modules/store/csf/prepareStory.test.ts @@ -2,13 +2,7 @@ import global from 'global'; import { expect } from '@jest/globals'; -import type { - Renderer, - ArgsEnhancer, - PlayFunctionContext, - // SBObjectType, - SBScalarType, -} from '@storybook/types'; +import type { Renderer, ArgsEnhancer, PlayFunctionContext, SBScalarType } from '@storybook/types'; import { addons, HooksContext } from '../../addons'; import { NO_TARGET_NAME } from '../args'; @@ -30,20 +24,6 @@ const moduleExport = {}; const stringType: SBScalarType = { name: 'string' }; const numberType: SBScalarType = { name: 'number' }; const booleanType: SBScalarType = { name: 'boolean' }; -// const complexType: SBObjectType = { -// name: 'object', -// value: { -// complex: { -// name: 'object', -// value: { -// object: { -// name: 'array', -// value: { name: 'string' }, -// }, -// }, -// }, -// }, -// }; beforeEach(() => { global.FEATURES = { breakingChangesV7: true }; @@ -193,44 +173,6 @@ describe('prepareStory', () => { expect(initialArgs).toEqual({}); }); - // it('are initialized to argTypes[x].defaultValue if unset', () => { - // const { initialArgs } = prepareStory( - // { - // id, - // name, - // args: { - // arg2: 3, - // arg4: 'foo', - // arg7: false, - // }, - // argTypes: { - // arg1: { name: 'arg1', type: stringType, defaultValue: 'arg1' }, - // arg2: { name: 'arg2', type: numberType, defaultValue: 2 }, - // arg3: { - // name: 'arg3', - // type: complexType, - // defaultValue: { complex: { object: ['type'] } }, - // }, - // arg4: { name: 'arg4', type: stringType }, - // arg5: { name: 'arg5', type: stringType }, - // arg6: { name: 'arg6', type: numberType, defaultValue: 0 }, // See https://github.com/storybookjs/storybook/issues/12767 } - // }, - // moduleExport, - // }, - // { id, title }, - // { render: () => {} } - // ); - - // expect(initialArgs).toEqual({ - // arg1: 'arg1', - // arg2: 3, - // arg3: { complex: { object: ['type'] } }, - // arg4: 'foo', - // arg6: 0, - // arg7: false, - // }); - // }); - describe('argsEnhancers', () => { it('are applied in the right order', () => { const run: number[] = []; From 9eb364ebd9bf9e55febb08dfc53caccc892cde3a Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Sat, 14 Jan 2023 00:52:49 +0100 Subject: [PATCH 5/6] fix tests --- .../react/src/__test__/__snapshots__/internals.test.tsx.snap | 5 ----- code/renderers/react/src/__test__/internals.test.tsx | 1 - 2 files changed, 6 deletions(-) diff --git a/code/renderers/react/src/__test__/__snapshots__/internals.test.tsx.snap b/code/renderers/react/src/__test__/__snapshots__/internals.test.tsx.snap index dcd51c8244fb..4507f513248b 100644 --- a/code/renderers/react/src/__test__/__snapshots__/internals.test.tsx.snap +++ b/code/renderers/react/src/__test__/__snapshots__/internals.test.tsx.snap @@ -5,7 +5,6 @@ exports[`Renders CSF2Secondary story 1`] = `