Skip to content
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

Release: Prerelease beta 8.5.0-beta.10 #30252

Merged
merged 45 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
54653ef
Enhance a11y addon integration
valentinpalkovic Dec 31, 2024
a1506f3
Refactor TestProviderRender to remove a11ytest tag and pre-select a11…
valentinpalkovic Jan 2, 2025
4283a92
Small text adjustments
valentinpalkovic Jan 2, 2025
5a422cf
Add support for additional file extensions in addon-a11y-addon-test
valentinpalkovic Jan 2, 2025
c43aa09
Update a11y addon test snapshots and enhance transformation logic for…
valentinpalkovic Jan 2, 2025
b0d96bc
Update execa dependency to version 9.5.2 and enhance post-install log…
valentinpalkovic Jan 2, 2025
8de05db
Enhance post-install script to inherit stdio for better logging durin…
valentinpalkovic Jan 2, 2025
335c760
Test
valentinpalkovic Jan 2, 2025
15b941d
Refactor TestProviderRender to improve state management and update co…
valentinpalkovic Jan 2, 2025
3ff5a62
Set a11ytest as preview annotation tags in portable stories run
valentinpalkovic Jan 2, 2025
e7b81bc
Refactor a11y test configuration handling in vitest-plugin
valentinpalkovic Jan 2, 2025
711a48f
Merge remote-tracking branch 'origin/next' into valentin/a11y-refacto…
valentinpalkovic Jan 3, 2025
78537d4
refresh scripts lockfile, upgrade chromatic-cli
ndelangen Jan 3, 2025
d31350d
Merge remote-tracking branch 'origin/next' into valentin/a11y-refacto…
valentinpalkovic Jan 7, 2025
21b452a
Rename a11ytest tag to a11y-test
valentinpalkovic Jan 7, 2025
4554321
Refactor a11y-addon-test to return formatted config instead of raw lines
valentinpalkovic Jan 7, 2025
51cfe14
Fix tests for Windows
valentinpalkovic Jan 7, 2025
980a51e
Fix tests for Windows
valentinpalkovic Jan 8, 2025
b06a35f
Fix tests for Windows
valentinpalkovic Jan 8, 2025
7e75f73
Merge remote-tracking branch 'origin/next' into valentin/a11y-refacto…
valentinpalkovic Jan 9, 2025
03093e1
Refactor addon-a11y automigration to place a11y-test tag as a comment…
valentinpalkovic Jan 9, 2025
090276b
Fix for windows
valentinpalkovic Jan 9, 2025
fc2610f
Fix for windows
valentinpalkovic Jan 9, 2025
a4a3b3d
Return to execa 8.0.1 to reduce bundle size
valentinpalkovic Jan 10, 2025
f31a131
Use inline snapshots instead of normal ones
valentinpalkovic Jan 10, 2025
733be67
Simplify code
valentinpalkovic Jan 10, 2025
9d614f5
Remove invalid file extensions
valentinpalkovic Jan 10, 2025
3441720
Streamline state initialization and add useEffect for state updates
valentinpalkovic Jan 10, 2025
f3139a9
use dynamic path for vitest.setup.js
JReinhold Jan 10, 2025
d8a18a5
Merge branch 'next' into valentin/a11y-refactorings
valentinpalkovic Jan 10, 2025
b451851
Addon-docs: Make new code panel opt in
shilman Jan 12, 2025
af159c9
Docs updates for `a11y-test` tag behavior
kylegach Jan 13, 2025
51dfb39
Update messages
kylegach Jan 13, 2025
1045b35
Merge branch 'next' into norbert/upgrades-2025-1
ndelangen Jan 13, 2025
523f051
Fix memoization issue of Panel
valentinpalkovic Jan 13, 2025
42d7d30
Merge branch 'next' into valentin/a11y-refactorings
valentinpalkovic Jan 13, 2025
5a33146
Update tests
valentinpalkovic Jan 13, 2025
1664776
Merge pull request #30233 from storybookjs/jeppe/fix-vitest-setup-path
JReinhold Jan 13, 2025
909605c
Merge pull request #30248 from storybookjs/shilman/docs-disable-codep…
valentinpalkovic Jan 13, 2025
66facc9
Merge pull request #30162 from storybookjs/valentin/a11y-refactorings
valentinpalkovic Jan 13, 2025
a6a633a
Merge branch 'next-release' into next
storybook-bot Jan 13, 2025
4224713
Merge pull request #30182 from storybookjs/norbert/upgrades-2025-1
ndelangen Jan 13, 2025
6b33750
Addon A11y: Change default element selector
valentinpalkovic Jan 13, 2025
9057d1f
Merge pull request #30253 from storybookjs/valentin/run-a11y-tests-on…
valentinpalkovic Jan 13, 2025
4911535
Write changelog for 8.5.0-beta.10 [skip ci]
storybook-bot Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 8.5.0-beta.10

