Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 10.2.3

- Addon-Vitest: Normalize Windows paths in addon-vitest automigration - [#33340](https://github.com/storybookjs/storybook/pull/33340), thanks @tanujbhaud!
- Core: Fix `previewHref` when current path does not end with a slash - [#33647](https://github.com/storybookjs/storybook/pull/33647), thanks @ghengeveld!

## 10.2.2

- Addon Vitest: Support simple vite.config without defineConfig helper - [#33694](https://github.com/storybookjs/storybook/pull/33694), thanks @valentinpalkovic!
Expand Down
33 changes: 31 additions & 2 deletions code/addons/vitest/src/updateVitestFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ describe('updateWorkspaceFile', () => {
+
+ // More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
+ export default ['packages/*', 'ROOT_CONFIG', {
+ extends: '',
+ extends: '.',
+ plugins: [
+ // The plugin will run tests for the stories defined in your Storybook config
+ // See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
Expand Down Expand Up @@ -1235,7 +1235,7 @@ describe('updateWorkspaceFile', () => {
+
+ // More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
+ export default defineWorkspace(['packages/*', 'ROOT_CONFIG', {
+ extends: '',
+ extends: '.',
+ plugins: [
+ // The plugin will run tests for the stories defined in your Storybook config
+ // See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
Expand All @@ -1258,3 +1258,32 @@ describe('updateWorkspaceFile', () => {
`);
});
});

describe('loadTemplate', () => {
it('normalizes Windows paths to forward slashes', async () => {
// Windows-style path with backslashes (need to escape them in JS strings)
const windowsPath = '.\\apps\\frontend-storybook\\.storybook';

const result = await loadTemplate('vitest.config.template.ts', {
CONFIG_DIR: windowsPath,
SETUP_FILE: '.\\apps\\frontend-storybook\\.storybook\\vitest.setup.ts',
});

// Should contain forward slashes, not backslashes
expect(result).toContain('apps/frontend-storybook/.storybook');
expect(result).not.toContain('\\apps\\');
});

it('preserves forward slashes in paths', async () => {
// Unix-style path with forward slashes
const unixPath = './apps/frontend-storybook/.storybook';

const result = await loadTemplate('vitest.config.template.ts', {
CONFIG_DIR: unixPath,
SETUP_FILE: './apps/frontend-storybook/.storybook/vitest.setup.ts',
});

// Should still contain forward slashes
expect(result).toContain('apps/frontend-storybook/.storybook');
});
});
7 changes: 5 additions & 2 deletions code/addons/vitest/src/updateVitestFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'node:fs/promises';

import type { BabelFile, types as t } from 'storybook/internal/babel';

import { join } from 'pathe';
import { join, normalize } from 'pathe';

import { resolvePackageDir } from '../../../core/src/shared/utils/module';

Expand All @@ -11,7 +11,10 @@ export const loadTemplate = async (name: string, replacements: Record<string, st
join(resolvePackageDir('@storybook/addon-vitest'), 'templates', name),
'utf8'
);
Object.entries(replacements).forEach(([key, value]) => (template = template.replace(key, value)));
// Normalize Windows paths (backslashes) to forward slashes for JavaScript string compatibility
Object.entries(replacements).forEach(
([key, value]) => (template = template.replace(key, normalize(value)))
);
return template;
};

Expand Down
7 changes: 4 additions & 3 deletions code/core/src/manager-api/modules/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,14 @@ export const init: ModuleFn<SubAPI, SubState> = (moduleArgs) => {
throw new Error(`Invalid refId: ${refId}`);
}

const originAddress = global.window.location.origin + location.pathname;
const pathname = location.pathname || '/';
const originAddress = global.window.location.origin + pathname;
const networkAddress = global.STORYBOOK_NETWORK_ADDRESS ?? originAddress;
const managerBase =
base === 'origin' ? originAddress : base === 'network' ? networkAddress : location.pathname;
base === 'origin' ? originAddress : base === 'network' ? networkAddress : pathname;
const previewBase = refId
? refs[refId].url + '/iframe.html'
: global.PREVIEW_URL || `${managerBase}iframe.html`;
: global.PREVIEW_URL || `${managerBase.replace(/\/[^/]*$/, '/')}iframe.html`;

const refParam = refId ? `&refId=${encodeURIComponent(refId)}` : '';
const { args = '', globals = '', ...otherParams } = queryParams;
Expand Down
16 changes: 16 additions & 0 deletions code/core/src/manager-api/tests/url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,5 +469,21 @@ describe('getStoryHrefs', () => {
const { managerHref, previewHref } = api.getStoryHrefs('test--story');
expect(managerHref).toEqual('/?path=/story/test--story');
expect(previewHref).toEqual('https://custom.preview.url/?id=test--story&viewMode=story');
delete global.PREVIEW_URL;
});

it('correctly links from /index.html', () => {
const { api, state } = initURL({
store,
provider: { channel: new EventEmitter() },
state: { location: { pathname: '/index.html', search: '' } },
navigate: vi.fn(),
fullAPI: { getCurrentStoryData: () => ({ id: 'test--story' }) },
});
store.setState(state);

const { managerHref, previewHref } = api.getStoryHrefs('test--story');
expect(managerHref).toEqual('/index.html?path=/story/test--story');
expect(previewHref).toEqual('/iframe.html?id=test--story&viewMode=story');
});
});
3 changes: 2 additions & 1 deletion code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,6 @@
"Dependency Upgrades"
]
]
}
},
"deferredNextVersion": "10.2.3"
}
2 changes: 1 addition & 1 deletion docs/versions/latest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"10.2.2","info":{"plain":"- Addon Vitest: Support simple vite.config without defineConfig helper - [#33694](https://github.com/storybookjs/storybook/pull/33694), thanks @valentinpalkovic!\n- Addon-Vitest: Append Storybook project to existing test.projects array without double nesting - [#33708](https://github.com/storybookjs/storybook/pull/33708), thanks @valentinpalkovic!\n- Addon-Vitest: Update Vitest plugin configuration to disable requireAssertions for expect - [#33693](https://github.com/storybookjs/storybook/pull/33693), thanks @valentinpalkovic!\n- Composition: Handle 401 responses with loginUrl from Chromatic - [#33705](https://github.com/storybookjs/storybook/pull/33705), thanks @kasperpeulen!\n- Telemetry: Add agent detection - [#33675](https://github.com/storybookjs/storybook/pull/33675), thanks @valentinpalkovic!"}}
{"version":"10.2.3","info":{"plain":"- Addon-Vitest: Normalize Windows paths in addon-vitest automigration - [#33340](https://github.com/storybookjs/storybook/pull/33340), thanks @tanujbhaud!\n- Core: Fix `previewHref` when current path does not end with a slash - [#33647](https://github.com/storybookjs/storybook/pull/33647), thanks @ghengeveld!"}}