Merge branch 'next' into valentin/replace-storybook-jest-by-test

This commit is contained in:
Valentin Palkovic 2024-01-12 16:22:05 +01:00 committed by GitHub
commit 9f9b07aed3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 71 additions and 219 deletions

View File

@ -1,3 +1,8 @@
## 7.6.8
- Addon-actions: Fix module resolution for react-native - [#25296](https://github.com/storybookjs/storybook/pull/25296), thanks [@dannyhw](https://github.com/dannyhw)!
- Storysource: Fix import error - [#25391](https://github.com/storybookjs/storybook/pull/25391), thanks [@unional](https://github.com/unional)!
## 7.6.7
- Core: Skip no-framework error when ignorePreview=true - [#25286](https://github.com/storybookjs/storybook/pull/25286), thanks [@ndelangen](https://github.com/ndelangen)!

View File

@ -1,8 +1,8 @@
diff --git a/dist/index.js b/dist/index.js
index 5a61947ad50426d27390b4e82533179323ad3ba1..32bfc45909b645cb31cec2e204c8baa23f21fdd2 100644
index 974d6b26f626024fc9904908100c9ecaa54f43e1..5be2d35267e7f0525c6588758dbebe72599f88a9 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -6,23 +6,29 @@ import { processError } from '@vitest/utils/error';
@@ -6,31 +6,37 @@ import { processError } from '@vitest/utils/error';
import { util } from 'chai';
const MATCHERS_OBJECT = Symbol.for("matchers-object");
@ -11,15 +11,19 @@ index 5a61947ad50426d27390b4e82533179323ad3ba1..32bfc45909b645cb31cec2e204c8baa2
+// Otherwise, vitest will override global jest matchers, and crash.
+const JEST_MATCHERS_OBJECT = Symbol.for("$$jest-matchers-object-storybook");
const GLOBAL_EXPECT = Symbol.for("expect-global");
const ASYMMETRIC_MATCHERS_OBJECT = Symbol.for("asymmetric-matchers-object");
if (!Object.prototype.hasOwnProperty.call(globalThis, MATCHERS_OBJECT)) {
const globalState = /* @__PURE__ */ new WeakMap();
- const matchers = /* @__PURE__ */ Object.create(null);
const assymetricMatchers = /* @__PURE__ */ Object.create(null);
Object.defineProperty(globalThis, MATCHERS_OBJECT, {
get: () => globalState
});
+ Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
+ get: () => assymetricMatchers
+ });
+}
+
+if (!Object.prototype.hasOwnProperty.call(globalThis, JEST_MATCHERS_OBJECT)) {
+ const matchers = /* @__PURE__ */ Object.create(null);
Object.defineProperty(globalThis, JEST_MATCHERS_OBJECT, {
@ -30,8 +34,15 @@ index 5a61947ad50426d27390b4e82533179323ad3ba1..32bfc45909b645cb31cec2e204c8baa2
matchers
})
});
- Object.defineProperty(globalThis, ASYMMETRIC_MATCHERS_OBJECT, {
- get: () => assymetricMatchers
- });
}
+
function getState(expect) {
return globalThis[MATCHERS_OBJECT].get(expect);
}
+
function setState(state, expect) {
const map = globalThis[MATCHERS_OBJECT];
const current = map.get(expect) || {};

View File

@ -40,6 +40,7 @@
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"react-native": "dist/index.mjs",
"types": "dist/index.d.ts",
"typesVersions": {
"*": {

View File

@ -221,11 +221,6 @@ export const transformStoryIndexToStoriesHash = (
startCollapsed: collapsedRoots.includes(id),
// Note that this will later get appended to the previous list of children (see below)
children: [childId],
// deprecated fields
isRoot: true,
isComponent: false,
isLeaf: false,
});
// Usually the last path/name pair will be displayed as a component,
// *unless* there are other stories that are more deeply nested under it
@ -246,10 +241,6 @@ export const transformStoryIndexToStoriesHash = (
...(childId && {
children: [childId],
}),
// deprecated fields
isRoot: false,
isComponent: true,
isLeaf: false,
});
} else {
acc[id] = merge<API_GroupEntry>((acc[id] || {}) as API_GroupEntry, {
@ -262,10 +253,6 @@ export const transformStoryIndexToStoriesHash = (
...(childId && {
children: [childId],
}),
// deprecated fields
isRoot: false,
isComponent: false,
isLeaf: false,
});
}
});
@ -278,12 +265,6 @@ export const transformStoryIndexToStoriesHash = (
parent: paths[paths.length - 1],
renderLabel,
prepared: !!item.parameters,
// deprecated fields
kind: item.title,
isRoot: false,
isComponent: false,
isLeaf: true,
} as API_DocsEntry | API_StoryEntry;
return acc;

