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

fix: await interactions rule scope. #100

Merged
merged 7 commits into from
Oct 11, 2022

Conversation

zhyd1997
Copy link
Contributor

Issue: #47

What Changed

Checklist

Check the ones applicable to your change:

  • Ran yarn update-all
  • Tests are updated
  • Documentation is updated

Change Type

Indicate the type of change your pull request is:

  • maintenance
  • documentation
  • patch
  • minor
  • major

@zhyd1997 zhyd1997 marked this pull request as ready for review July 19, 2022 07:10
@ndelangen ndelangen requested a review from yannbf July 19, 2022 07:35
Copy link
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @zhyd1997 thanks a lot for your contribution! I added a couple comments.

tests/lib/rules/await-interactions.test.ts Outdated Show resolved Hide resolved
@@ -130,24 +130,36 @@ export = createStorybookRule({
return getClosestFunctionAncestor(parent)
}

const isExpectFromStorybookImported = (node: ImportDeclaration) => {
return (
node.source.value.startsWith('@storybook/')
Copy link
Member

@yannbf yannbf Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check will be true if the user has any random import from @storybook/* such as:

import { actions } from '@storybook/addon-actions'
import { Meta } from '@storybook/react'
import { expect } from '@storybook/jest'

while this is the import that should matter.

import { userEvent } from '@storybook/testing-library'

That is, for the userEvent case in particular. It's still possible to have play functions that do not use @storybook/testing-library but use expect from @storybook/jest instead

Copy link
Member

@yannbf yannbf Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are a couple more examples:

// if userEvent is imported from here, then it should provide an error message
import { userEvent } from '@storybook/testing-library'

// if userEvent is imported from somewhere else, it should not
import { userEvent } from '../utils'

Another example that the plugin should not provide an error message:

MyStory.play = async () => {
  const userEvent = { test: () => {} }
  // should not complain
  userEvent.test()
}

And another example that the plugin should provide an error message:

import { expect } from '@storybook/jest'
MyStory.play = async ({ args }) => {
  // should complain
  expect(args.onClick).toHaveBeenCalled()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still working on case 2...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done c5ed780

@zhyd1997
Copy link
Contributor Author

@yannbf @ndelangen

Thanks for the quick code review, give me some more time to update the PR.

more real use case.

Co-authored-by: Yann Braga <yannbf@gmail.com>
@zhyd1997 zhyd1997 marked this pull request as draft July 19, 2022 09:19
@zhyd1997 zhyd1997 marked this pull request as ready for review July 21, 2022 08:44
@ndelangen
Copy link
Member

Is this ready for review again?

If so, @yannbf and me can take a look again? 🙏
Thank you for the hard work @zhyd1997 !

@zhyd1997
Copy link
Contributor Author

zhyd1997 commented Aug 2, 2022

@ndelangen

Yes, it's ready for review again.
Sorry for that! 🙏🏿

@yannbf yannbf added the patch Increment the patch version when merged label Oct 11, 2022
@yannbf
Copy link
Member

yannbf commented Oct 11, 2022

Thank you so much once again @zhyd1997 ! Sorry it took some time, but I'm getting this in now!

@yannbf yannbf merged commit aa4a242 into storybookjs:main Oct 11, 2022
@github-actions
Copy link

🚀 PR was released in v0.6.6 🚀

@github-actions github-actions bot added the released This issue/pull request has been released. label Oct 11, 2022
@zhyd1997 zhyd1997 deleted the fix/await-interactions-rule-scope branch October 11, 2022 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants