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

Add isTestRunner utility #198

Merged
merged 9 commits into from
Oct 7, 2022
Merged

Add isTestRunner utility #198

merged 9 commits into from
Oct 7, 2022

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Oct 6, 2022

Release notes

The test-runner adds a StorybookTestRunner entry to the browser's user agent. You can use it to determine if a story is rendering in the context of the test runner. This might be useful if you want to disable certain features in your stories when running in the test runner, though it's likely an edge case.

export const MyStory = () => {
  const isTestRunner = window.navigator.userAgent.match(/StorybookTestRunner/)
  return (
    <div>
      <p>Is this story running in the test runner?</p>
      <p>{isTestRunner ? 'Yes' : 'No'}</p>
    </div>
  );
};

Given that this check is happening in the browser, it is only applicable in the following scenarios:

  • inside of a render/template function of a story
  • inside of a play function
  • inside of preview.js
  • inside any other code that is executed in the browser
📦 Published PR as canary version: 0.8.0--canary.198.d45feb9.0

✨ Test out this PR locally via:

npm install @storybook/[email protected]
# or 
yarn add @storybook/[email protected]

Version

Published prerelease version: v0.8.0-next.0

Changelog

🚀 Enhancement

Authors: 2

@yannbf yannbf added the minor Increment the minor version when merged label Oct 6, 2022
@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2022

Codecov Report

Base: 76.53% // Head: 76.63% // Increases project coverage by +0.09% 🎉

Coverage data is based on head (4010e3e) compared to base (aa45827).
Patch coverage: 80.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             next     #198      +/-   ##
==========================================
+ Coverage   76.53%   76.63%   +0.09%     
==========================================
  Files          11       12       +1     
  Lines         179      184       +5     
  Branches       37       38       +1     
==========================================
+ Hits          137      141       +4     
- Misses         42       43       +1     
Impacted Files Coverage Δ
.storybook/preview.js 80.00% <80.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@yannbf yannbf force-pushed the feat/is-test-runner-utility branch 3 times, most recently from c99b443 to a7305ad Compare October 6, 2022 19:02
@yannbf yannbf force-pushed the feat/is-test-runner-utility branch from a7305ad to 53a5749 Compare October 6, 2022 20:17
Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks @yannbf

README.md Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Oct 7, 2022

🚀 PR was released in v0.8.0 🚀

This was referenced Oct 12, 2022
@yannbf yannbf deleted the feat/is-test-runner-utility branch November 18, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants