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 8.3.0-alpha.8 #28916

Merged
merged 56 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e2a04bb
Build: Update git push commands in publish.yml
valentinpalkovic Jul 10, 2024
3ac9915
Build: Add packageManager property
tobiasdiez Aug 3, 2024
517e869
update yarn
tobiasdiez Aug 3, 2024
0545c3c
Add packageManager also to scripts
tobiasdiez Aug 3, 2024
7e10dd7
Fix docs scroll for non-ascii anchors
SkReD Aug 7, 2024
c733967
Merge branch 'next' into fix-docs-anchor-scroll
SkReD Aug 7, 2024
aec16d5
chore: upgrade `commander` dependency
43081j Aug 9, 2024
60c9c14
Merge branch 'next' into pr/43081j/28857-1
ndelangen Aug 12, 2024
fdf569b
fixes
ndelangen Aug 13, 2024
0477af8
Merge branch 'next' into packagemanager
tobiasdiez Aug 13, 2024
0f6a2d3
fixes
ndelangen Aug 13, 2024
a80b43f
dedupe and ignore ts error
ndelangen Aug 14, 2024
2dfa8af
Merge branch 'next' into pr/43081j/28857-1
ndelangen Aug 14, 2024
296dfd2
fix some nextjs failure, maybe due to some dep dedupe
ndelangen Aug 14, 2024
885071e
Merge branch 'next' into packagemanager
ndelangen Aug 14, 2024
bdb606a
Merge branch 'next' into fix-docs-anchor-scroll
ndelangen Aug 14, 2024
6c4a442
set default viewport if applicable
yannbf Aug 16, 2024
b4fc809
fix lint issues
yannbf Aug 16, 2024
25d2a8e
refactor return type
yannbf Aug 16, 2024
0b6f53d
Web Components: Introduce setProjectAnnotations API
yannbf Aug 16, 2024
18df216
Angular: Introduce setProjectAnnotations API
yannbf Aug 16, 2024
0809eb5
HTML: Introduce setProjectAnnotations API
yannbf Aug 16, 2024
3229c13
Preact: Introduce setProjectAnnotations API
yannbf Aug 16, 2024
a38643e
SvelteKit: Introduce setProjectAnnotations API
yannbf Aug 16, 2024
1738902
minor change in jsdoc
yannbf Aug 16, 2024
52903fa
fix tests
yannbf Aug 16, 2024
7ff1345
extra changes
yannbf Aug 16, 2024
a853126
refactor
yannbf Aug 16, 2024
223e2f9
update error message
yannbf Aug 16, 2024
d20b3c6
add test story
SkReD Aug 16, 2024
0969121
fix lint errors
yannbf Aug 17, 2024
025e692
Merge branch 'next' into commander-of-commanders
43081j Aug 18, 2024
b24135d
Addon-docs: Remove babel dependency
shilman Aug 19, 2024
68afda8
Merge pull request #28905 from storybookjs/yann/improve-vitest-viewport
yannbf Aug 19, 2024
2b9141a
Merge pull request #28857 from 43081j/commander-of-commanders
ndelangen Aug 19, 2024
004df0c
Merge pull request #28826 from SkReD/fix-docs-anchor-scroll
ndelangen Aug 19, 2024
67afdd1
increase CI class for vitest integration
yannbf Aug 19, 2024
70fc796
add vite plugin to sveltekit
yannbf Aug 19, 2024
4684455
SvelteKit: Add portable stories vite plugin
yannbf Aug 19, 2024
d8ee6ed
fix formatting
yannbf Aug 19, 2024
16b4f11
fix lint
yannbf Aug 19, 2024
8399ee1
fix lint
yannbf Aug 19, 2024
5f1dce6
Merge pull request #28907 from storybookjs/yann/introduce-project-ann…
yannbf Aug 19, 2024
31c9141
Merge pull request #28918 from storybookjs/yann/add-sveltekit-portabl…
yannbf Aug 19, 2024
7d16b45
Merge branch 'next' into packagemanager
ndelangen Aug 19, 2024
80b3dce
Merge branch 'next' into valentin/fix-force-push-step-in-publish-step
JReinhold Aug 19, 2024
e0daec5
Merge pull request #28505 from storybookjs/valentin/fix-force-push-st…
JReinhold Aug 19, 2024
17584a0
Merge pull request #28795 from tobiasdiez/packagemanager
valentinpalkovic Aug 19, 2024
61b1a7b
Merge pull request #28915 from storybookjs/shilman/remove-babel-from-…
shilman Aug 19, 2024
e554a7f
Addon Vitest: Improve transformation logic to avoid duplicate tests
yannbf Aug 20, 2024
518d76b
fix types
yannbf Aug 20, 2024
2b4004d
fix lint
yannbf Aug 20, 2024
82b5534
fix lint
yannbf Aug 20, 2024
fad8af0
fix lint
yannbf Aug 20, 2024
a57a1ab
Merge pull request #28929 from storybookjs/yann/addon-vitest-transfor…
yannbf Aug 20, 2024
7e83d7e
Write changelog for 8.3.0-alpha.8 [skip ci]
storybook-bot Aug 20, 2024
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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ jobs:
parallelism:
type: integer
executor:
class: large
class: xlarge
name: sb_playwright
parallelism: << parameters.parallelism >>
steps:
Expand Down Expand Up @@ -723,7 +723,7 @@ workflows:
requires:
- build-sandboxes
- vitest-integration:
parallelism: 4
parallelism: 5
requires:
- create-sandboxes
- bench:
Expand Down Expand Up @@ -789,7 +789,7 @@ workflows:
requires:
- build-sandboxes
- vitest-integration:
parallelism: 4
parallelism: 5
requires:
- create-sandboxes
- test-portable-stories:
Expand Down Expand Up @@ -856,7 +856,7 @@ workflows:
requires:
- build-sandboxes
- vitest-integration:
parallelism: 8
parallelism: 11
requires:
- create-sandboxes
- test-portable-stories:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ jobs:
run: |
git checkout next
git pull
git push --force origin latest-release
git push --force origin main
git push origin --force next:latest-release
git push origin --force next:main

