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 53a5749
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
23 changes: 17 additions & 6 deletions package.json
Expand Up @@ -18,7 +18,21 @@
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/ts/index.d.ts",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"types": "./dist/ts/index.d.ts"
},
"./is-test-runner": {
"import": "./dist/esm/is-test-runner.mjs",
"require": "./dist/cjs/is-test-runner.cjs"
},
"./package.json": "./package.json"
},
"bin": {
"test-storybook": "./bin/test-storybook.js"
},
"files": [
"bin",
"dist/**/*",
Expand All @@ -30,8 +44,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,.cjs,.mjs\"",
"buildBabel:esm": "babel ./src -d ./dist/esm --env-name esm --extensions \".js,.jsx,.ts,.tsx,.cjs,.mjs\"",
"buildTsc": "tsc --declaration --emitDeclarationOnly --outDir ./dist/ts",
"prebuild": "yarn clean",
"build": "concurrently \"yarn buildBabel\" \"yarn buildTsc\"",
Expand All @@ -52,9 +66,6 @@
"generate-dynamic-stories": "node scripts/generate-dynamic-stories.js",
"prepare": "husky install"
},
"bin": {
"test-storybook": "./bin/test-storybook.js"
},
"devDependencies": {
"@auto-it/released": "^10.37.1",
"@babel/cli": "^7.12.1",
Expand Down
8 changes: 8 additions & 0 deletions src/is-test-runner/is-test-runner.cjs
@@ -0,0 +1,8 @@
/**
* Returns whether the story is rendering inside of the Storybook test runner.
*/
module.exports = {
isTestRunner: function () {
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 53a5749

Please sign in to comment.