diff --git a/package.json b/package.json index 85fa378a..4832b66d 100644 --- a/package.json +++ b/package.json @@ -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/**/*", @@ -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\"", @@ -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", diff --git a/src/is-test-runner/is-test-runner.cjs b/src/is-test-runner/is-test-runner.cjs new file mode 100644 index 00000000..2bbabd78 --- /dev/null +++ b/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'; + } +} diff --git a/src/is-test-runner.ts b/src/is-test-runner/is-test-runner.mjs similarity index 58% rename from src/is-test-runner.ts rename to src/is-test-runner/is-test-runner.mjs index eb546e12..1907dec4 100644 --- a/src/is-test-runner.ts +++ b/src/is-test-runner/is-test-runner.mjs @@ -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; }