-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into feature/bump-mdx-js
- Loading branch information
Showing
433 changed files
with
18,021 additions
and
4,921 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
import type { LoaderFunction } from '@storybook/types'; | ||
import { global } from '@storybook/global'; | ||
import type { onMockCall as onMockCallType } from '@storybook/test'; | ||
import { action } from './runtime'; | ||
|
||
export const tinySpyInternalState = Symbol.for('tinyspy:spy'); | ||
let subscribed = false; | ||
|
||
const attachActionsToFunctionMocks: LoaderFunction = (context) => { | ||
const logActionsWhenMockCalled: LoaderFunction = (context) => { | ||
const { | ||
args, | ||
parameters: { actions }, | ||
} = context; | ||
if (actions?.disable) return; | ||
|
||
Object.entries(args) | ||
.filter( | ||
([, value]) => | ||
typeof value === 'function' && '_isMockFunction' in value && value._isMockFunction | ||
) | ||
.forEach(([key, value]) => { | ||
// See this discussion for context: | ||
// https://github.com/vitest-dev/vitest/pull/5352 | ||
const previous = | ||
value.getMockImplementation() ?? | ||
(tinySpyInternalState in value ? value[tinySpyInternalState]?.getOriginal() : undefined); | ||
if (previous?._actionAttached !== true && previous?.isAction !== true) { | ||
const implementation = (...params: unknown[]) => { | ||
action(key)(...params); | ||
return previous?.(...params); | ||
}; | ||
implementation._actionAttached = true; | ||
value.mockImplementation(implementation); | ||
if ( | ||
!subscribed && | ||
'__STORYBOOK_TEST_ON_MOCK_CALL__' in global && | ||
typeof global.__STORYBOOK_TEST_ON_MOCK_CALL__ === 'function' | ||
) { | ||
const onMockCall = global.__STORYBOOK_TEST_ON_MOCK_CALL__ as typeof onMockCallType; | ||
onMockCall((mock, args) => { | ||
const name = mock.getMockName(); | ||
|
||
// TODO: Make this a configurable API in 8.2 | ||
if ( | ||
!/^next\/.*::/.test(name) || | ||
[ | ||
'next/router::useRouter()', | ||
'next/navigation::useRouter()', | ||
'next/navigation::redirect', | ||
'next/cache::', | ||
'next/headers::cookies().set', | ||
'next/headers::cookies().delete', | ||
'next/headers::headers().set', | ||
'next/headers::headers().delete', | ||
].some((prefix) => name.startsWith(prefix)) | ||
) { | ||
action(name)(args); | ||
} | ||
}); | ||
subscribed = true; | ||
} | ||
}; | ||
|
||
export const loaders: LoaderFunction[] = [attachActionsToFunctionMocks]; | ||
export const loaders: LoaderFunction[] = [logActionsWhenMockCalled]; |
Oops, something went wrong.