- Addon A11y: Adjust default behaviour when using with experimental-addon-test - [#30162](https://github.com/storybookjs/storybook/pull/30162), thanks @valentinpalkovic!
- Addon A11y: Change default element selector - [#30253](https://github.com/storybookjs/storybook/pull/30253), thanks @valentinpalkovic!
- Addon Docs: Make new code panel opt in - [#30248](https://github.com/storybookjs/storybook/pull/30248), thanks @shilman!
- Addon Test: Fix generated path to `vitest.setup.js` - [#30233](https://github.com/storybookjs/storybook/pull/30233), thanks @JReinhold!

## 8.5.0-beta.9

- Addon Test: Add prerequisite check for MSW - [#30193](https://github.com/storybookjs/storybook/pull/30193), thanks @yannbf!
Expand Down
25 changes: 20 additions & 5 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [Introducing features.developmentModeForBuild](#introducing-featuresdevelopmentmodeforbuild)
- [Added source code panel to docs](#added-source-code-panel-to-docs)
- [Addon-a11y: Component test integration](#addon-a11y-component-test-integration)
- [Addon-a11y: Changing the default element selector](#addon-a11y-changing-the-default-element-selector)
- [Addon-a11y: Deprecated `parameters.a11y.manual`](#addon-a11y-deprecated-parametersa11ymanual)
- [Addon-test: You should no longer copy the content of `viteFinal` to your configuration](#addon-test-you-should-no-longer-copy-the-content-of-vitefinal-to-your-configuration)
- [Addon-test: Indexing behavior of @storybook/experimental-addon-test is changed](#addon-test-indexing-behavior-of-storybookexperimental-addon-test-is-changed)
Expand Down Expand Up @@ -435,7 +436,7 @@ As part of our ongoing efforts to improve the testability and debuggability of S
In development mode, React and other libraries often include additional checks and warnings that help catch potential issues early. These checks are usually stripped out in production builds to optimize performance. However, when running tests or debugging issues in a built Storybook, having these additional checks can be incredibly valuable. One such feature is React's `act`, which ensures that all updates related to a test are processed and applied before making assertions. `act` is crucial for reliable and predictable test results, but it only works correctly when `NODE_ENV` is set to `development`.

```js
// main.js
// .storybook/main.js
export default {
features: {
developmentModeForBuild: true,
Expand All @@ -445,15 +446,16 @@ export default {

### Added source code panel to docs

Starting in 8.5, Storybook Docs (`@storybook/addon-docs`) automatically adds a new addon panel to stories that displays a source snippet beneath each story. This works similarly to the existing [source snippet doc block](https://storybook.js.org/docs/writing-docs/doc-blocks#source), but in the story view. It is intended to replace the [Storysource addon](https://storybook.js.org/addons/@storybook/addon-storysource).
Storybook Docs (`@storybook/addon-docs`) now can automatically add a new addon panel to stories that displays a source snippet beneath each story. This is an experimental feature that works similarly to the existing [source snippet doc block](https://storybook.js.org/docs/writing-docs/doc-blocks#source), but in the story view. It is intended to replace the [Storysource addon](https://storybook.js.org/addons/@storybook/addon-storysource).

If you wish to disable this panel globally, add the following line to your `.storybook/preview.js` project configuration. You can also selectively disable/enable at the story level.
To enable this globally, add the following line to your project configuration. You can also configure at the component/story level.

```js
// .storybook/preview.js
export default {
parameters: {
docs: {
codePanel: false,
codePanel: true,
},
},
};
Expand Down Expand Up @@ -481,11 +483,24 @@ const annotations = setProjectAnnotations([
beforeAll(annotations.beforeAll);
```

### Addon-a11y: Changing the default element selector

In Storybook 8.5, we changed the default element selector used by the Accessibility addon from `#storybook-root` to `body`. This change was made to align with the default element selector used by the Test addon when running accessibility tests via Vitest. Additionally, Tooltips or Popovers that are rendered outside the `#storybook-root` element will now be included in the accessibility tests per default allowing for a more comprehensive test coverage. If you want to fall back to the previous behavior, you can set the `a11y.element` parameter in your `.storybook/preview.<ts|js>` configuration:

```diff
// .storybook/preview.js
export const parameters = {
a11y: {
+ element: '#storybook-root',
},
};
```

### Addon-a11y: Deprecated `parameters.a11y.manual`

We have deprecated `parameters.a11y.manual` in 8.5. Please use `globals.a11y.manual` instead.

### Addon-test: You should no longer copy the content of `viteFinal` to your configuration
### Addon-test: You should no longer copy the content of `viteFinal` to your configuration

In version 8.4 of `@storybook/experimental-addon-test`, it was required to copy any custom configuration you had in `viteFinal` in `main.ts`, to the Vitest Storybook project. This is no longer necessary, as the Storybook Test plugin will automatically include your `viteFinal` configuration. You should remove any configurations you might already have in `viteFinal` to remove duplicates.

Expand Down
2 changes: 1 addition & 1 deletion code/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,4 @@ export const parameters = {
},
};

export const tags = ['test', 'vitest', '!a11ytest'];
export const tags = ['test', 'vitest'];
2 changes: 1 addition & 1 deletion code/addons/a11y/src/a11yRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const runNext = async () => {
export const run = async (input: A11yParameters = defaultParameters) => {
const { default: axe } = await import('axe-core');

const { element = '#storybook-root', config = {}, options = {} } = input;
const { element = 'body', config = {}, options = {} } = input;
const htmlElement = document.querySelector(element as string) ?? document.body;

if (!htmlElement) {
Expand Down
2 changes: 1 addition & 1 deletion code/addons/a11y/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const TEST_PROVIDER_ID = 'storybook/addon-a11y/test-provider';

export const EVENTS = { RESULT, REQUEST, RUNNING, ERROR, MANUAL };

export const A11Y_TEST_TAG = 'a11ytest';
export const A11Y_TEST_TAG = 'a11y-test';
4 changes: 3 additions & 1 deletion code/addons/a11y/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ const $ = execa({
});

export default async function postinstall(options: PostinstallOptions) {
await $`storybook automigrate addonA11yAddonTest ${options.yes ? '--yes' : ''}`;
await $({
stdio: 'inherit',
})`storybook automigrate addonA11yAddonTest ${options.yes ? '--yes' : ''}`;
Comment on lines +14 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: stdio: 'inherit' is redundant here since it's already set in the top-level execa config

}
2 changes: 1 addition & 1 deletion code/addons/a11y/src/preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ describe('afterEach', () => {
});
});

it('should run accessibility checks if "a11ytest" flag is not available and is not running in Vitest', async () => {
it('should run accessibility checks if "a11y-test" flag is not available and is not running in Vitest', async () => {
const context = createContext({
tags: [],
});
Expand Down
3 changes: 0 additions & 3 deletions code/addons/a11y/src/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,3 @@ export const initialGlobals = {
manual: false,
},
};

// A11Y_TEST_TAG constant in ./constants.ts. Has to be statically analyzable.
export const tags = ['a11ytest'];
12 changes: 3 additions & 9 deletions code/addons/docs/src/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@ addons.register(ADDON_ID, (api) => {
type: types.PANEL,
paramKey: PARAM_KEY,
/**
* This code panel can be disabled by the user by adding this parameter:
* This code panel can be enabled by adding this parameter:
*
* @example
*
* ```ts
* parameters: {
* docs: {
* codePanel: false,
* codePanel: true,
* },
* },
* ```
*/
disabled: (parameters) => {
return (
!!parameters &&
typeof parameters[PARAM_KEY] === 'object' &&
parameters[PARAM_KEY].codePanel === false
);
},
disabled: (parameters) => !parameters?.docs?.codePanel,
match: ({ viewMode }) => viewMode === 'story',
render: ({ active }) => {
const [codeSnippet, setSourceCode] = useAddonState<{
Expand Down
60 changes: 48 additions & 12 deletions code/addons/test/src/components/TestProviderRender.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import React, { type ComponentProps, type FC, useCallback, useMemo, useRef, useState } from 'react';
import React, {
type ComponentProps,
type FC,
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';

import {
Button,
Expand All @@ -12,10 +20,11 @@ import {
type TestProviderConfig,
type TestProviderState,
} from 'storybook/internal/core-events';
import { addons } from 'storybook/internal/manager-api';
import { addons, useStorybookState } from 'storybook/internal/manager-api';
import type { API } from 'storybook/internal/manager-api';
import { styled, useTheme } from 'storybook/internal/theming';

import type { Tag } from '@storybook/csf';
import {
AccessibilityIcon,
EditIcon,
Expand Down Expand Up @@ -106,23 +115,38 @@ const statusMap: Record<TestStatus, ComponentProps<typeof TestStatusIcon>['statu
pending: 'pending',
};

export const TestProviderRender: FC<
{
api: API;
state: TestProviderConfig & TestProviderState<Details, Config>;
entryId?: string;
} & ComponentProps<typeof Container>
> = ({ state, api, entryId, ...props }) => {
type TestProviderRenderProps = {
api: API;
state: TestProviderConfig & TestProviderState<Details, Config>;
entryId?: string;
} & ComponentProps<typeof Container>;

export const TestProviderRender: FC<TestProviderRenderProps> = ({
state,
api,
entryId,
...props
}) => {
const [isEditing, setIsEditing] = useState(false);
const theme = useTheme();
const coverageSummary = state.details?.coverageSummary;
const storybookState = useStorybookState();

const isA11yAddon = addons.experimental_getRegisteredAddons().includes(A11Y_ADDON_ID);

const isA11yAddonInitiallyChecked = useMemo(() => {
const internalIndex = storybookState.internal_index;
if (!internalIndex || !isA11yAddon) {
return false;
}

return Object.values(internalIndex.entries).some((entry) => entry.tags?.includes('a11y-test'));
}, [isA11yAddon, storybookState.internal_index]);

const [config, updateConfig] = useConfig(
api,
state.id,
state.config || { a11y: false, coverage: false }
state.config || { a11y: isA11yAddonInitiallyChecked, coverage: false }
);

const isStoryEntry = entryId?.includes('--') ?? false;
Expand Down Expand Up @@ -425,14 +449,22 @@ export const TestProviderRender: FC<
};

function useConfig(api: API, providerId: string, initialConfig: Config) {
const updateTestProviderState = useCallback(
(config: Config) => {
api.updateTestProviderState(providerId, { config });
api.emit(TESTING_MODULE_CONFIG_CHANGE, { providerId, config });
},
[api, providerId]
);

const [currentConfig, setConfig] = useState<Config>(initialConfig);

const lastConfig = useRef(initialConfig);

const saveConfig = useCallback(
debounce((config: Config) => {
if (!isEqual(config, lastConfig.current)) {
api.updateTestProviderState(providerId, { config });
api.emit(TESTING_MODULE_CONFIG_CHANGE, { providerId, config });
updateTestProviderState(config);
lastConfig.current = config;
}
}, 500),
Expand All @@ -450,5 +482,9 @@ function useConfig(api: API, providerId: string, initialConfig: Config) {
[saveConfig]
);

useEffect(() => {
updateTestProviderState(initialConfig);
}, []);

return [currentConfig, updateConfig] as const;
}
32 changes: 24 additions & 8 deletions code/addons/test/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,13 @@ export default async function postInstall(options: PostinstallOptions) {
existsSync
);

const a11yAddon = info.addons.find((addon) => addon.includes(addonA11yName));

const imports = [
`import { beforeAll } from 'vitest';`,
`import { setProjectAnnotations } from '${annotationsImport}';`,
];

const projectAnnotations = [];

if (a11yAddon) {
imports.push(`import * as a11yAddonAnnotations from '@storybook/addon-a11y/preview';`);
projectAnnotations.push('a11yAddonAnnotations');
}

if (previewExists) {
imports.push(`import * as projectAnnotations from './preview';`);
projectAnnotations.push('projectAnnotations');
Expand All @@ -357,6 +350,27 @@ export default async function postInstall(options: PostinstallOptions) {
`
);

const a11yAddon = info.addons.find((addon) => addon.includes(addonA11yName));

if (a11yAddon) {
try {
logger.plain(`${step} Setting up ${addonA11yName} for @storybook/experimental-addon-test:`);
await $({
stdio: 'inherit',
})`storybook automigrate addonA11yAddonTest ${options.yes ? '--yes' : ''}`;
} catch (e) {
printError(
'🚨 Oh no!',
dedent`
We have detected that you have ${addonA11yName} installed but could not automatically set it up for @storybook/experimental-addon-test.

Please refer to the documentation to complete the setup manually:
${picocolors.cyan(`https://storybook.js.org/docs/writing-tests/accessibility-testing#test-addon-integration`)}
`
);
}
}

// Check for existing Vitest workspace. We can't extend it so manual setup is required.
const vitestWorkspaceFile = await findFile('vitest.workspace');
if (vitestWorkspaceFile) {
Expand Down Expand Up @@ -407,6 +421,8 @@ export default async function postInstall(options: PostinstallOptions) {
// If there's an existing config, we create a workspace file so we can run Storybook tests alongside.
const extension = extname(rootConfig);
const browserWorkspaceFile = resolve(dirname(rootConfig), `vitest.workspace${extension}`);
// to be set in vitest config
const vitestSetupFilePath = relative(dirname(browserWorkspaceFile), vitestSetupFile);

logger.line(1);
logger.plain(`${step} Creating a Vitest project workspace file:`);
Expand Down Expand Up @@ -442,7 +458,7 @@ export default async function postInstall(options: PostinstallOptions) {
name: 'chromium',
provider: 'playwright',
},
setupFiles: ['./.storybook/vitest.setup.ts'],
setupFiles: ['${vitestSetupFilePath}'],
},
},
]);
Expand Down
13 changes: 11 additions & 2 deletions code/addons/test/src/vitest-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,25 @@ export const storybookTest = async (options?: UserOptions): Promise<Plugin[]> =>
getInitialGlobals: () => {
const envConfig = JSON.parse(process.env.VITEST_STORYBOOK_CONFIG ?? '{}');

const isA11yEnabled = process.env.VITEST_STORYBOOK
const shouldRunA11yTests = process.env.VITEST_STORYBOOK
? (envConfig.a11y ?? false)
: true;

return {
a11y: {
manual: !isA11yEnabled,
manual: !shouldRunA11yTests,
},
};
},
getTags: () => {
const envConfig = JSON.parse(process.env.VITEST_STORYBOOK_CONFIG ?? '{}');

const shouldSetTag = process.env.VITEST_STORYBOOK
? (envConfig.a11y ?? false)
: false;

return shouldSetTag ? ['a11y-test'] : [];
},
},
// if there is a test.browser config AND test.browser.screenshotFailures is not explicitly set, we set it to false
...(inputConfig_ONLY_MUTATE_WHEN_STRICTLY_NEEDED_OR_YOU_WILL_BE_FIRED.test?.browser &&
Expand Down
5 changes: 3 additions & 2 deletions code/addons/test/src/vitest-plugin/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { setViewport } from './viewports';
declare module '@vitest/browser/context' {
interface BrowserCommands {
getInitialGlobals: () => Promise<Record<string, any>>;
getTags: () => Promise<string[] | undefined>;
}
}

const { getInitialGlobals } = server.commands;
const { getInitialGlobals, getTags } = server.commands;

export const testStory = (
exportName: string,
Expand All @@ -28,7 +29,7 @@ export const testStory = (
const composedStory = composeStory(
story,
meta,
{ initialGlobals: (await getInitialGlobals?.()) ?? {} },
{ initialGlobals: (await getInitialGlobals?.()) ?? {}, tags: await getTags?.() },
undefined,
exportName
);
Expand Down
Loading
Loading