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 c99b443
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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 All @@ -30,8 +37,8 @@
"scripts": {
"clean": "rimraf ./dist",
"buildBabel": "concurrently \"yarn buildBabel:cjs\" \"yarn buildBabel:esm\"",
"buildBabel:cjs": "babel ./src -d ./dist/cjs --extensions \".js,.jsx,.ts,.tsx\"",
"buildBabel:esm": "babel ./src -d ./dist/esm --env-name esm --extensions \".js,.jsx,.ts,.tsx\"",
"buildBabel:cjs": "babel ./src -d ./dist/cjs --extensions \".js,.jsx,.ts,.tsx\" --copy-files src/is-test-runner.js",
"buildBabel:esm": "babel ./src -d ./dist/esm --env-name esm --extensions \".js,.jsx,.ts,.tsx\" --copy-files src/is-test-runner.js",
"buildTsc": "tsc --declaration --emitDeclarationOnly --outDir ./dist/ts",
"prebuild": "yarn clean",
"build": "concurrently \"yarn buildBabel\" \"yarn buildTsc\"",
Expand Down
6 changes: 6 additions & 0 deletions src/is-test-runner/is-test-runner.cjs
Original file line number Diff line number Diff line change
@@ -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';
}
Original file line number Diff line number Diff line change
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 c99b443

Please sign in to comment.