- name: Sync CHANGELOG.md from `main` to `next`
if: steps.target.outputs.target == 'main'
Expand All @@ -174,6 +174,7 @@ jobs:
git commit -m "Update CHANGELOG.md for v${{ steps.version.outputs.current-version }} [skip ci]" || true
git push origin next

# TODO: remove this step - @JReinhold
- name: Sync version JSONs from `next-release` to `main`
if: github.ref_name == 'next-release'
working-directory: .
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.prerelease.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 8.3.0-alpha.8

- Addon Vitest: Improve transformation logic to avoid duplicate tests - [#28929](https://github.com/storybookjs/storybook/pull/28929), thanks @yannbf!
- Addon Vitest: Set default viewport if applicable - [#28905](https://github.com/storybookjs/storybook/pull/28905), thanks @yannbf!
- Addon-docs: Remove babel dependency - [#28915](https://github.com/storybookjs/storybook/pull/28915), thanks @shilman!
- Blocks: Fix scroll to non-ascii anchors - [#28826](https://github.com/storybookjs/storybook/pull/28826), thanks @SkReD!
- Core: Introduce setProjectAnnotations API to more renderers and frameworks - [#28907](https://github.com/storybookjs/storybook/pull/28907), thanks @yannbf!
- Dependencies: Upgrade `commander` - [#28857](https://github.com/storybookjs/storybook/pull/28857), thanks @43081j!
- SvelteKit: Introduce portable stories support - [#28918](https://github.com/storybookjs/storybook/pull/28918), thanks @yannbf!

## 8.3.0-alpha.7

- Addon Vitest: Set screenshotFailures to false by default - [#28908](https://github.com/storybookjs/storybook/pull/28908), thanks @yannbf!
Expand Down
1 change: 0 additions & 1 deletion code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"prep": "jiti ../../../scripts/prepare/bundle.ts"
},
"dependencies": {
"@babel/core": "^7.24.4",
"@mdx-js/react": "^3.0.0",
"@storybook/blocks": "workspace:*",
"@storybook/csf-plugin": "workspace:*",
Expand Down
14 changes: 14 additions & 0 deletions code/addons/docs/template/stories/docs2/UtfSymbolScroll.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta } from '@storybook/addon-docs';

<Meta title="UtfSymbolsScroll" />

## Instruction

> Instruction below works only in iframe.html. Unknown code in normal mode (with manager) removes hash from url.

Click on [link](#anchor-with-utf-symbols-абвг). That will jump scroll to anchor after green block below. Then reload page and
it should smooth-scroll to that anchor.

<div style={{ height: "1500px", background: "green", color: "white" }}>Space for scroll test</div>

## Anchor with utf symbols (абвг)
31 changes: 26 additions & 5 deletions code/addons/vitest/src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { join, resolve } from 'node:path';

import type { Plugin } from 'vitest/config';

import { loadAllPresets, validateConfigurationFiles } from 'storybook/internal/common';
import { vitestTransform } from 'storybook/internal/csf-tools';
import {
getInterpretedFile,
loadAllPresets,
validateConfigurationFiles,
} from 'storybook/internal/common';
import { readConfig, vitestTransform } from 'storybook/internal/csf-tools';
import { MainFileMissingError } from 'storybook/internal/server-errors';
import type { StoriesEntry } from 'storybook/internal/types';

Expand All @@ -16,6 +20,16 @@ const defaultOptions: UserOptions = {
storybookUrl: 'http://localhost:6006',
};

const extractTagsFromPreview = async (configDir: string) => {
const previewConfigPath = getInterpretedFile(join(resolve(configDir), 'preview'));

if (!previewConfigPath) {
return [];
}
const previewConfig = await readConfig(previewConfigPath);
return previewConfig.getFieldValue(['tags']) ?? [];
};

export const storybookTest = (options?: UserOptions): Plugin => {
const finalOptions = {
...defaultOptions,
Expand Down Expand Up @@ -45,27 +59,33 @@ export const storybookTest = (options?: UserOptions): Plugin => {
finalOptions.configDir = resolve(process.cwd(), finalOptions.configDir);
}

let previewLevelTags: string[];

return {
name: 'vite-plugin-storybook-test',
enforce: 'pre',
async buildStart() {
// evaluate main.js and preview.js so we can extract
// stories for autotitle support and tags for tags filtering support
const configDir = finalOptions.configDir;
try {
await validateConfigurationFiles(finalOptions.configDir);
await validateConfigurationFiles(configDir);
} catch (err) {
throw new MainFileMissingError({
location: finalOptions.configDir,
location: configDir,
source: 'vitest',
});
}

const presets = await loadAllPresets({
configDir: finalOptions.configDir,
configDir,
corePresets: [],
overridePresets: [],
packageJson: {},
});

stories = await presets.apply('stories', []);
previewLevelTags = await extractTagsFromPreview(configDir);
},
async config(config) {
// If we end up needing to know if we are running in browser mode later
Expand Down Expand Up @@ -123,6 +143,7 @@ export const storybookTest = (options?: UserOptions): Plugin => {
configDir: finalOptions.configDir,
tagsFilter: finalOptions.tags,
stories,
previewLevelTags,
});
}
},
Expand Down
32 changes: 14 additions & 18 deletions code/addons/vitest/src/plugin/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,29 @@
/* eslint-disable no-underscore-dangle */
import { type RunnerTask, type TaskContext, type TaskMeta, type TestContext } from 'vitest';

import type { ComposedStoryFn } from 'storybook/internal/types';
import { composeStory } from 'storybook/internal/preview-api';
import type { ComponentAnnotations, ComposedStoryFn } from 'storybook/internal/types';

import type { UserOptions } from './types';
import { setViewport } from './viewports';

type TagsFilter = Required<UserOptions['tags']>;

export const isValidTest = (storyTags: string[], tagsFilter: TagsFilter) => {
const isIncluded =
tagsFilter?.include.length === 0 || tagsFilter?.include.some((tag) => storyTags.includes(tag));
const isNotExcluded = tagsFilter?.exclude.every((tag) => !storyTags.includes(tag));

return isIncluded && isNotExcluded;
};

export const testStory = (Story: ComposedStoryFn, tagsFilter: TagsFilter) => {
export const testStory = (
exportName: string,
story: ComposedStoryFn,
meta: ComponentAnnotations,
skipTags: string[]
) => {
const composedStory = composeStory(story, meta, undefined, undefined, exportName);
return async (context: TestContext & TaskContext & { story: ComposedStoryFn }) => {
if (Story === undefined || tagsFilter?.skip.some((tag) => Story.tags.includes(tag))) {
if (composedStory === undefined || skipTags?.some((tag) => composedStory.tags.includes(tag))) {
context.skip();
}

context.story = Story;
context.story = composedStory;

const _task = context.task as RunnerTask & { meta: TaskMeta & { storyId: string } };
_task.meta.storyId = Story.id;
_task.meta.storyId = composedStory.id;

await setViewport(Story.parameters.viewport);
await Story.run();
await setViewport(composedStory.parameters.viewport);
await composedStory.run();
};
};
154 changes: 154 additions & 0 deletions code/addons/vitest/src/plugin/viewports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/* eslint-disable no-underscore-dangle */
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { page } from '@vitest/browser/context';

import { DEFAULT_VIEWPORT_DIMENSIONS, type ViewportsParam, setViewport } from './viewports';

vi.mock('@vitest/browser/context', () => ({
page: {
viewport: vi.fn(),
},
}));

describe('setViewport', () => {
beforeEach(() => {
vi.clearAllMocks();
globalThis.__vitest_browser__ = true;
});

afterEach(() => {
globalThis.__vitest_browser__ = false;
});

it('should no op outside when not in Vitest browser mode', async () => {
globalThis.__vitest_browser__ = false;

await setViewport();
expect(page.viewport).not.toHaveBeenCalled();
});

it('should fall back to DEFAULT_VIEWPORT_DIMENSIONS if defaultViewport does not exist', async () => {
const viewportsParam: any = {
defaultViewport: 'nonExistentViewport',
};

await setViewport(viewportsParam);
expect(page.viewport).toHaveBeenCalledWith(
DEFAULT_VIEWPORT_DIMENSIONS.width,
DEFAULT_VIEWPORT_DIMENSIONS.height
);
});

it('should set the dimensions of viewport from INITIAL_VIEWPORTS', async () => {
const viewportsParam: any = {
// supported by default in addon viewports
defaultViewport: 'ipad',
};

await setViewport(viewportsParam);
expect(page.viewport).toHaveBeenCalledWith(768, 1024);
});

it('should set custom defined viewport dimensions', async () => {
const viewportsParam: ViewportsParam = {
defaultViewport: 'customViewport',
viewports: {
customViewport: {
name: 'Custom Viewport',
type: 'mobile',
styles: {
width: '800px',
height: '600px',
},
},
},
};

await setViewport(viewportsParam);
expect(page.viewport).toHaveBeenCalledWith(800, 600);
});

it('should correctly handle percentage-based dimensions', async () => {
const viewportsParam: ViewportsParam = {
defaultViewport: 'percentageViewport',
viewports: {
percentageViewport: {
name: 'Percentage Viewport',
type: 'desktop',
styles: {
width: '50%',
height: '50%',
},
},
},
};

await setViewport(viewportsParam);
expect(page.viewport).toHaveBeenCalledWith(600, 450); // 50% of 1920 and 1080
});

it('should correctly handle vw and vh based dimensions', async () => {
const viewportsParam: ViewportsParam = {
defaultViewport: 'viewportUnits',
viewports: {
viewportUnits: {
name: 'VW/VH Viewport',
type: 'desktop',
styles: {
width: '50vw',
height: '50vh',
},
},
},
};

await setViewport(viewportsParam);
expect(page.viewport).toHaveBeenCalledWith(600, 450); // 50% of 1920 and 1080
});

it('should correctly handle em based dimensions', async () => {
const viewportsParam: ViewportsParam = {
defaultViewport: 'viewportUnits',
viewports: {
viewportUnits: {
name: 'em/rem Viewport',
type: 'mobile',
styles: {
width: '20em',
height: '40rem',
},
},
},
};

await setViewport(viewportsParam);
expect(page.viewport).toHaveBeenCalledWith(320, 640); // dimensions * 16
});

it('should throw an error for unsupported dimension values', async () => {
const viewportsParam: ViewportsParam = {
defaultViewport: 'invalidViewport',
viewports: {
invalidViewport: {
name: 'Invalid Viewport',
type: 'desktop',
styles: {
width: 'calc(100vw - 20px)',
height: '10pc',
},
},
},
};

await expect(setViewport(viewportsParam)).rejects.toThrowErrorMatchingInlineSnapshot(`
[SB_ADDON_VITEST_0001 (UnsupportedViewportDimensionError): Encountered an unsupported value "calc(100vw - 20px)" when setting the viewport width dimension.

The Storybook plugin only supports values in the following units:
- px, vh, vw, em, rem and %.

You can either change the viewport for this story to use one of the supported units or skip the test by adding '!test' to the story's tags per https://storybook.js.org/docs/writing-stories/tags]
`);
expect(page.viewport).not.toHaveBeenCalled();
});
});
Loading
Loading