-
Notifications
You must be signed in to change notification settings - Fork 3
wrap interactor's actions to show them in storybook interactions debugger #126
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
615d1ff
wrap interactor's actions to show them in storybook interactions debu…
wKich 513ce45
pass interactor options to action wrapper
wKich 06aaa0c
Merge remote-tracking branch 'origin/main' into interactive-stories
wKich 3b1b2a4
add code representation for matchers
wKich d2cec70
Merge remote-tracking branch 'origin/main' into interactive-stories
wKich ac82a9a
make code representation for action
wKich ef844d2
revert formating
wKich aa78dfd
update interaction
wKich ab89935
fix failed tests for material-ui
wKich 3bc0ddc
fix types for cypress
wKich 7ab97bf
Merge branch 'main' into interactive-stories
wKich d3be18a
fix syntax error
wKich eca72dd
add tests
wKich 4a0ae0f
fix globals tests
wKich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,12 +1,12 @@ | ||
| import { converge } from "./converge"; | ||
| import { interaction } from "./interaction"; | ||
| import { unsafeSyncResolveUnique } from './constructor' | ||
| import { serializeOptions, unsafeSyncResolveUnique } from './constructor' | ||
| import { EmptyObject, FilterReturn, Interactor } from "./specification"; | ||
|
|
||
| export const read = <E extends Element, F extends EmptyObject>(interactor: Interactor<E, F>, field: keyof F): Promise<FilterReturn<F>> => { | ||
| let filter = interactor.options.specification.filters?.[field] | ||
| return interaction(`get ${field} from ${interactor.description}`, async () => { | ||
| let filterFn = typeof(filter) === 'function' ? filter : filter.apply | ||
| return await converge(() => filterFn(unsafeSyncResolveUnique(interactor.options))); | ||
| }); | ||
| }, serializeOptions('read', interactor.options)); | ||
| } |
This file contains hidden or 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,6 +1,6 @@ | ||
| module.exports = { | ||
| stories: ["../stories/**/*.stories.@(md|ts)x"], | ||
| addons: ["@storybook/addon-postcss", "@storybook/addon-essentials"], | ||
| features: { previewCsfV3: true }, | ||
| addons: ["@storybook/addon-postcss", "@storybook/addon-essentials", "@storybook/addon-interactions"], | ||
| features: { previewCsfV3: true, interactionsDebugger: true }, | ||
| core: { builder: "webpack5" }, | ||
| }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { instrument } from "@storybook/instrumenter"; | ||
| import { addActionWrapper, InteractorOptions } from "@interactors/globals"; | ||
|
|
||
| // NOTE: Dummy call to initialize instrumenter. See: https://github.com/storybookjs/storybook/blob/next/lib/instrumenter/src/instrumenter.ts#L512 | ||
| instrument({}); | ||
|
|
||
| let topActionRef = null; | ||
|
|
||
| addActionWrapper((_description, action, _type, options) => async () => { | ||
| if (!topActionRef) topActionRef = action; | ||
| try { | ||
| if (topActionRef != action) return action(); | ||
| const instrumenter = global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__; | ||
| const { actionName } = options; | ||
| let find = (r) => r; | ||
|
|
||
| for (const ancestor of options.ancestors ?? []) { | ||
| ({ find } = find( | ||
| instrumenter.track( | ||
| ancestor.name, | ||
| () => ({ find: (r) => r }), | ||
| ancestor.locator ? [ancestor.locator, ancestor.filter] : [ancestor.filter], | ||
| { intercept: () => true } | ||
| ) | ||
| )); | ||
| } | ||
| const { [actionName]: wrappedAction } = find( | ||
| instrumenter.track( | ||
| options.name, | ||
| () => ({ [actionName]: action }), | ||
| options.locator ? [options.locator, options.filter] : [options.filter], | ||
| { intercept: () => true } | ||
| ) | ||
| ); | ||
|
|
||
| await wrappedAction(...options.args); | ||
| } finally { | ||
| if (topActionRef == action) topActionRef = null; | ||
| } | ||
| }); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this wrapper should be a type:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. That was a little bit tricky to not break things