View File

@ -1448,9 +1448,6 @@ describe('stories API', () => {
],
"depth": 0,
"id": "a",
"isComponent": true,
"isLeaf": false,
"isRoot": false,
"name": "a",
"parent": undefined,
"renderLabel": undefined,
@ -1460,10 +1457,6 @@ describe('stories API', () => {
"depth": 1,
"id": "a--1",
"importPath": "./a.ts",
"isComponent": false,
"isLeaf": true,
"isRoot": false,
"kind": "a",
"name": "1",
"parent": "a",
"prepared": false,
@ -1475,10 +1468,6 @@ describe('stories API', () => {
"depth": 1,
"id": "a--2",
"importPath": "./a.ts",
"isComponent": false,
"isLeaf": true,
"isRoot": false,
"kind": "a",
"name": "2",
"parent": "a",
"prepared": false,
@ -1524,9 +1513,6 @@ describe('stories API', () => {
],
"depth": 0,
"id": "a",
"isComponent": true,
"isLeaf": false,
"isRoot": false,
"name": "a",
"parent": undefined,
"renderLabel": undefined,
@ -1536,10 +1522,6 @@ describe('stories API', () => {
"depth": 1,
"id": "a--1",
"importPath": "./a.ts",
"isComponent": false,
"isLeaf": true,
"isRoot": false,
"kind": "a",
"name": "1",
"parent": "a",
"prepared": false,
@ -1572,9 +1554,6 @@ describe('stories API', () => {
],
"depth": 0,
"id": "a",
"isComponent": true,
"isLeaf": false,
"isRoot": false,
"name": "a",
"parent": undefined,
"renderLabel": undefined,
@ -1584,10 +1563,6 @@ describe('stories API', () => {
"depth": 1,
"id": "a--1",
"importPath": "./a.ts",
"isComponent": false,
"isLeaf": true,
"isRoot": false,
"kind": "a",
"name": "1",
"parent": "a",
"prepared": false,
@ -1599,10 +1574,6 @@ describe('stories API', () => {
"depth": 1,
"id": "a--2",
"importPath": "./a.ts",
"isComponent": false,
"isLeaf": true,
"isRoot": false,
"kind": "a",
"name": "2",
"parent": "a",
"prepared": false,

View File

@ -157,7 +157,6 @@ describe('initModule', () => {
type: 'story',
args: { a: 1, b: 2 },
initialArgs: { a: 1, b: 1 },
isLeaf: true,
}),
}),
});
@ -194,7 +193,7 @@ describe('initModule', () => {
state: { location: {} },
navigate,
fullAPI: Object.assign(fullAPI, {
getCurrentStoryData: () => ({ type: 'story', args: { a: 1 }, isLeaf: true }),
getCurrentStoryData: () => ({ type: 'story', args: { a: 1 } }),
}),
});

View File

@ -50,9 +50,8 @@
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/user-event": "14.3.0",
"@types/chai": "^4",
"@vitest/expect": "^0.34.2",
"@vitest/spy": "^0.34.1",
"@vitest/expect": "1.1.3",
"@vitest/spy": "^1.1.3",
"chai": "^4.3.7",
"util": "^0.12.4"
},

View File

@ -2,7 +2,7 @@ import {
spyOn,
isMockFunction,
fn,
spies as mocks,
mocks,
type MaybeMocked,
type MaybeMockedDeep,
type MaybePartiallyMocked,

View File

@ -9,81 +9,42 @@ export interface API_BaseEntry {
name: string;
refId?: string;
renderLabel?: (item: API_BaseEntry) => any;
/** @deprecated */
isRoot: boolean;
/** @deprecated */
isComponent: boolean;
/** @deprecated */
isLeaf: boolean;
}
export interface API_RootEntry extends API_BaseEntry {
type: 'root';
startCollapsed?: boolean;
children: StoryId[];
/** @deprecated */
isRoot: true;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: false;
}
export interface API_GroupEntry extends API_BaseEntry {
type: 'group';
parent?: StoryId;
children: StoryId[];
/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: false;
}
export interface API_ComponentEntry extends API_BaseEntry {
type: 'component';
parent?: StoryId;
children: StoryId[];
/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: true;
/** @deprecated */
isLeaf: false;
}
export interface API_DocsEntry extends API_BaseEntry {
type: 'docs';
parent: StoryId;
title: ComponentTitle;
/** @deprecated */
kind: ComponentTitle;
importPath: Path;
tags: Tag[];
prepared: boolean;
parameters?: {
[parameterName: string]: any;
};
/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: true;
}
export interface API_StoryEntry extends API_BaseEntry {
type: 'story';
parent: StoryId;
title: ComponentTitle;
/** @deprecated */
kind: ComponentTitle;
importPath: Path;
tags: Tag[];
prepared: boolean;
@ -93,13 +54,6 @@ export interface API_StoryEntry extends API_BaseEntry {
args?: Args;
argTypes?: ArgTypes;
initialArgs?: Args;
/** @deprecated */
isRoot: false;
/** @deprecated */
isComponent: false;
/** @deprecated */
isLeaf: true;
}
export type API_LeafEntry = API_DocsEntry | API_StoryEntry;
@ -110,15 +64,6 @@ export type API_HashEntry =
| API_DocsEntry
| API_StoryEntry;
/** @deprecated */
export type API_Root = API_RootEntry;
/** @deprecated */
export type API_Group = API_GroupEntry | API_ComponentEntry;
/** @deprecated */
export type API_Story = API_LeafEntry;
/**
* The `IndexHash` is our manager-side representation of the `StoryIndex`.
* We create entries in the hash not only for each story or docs entry, but

View File

@ -80,7 +80,7 @@
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/experimental-utils": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@vitest/expect@^0.34.2": "patch:@vitest/expect@npm%3A0.34.5#./.yarn/patches/@vitest-expect-npm-0.34.5-8031508efe.patch",
"@vitest/expect@1.1.3": "patch:@vitest/expect@npm%3A1.1.3#~/.yarn/patches/@vitest-expect-npm-1.1.3-2062bf533f.patch",
"esbuild": "^0.18.0",
"eslint": "^8.28.0",
"eslint-plugin-prettier": "^5.1.2",

View File

@ -27,9 +27,6 @@ const mockManagerStore: any = {
type: 'root',
id: 'someRootId',
name: 'root',
isRoot: true,
isComponent: false,
isLeaf: false,
renderLabel,
},
someComponentId: {
@ -37,9 +34,6 @@ const mockManagerStore: any = {
id: 'someComponentId',
name: 'component',
parent: 'someRootId',
isRoot: false,
isComponent: true,
isLeaf: false,
renderLabel,
},
someStoryId: {
@ -47,9 +41,6 @@ const mockManagerStore: any = {
id: 'someStoryId',
name: 'story',
parent: 'someComponentId',
isRoot: false,
isComponent: false,
isLeaf: true,
renderLabel,
},
},
@ -110,9 +101,6 @@ export const LongStoryName: Story = {
type: 'root',
id: 'someRootId',
name: 'someLongRootName',
isRoot: true,
isComponent: false,
isLeaf: false,
renderLabel,
},
someComponentId: {
@ -120,9 +108,6 @@ export const LongStoryName: Story = {
id: 'someComponentId',
name: 'someComponentName',
parent: 'someRootId',
isRoot: false,
isComponent: true,
isLeaf: false,
renderLabel,
},
someStoryId: {
@ -130,9 +115,6 @@ export const LongStoryName: Story = {
id: 'someStoryId',
name: 'someLongStoryName',
parent: 'someComponentId',
isRoot: false,
isComponent: false,
isLeaf: true,
renderLabel,
},
},

View File

@ -39,10 +39,6 @@ export const previewProps: PreviewProps = {
options: {},
},
args: {},
kind: 'kind',
isRoot: false,
isComponent: false,
isLeaf: true,
},
path: 'string',
viewMode: 'story',

View File

@ -177,13 +177,8 @@ const Result: FC<
const api = useStorybookApi();
useEffect(() => {
if (api && props.isHighlighted && item.isComponent) {
api.emit(
PRELOAD_ENTRIES,
// @ts-expect-error (TODO)
{ ids: [item.isLeaf ? item.id : item.children[0]] },
{ options: { target: item.refId } }
);
if (api && props.isHighlighted && item.type === 'component') {
api.emit(PRELOAD_ENTRIES, { ids: [item.children[0]] }, { options: { target: item.refId } });
}
}, [props.isHighlighted, item]);
@ -275,9 +270,9 @@ export const SearchResults: FC<{
const currentTarget = event.currentTarget as HTMLElement;
const storyId = currentTarget.getAttribute('data-id');
const refId = currentTarget.getAttribute('data-refid');
const item = api.getData(storyId, refId === 'storybook_internal' ? undefined : refId);
const item = api.resolveStory(storyId, refId === 'storybook_internal' ? undefined : refId);
if (item?.isComponent) {
if (item?.type === 'component') {
api.emit(PRELOAD_ENTRIES, {
// @ts-expect-error (TODO)
ids: [item.isLeaf ? item.id : item.children[0]],

View File

@ -87,9 +87,6 @@ export const SingleStoryComponents: Story = {
type: 'component',
name: 'Single',
id: 'single',
isRoot: false,
isLeaf: false,
isComponent: true,
parent: null,
depth: 0,
children: ['single--single'],
@ -100,11 +97,7 @@ export const SingleStoryComponents: Story = {
id: 'single--single',
title: 'Single',
name: 'Single',
kind: 'single',
tags: [],
isRoot: false,
isLeaf: true,
isComponent: false,
prepared: true,
args: {},
argTypes: {},
@ -159,9 +152,6 @@ export const DocsOnlySingleStoryComponents = {
single: {
type: 'component',
name: 'Single',
isRoot: false,
isLeaf: false,
isComponent: true,
id: 'single',
parent: null,
depth: 0,
@ -172,11 +162,7 @@ export const DocsOnlySingleStoryComponents = {
id: 'single--docs',
title: 'Single',
name: 'Single',
kind: 'single',
tags: [],
isRoot: false,
isLeaf: true,
isComponent: false,
prepared: true,
depth: 1,
parent: 'single',

View File

@ -317,7 +317,7 @@ const Node = React.memo<NodeProps>(function Node({
if (item.type === 'component' && !isExpanded && isDesktop) onSelectStoryId(item.id);
}}
onMouseEnter={() => {
if (item.isComponent) {
if (item.type === 'component') {
api.emit(PRELOAD_ENTRIES, {
ids: [item.children[0]],
options: { target: refId },

View File

@ -38,7 +38,6 @@ const generateStories = ({ title, refId }: { title: string; refId?: string }): A
const docsId = `${rootId}-${hypenatedComponentName}--docs`;
const storyBase: HashEntry[] = [
// @ts-expect-error the missing fields are deprecated and replaced by the type prop
{
type: 'root',
id: rootId,
@ -48,7 +47,6 @@ const generateStories = ({ title, refId }: { title: string; refId?: string }): A
children: [componentId],
startCollapsed: false,
},
// @ts-expect-error the missing fields are deprecated and replaced by the type prop
{
type: 'component',
id: componentId,

View File

@ -109,11 +109,10 @@ export const useHighlighted = ({
if (highlightable[nextIndex].getAttribute('data-nodetype') === 'component') {
const { itemId, refId } = highlightedRef.current;
const item = api.getData(itemId, refId === 'storybook_internal' ? undefined : refId);
if (item.isComponent) {
const item = api.resolveStory(itemId, refId === 'storybook_internal' ? undefined : refId);
if (item.type === 'component') {
api.emit(PRELOAD_ENTRIES, {
// @ts-expect-error (TODO)
ids: [item.isLeaf ? item.id : item.children[0]],
ids: [item.children[0]],
options: { target: refId },
});
}

View File

@ -6655,9 +6655,8 @@ __metadata:
"@testing-library/dom": "npm:^9.3.1"
"@testing-library/jest-dom": "npm:^6.1.3"
"@testing-library/user-event": "npm:14.3.0"
"@types/chai": "npm:^4"
"@vitest/expect": "npm:^0.34.2"
"@vitest/spy": "npm:^0.34.1"
"@vitest/expect": "npm:1.1.3"
"@vitest/spy": "npm:^1.1.3"
chai: "npm:^4.3.7"
ts-dedent: "npm:^2.2.0"
type-fest: "npm:~2.19"
@ -7173,13 +7172,6 @@ __metadata:
languageName: node
linkType: hard
"@types/chai@npm:^4":
version: 4.3.11
resolution: "@types/chai@npm:4.3.11"
checksum: 0c216ac4a19bfbf8318bb104d32e50704ee2ffc4b538b976c4326e6638fee121462402caa570662227a2a218810388aadb14bdbd3d3d474ec300b00695db448a
languageName: node
linkType: hard
"@types/color-convert@npm:^2.0.0":
version: 2.0.3
resolution: "@types/color-convert@npm:2.0.3"
@ -8342,17 +8334,6 @@ __metadata:
languageName: node
linkType: hard
"@vitest/expect@npm:0.34.5":
version: 0.34.5
resolution: "@vitest/expect@npm:0.34.5"
dependencies:
"@vitest/spy": "npm:0.34.5"
"@vitest/utils": "npm:0.34.5"
chai: "npm:^4.3.7"
checksum: dc30a5e1f2732a1906df57f65381df1129dbf994496734c27e4a3f832852862501eaba1ec2987215ec12ee23a8f2ef1d8ff63c7cd5490046a7a26800da1adcb2
languageName: node
linkType: hard
"@vitest/expect@npm:1.0.4":
version: 1.0.4
resolution: "@vitest/expect@npm:1.0.4"
@ -8364,14 +8345,25 @@ __metadata:
languageName: node
linkType: hard
"@vitest/expect@patch:@vitest/expect@npm%3A0.34.5#./.yarn/patches/@vitest-expect-npm-0.34.5-8031508efe.patch::locator=%40storybook%2Froot%40workspace%3A.":
version: 0.34.5
resolution: "@vitest/expect@patch:@vitest/expect@npm%3A0.34.5#./.yarn/patches/@vitest-expect-npm-0.34.5-8031508efe.patch::version=0.34.5&hash=f89b80&locator=%40storybook%2Froot%40workspace%3A."
"@vitest/expect@npm:1.1.3":
version: 1.1.3
resolution: "@vitest/expect@npm:1.1.3"
dependencies:
"@vitest/spy": "npm:0.34.5"
"@vitest/utils": "npm:0.34.5"
chai: "npm:^4.3.7"
checksum: b08f0b1df6a37305f3f68feec15cfac048ca9e3924998698625394296faac4e539e23d7422eec59c0850a83b7342b574a2d2d174aaa33a7eb0004e4e366c515c
"@vitest/spy": "npm:1.1.3"
"@vitest/utils": "npm:1.1.3"
chai: "npm:^4.3.10"
checksum: fe5c9eade516a754efc26d4b6378a250f0c3b668fa15b3e6b6042190b64a65c4459b7fd67bfca72fb1fbf215feb838b68da4ab224a2a10137d8828ca6af70516
languageName: node
linkType: hard
"@vitest/expect@patch:@vitest/expect@npm%3A1.1.3#~/.yarn/patches/@vitest-expect-npm-1.1.3-2062bf533f.patch":
version: 1.1.3
resolution: "@vitest/expect@patch:@vitest/expect@npm%3A1.1.3#~/.yarn/patches/@vitest-expect-npm-1.1.3-2062bf533f.patch::version=1.1.3&hash=5d51c9"
dependencies:
"@vitest/spy": "npm:1.1.3"
"@vitest/utils": "npm:1.1.3"
chai: "npm:^4.3.10"
checksum: 426287f864f58b05b1c4689bc87b4ef2ca7b3316a22e8e42d94ee9c125cbc0caf294618c9a1201a8ddf8ab68ce1ab194d1e34589f7d608906a3dc679074cfe22
languageName: node
linkType: hard
@ -8397,15 +8389,6 @@ __metadata:
languageName: node
linkType: hard
"@vitest/spy@npm:0.34.5":
version: 0.34.5
resolution: "@vitest/spy@npm:0.34.5"
dependencies:
tinyspy: "npm:^2.1.1"
checksum: bbee495ca6300f50dde6418d14db0d3281daf38df15abae95202ddef253d6dd8bedf9f4a79da5a2246d3758ab24aa737caccf752fabcd8ba902a4f14801c2a0c
languageName: node
linkType: hard
"@vitest/spy@npm:1.0.4":
version: 1.0.4
resolution: "@vitest/spy@npm:1.0.4"
@ -8415,23 +8398,12 @@ __metadata:
languageName: node
linkType: hard
"@vitest/spy@npm:^0.34.1":
version: 0.34.7
resolution: "@vitest/spy@npm:0.34.7"
"@vitest/spy@npm:1.1.3, @vitest/spy@npm:^1.1.3":
version: 1.1.3
resolution: "@vitest/spy@npm:1.1.3"
dependencies:
tinyspy: "npm:^2.1.1"
checksum: 1150b270eb72a5e8e7da997bcba90ebe5ed2ac50de1ea1f81738e16a19ab4bc77ca4d17639988df65695d4b325fe3647a1e4204d01024bcf5ecac8ba7764a2cc
languageName: node
linkType: hard
"@vitest/utils@npm:0.34.5":
version: 0.34.5
resolution: "@vitest/utils@npm:0.34.5"
dependencies:
diff-sequences: "npm:^29.4.3"
loupe: "npm:^2.3.6"
pretty-format: "npm:^29.5.0"
checksum: 99cc5974ada1dab2b02220005c0fc97147baba175601a0faa1b2b6687c7f579d21a401077377d6f759b3aa8a07dcc8851cdc3e07f9a550ec289286107487ac36
tinyspy: "npm:^2.2.0"
checksum: d1692582afb7b665ec283723b15bbb7da95896cbfd7befaad9fdac6b64a8250fd918781263d43e8e10ee4874cdd18646224f6d993749c3751296dced8095a9ed
languageName: node
linkType: hard
@ -8446,6 +8418,18 @@ __metadata:
languageName: node
linkType: hard
"@vitest/utils@npm:1.1.3":
version: 1.1.3
resolution: "@vitest/utils@npm:1.1.3"
dependencies:
diff-sequences: "npm:^29.6.3"
estree-walker: "npm:^3.0.3"
loupe: "npm:^2.3.7"
pretty-format: "npm:^29.7.0"
checksum: 86f48a7722927741449f40f33584dd9857629782f6661654225b5dd3c039d61cc60806c5dfe419bd793f2a231ba91fe708cbdec5d99b62a1f6f819b6f2121fc3
languageName: node
linkType: hard
"@vitest/utils@npm:^0.34.6":
version: 0.34.7
resolution: "@vitest/utils@npm:0.34.7"
@ -26918,7 +26902,7 @@ __metadata:
languageName: node
linkType: hard
"tinyspy@npm:^2.1.1, tinyspy@npm:^2.2.0":
"tinyspy@npm:^2.2.0":
version: 2.2.0
resolution: "tinyspy@npm:2.2.0"
checksum: 8c7b70748dd8590e85d52741db79243746c15bc03c92d75c23160a762142db577e7f53e360ba7300e321b12bca5c42dd2522a8dbeec6ba3830302573dd8516bc