Skip to content

Commit

Permalink
update entry point for isTestRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Oct 6, 2022
1 parent b923816 commit a7305ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -19,6 +19,13 @@
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/ts/index.d.ts",
"exports": {
"./is-test-runner": {
"import": "./src/is-test-runner/is-test-runner.mjs",
"browser": "./src/is-test-runner/is-test-runner.mjs",
"require": "./src/is-test-runner/is-test-runner.cjs"
}
},
"files": [
"bin",
"dist/**/*",
Expand Down
6 changes: 6 additions & 0 deletions src/is-test-runner/is-test-runner.cjs
@@ -0,0 +1,6 @@
/**
* Returns whether the story is rendering inside of the Storybook test runner.
*/
export function isTestRunner() {
return process?.env?.STORYBOOK_TEST_RUNNER === 'true';
}
Expand Up @@ -2,12 +2,9 @@
* Returns whether the story is rendering inside of the Storybook test runner.
*/
export function isTestRunner() {
const isTestRunnerInNode = process?.env?.STORYBOOK_TEST_RUNNER === 'true';
const isTestRunnerInBrowser = !!(
return!!(
typeof window !== 'undefined' &&
window &&
window.navigator.userAgent.match(/StorybookTestRunner/)
);

return isTestRunnerInNode || isTestRunnerInBrowser;
}

0 comments on commit a7305ad

Please sign in to comment.