diff --git a/.circleci/config.yml b/.circleci/config.yml index ef32f6fb4984..f6674fc9c46c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,7 @@ executors: docker: - image: cimg/node:16.17.1 environment: - NODE_OPTIONS: --max_old_space_size=3076 + NODE_OPTIONS: --max_old_space_size=6144 resource_class: <> sb_node_16_browsers: parameters: @@ -32,7 +32,7 @@ executors: docker: - image: cimg/node:16.17.1-browsers environment: - NODE_OPTIONS: --max_old_space_size=3076 + NODE_OPTIONS: --max_old_space_size=6144 resource_class: <> sb_playwright: parameters: @@ -43,14 +43,15 @@ executors: default: 'small' working_directory: /tmp/storybook docker: - - image: mcr.microsoft.com/playwright:v1.27.0-focal + - image: mcr.microsoft.com/playwright:v1.28.0-focal environment: - NODE_OPTIONS: --max_old_space_size=3076 + NODE_OPTIONS: --max_old_space_size=6144 resource_class: <> orbs: git-shallow-clone: guitarrapc/git-shallow-clone@2.4.0 browser-tools: circleci/browser-tools@1.4.0 + discord: antonioned/discord@0.1.0 commands: # Forked off from https://github.com/guitarrapc/git-shallow-clone-orb @@ -101,7 +102,7 @@ commands: then export HOME=$(getent passwd $(id -un) | cut -d: -f6) fi - + # known_hosts mkdir -p ~/.ssh if [ -x "$(command -v ssh-keyscan)" ] && ([ "<< parameters.keyscan_github >>" == "true" ] || [ "<< parameters.keyscan_bitbucket >>" == "true" ]) @@ -125,19 +126,19 @@ commands: echo 'bitbucket.org ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAubiN81eDcafrgMeLzaFPsw2kNvEcqTKl/VqLat/MaB33pZy0y3rJZtnqwR2qOOvbwKZYKiEO1O6VqNEBxKvJJelCq0dTXWT5pbO2gDXC6h6QDXCaHo6pOHGPUy+YBaGQRGuSusMEASYiWunYN0vCAI8QaXnWMXNMdFP3jHAJH0eDsoiGnLPBlBp4TNm6rYI74nMzgz3B9IikW4WVK+dc8KZJZWYjAuORU3jc1c/NPskD2ASinf8v3xnfXeukU0sJ5N6m5E8VLjObPEO+mN2t/FZTMZLiFqPWc/ALSqnMnnhwrNi2rbfg/rd/IpL8Le3pSBne8+seeFVBoGqzHM9yXw== ' >> ~/.ssh/known_hosts fi - + (umask 077; touch ~/.ssh/id_rsa) chmod 0600 ~/.ssh/id_rsa (echo $CHECKOUT_KEY > ~/.ssh/id_rsa) - + # use git+ssh instead of https git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true git config --global gc.auto 0 || true - + # checkout git clone << parameters.clone_options >> $CIRCLE_REPOSITORY_URL "<< parameters.path >>" cd "<< parameters.path >>" - + # Fetch remote and check the commit ID of the checked out code if [ -n "$CIRCLE_TAG" ] then @@ -151,7 +152,7 @@ commands: # others git fetch << parameters.fetch_options >> --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH" fi - + # Check the commit ID of the checked out code if [ -n "$CIRCLE_TAG" ] then @@ -162,7 +163,7 @@ commands: git reset --hard "$CIRCLE_SHA1" git checkout -q -B "$CIRCLE_BRANCH" fi - + git reset --hard "$CIRCLE_SHA1" name: Checkout code shallow cancel-workflow-on-failure: @@ -175,7 +176,36 @@ commands: echo "Canceling workflow as previous step resulted in failure." echo "To execute all checks locally, please run yarn ci-tests" curl -X POST --header "Content-Type: application/json" "https://circleci.com/api/v2/workflow/${CIRCLE_WORKFLOW_ID}/cancel?circle-token=${WORKFLOW_CANCELER}" + report-workflow-on-failure: + description: 'Reports failures to discord' + parameters: + template: + description: | + Which template to report in discord. Applicable for parallel sandbox jobs + type: string + default: 'none' + steps: + - run: + when: on_fail + command: git fetch --unshallow + - discord/status: + only_for_branches: main,next,next-release,latest-release + fail_only: true + failure_message: $(yarn get-report-message << pipeline.parameters.workflow >> << parameters.template >>) jobs: + pretty-docs: + executor: + class: small + name: sb_node_16_classic + steps: + - checkout_advanced: + clone_options: '--depth 1 --verbose' + - run: + name: Prettier + command: | + cd scripts + yarn + yarn docs:prettier:check build: executor: class: large @@ -197,6 +227,7 @@ jobs: command: | cd code yarn local-registry --publish + - report-workflow-on-failure - save_cache: name: Save Yarn cache key: build-yarn-2-cache-v4--{{ checksum "code/yarn.lock" }}--{{ checksum "scripts/yarn.lock" }} @@ -241,21 +272,22 @@ jobs: name: set up cra repro, skip tests command: | cd code - node ./lib/cli/bin/index.js repro-next cra/default-js --output ../../cra-bench + SANDBOX_ROOT=../bench yarn task --task sandbox --template cra/default-ts --skip-template-stories --start-from=never --no-link - run: name: Run @storybook/bench on repro command: | - cd ../cra-bench + cd bench/cra-default-ts rm -rf node_modules mkdir node_modules - npx -p @storybook/bench@0.7.6--canary.14.6702e4f.0 sb-bench 'yarn install' --label cra + npx -p @storybook/bench@next sb-bench 'yarn install' --label cra + - report-workflow-on-failure - run: name: prep artifacts when: always - command: tar cvzf /tmp/sb-bench.tar.gz ../cra-bench + command: tar cvzf /tmp/cra-default-ts-bench.tar.gz bench/cra-default-ts - store_artifacts: - path: /tmp/sb-bench.tar.gz - destination: sb-bench.tar.gz + path: /tmp/cra-default-ts-bench.tar.gz + destination: cra-default-ts-bench.tar.gz react-vite-bench: executor: class: large @@ -281,24 +313,25 @@ jobs: name: set up react-vite repro, skip tests command: | cd code - node ./lib/cli/bin/index.js repro-next react-vite/default-ts --output ../../react-vite-bench + SANDBOX_ROOT=../bench yarn task --task sandbox --template react-vite/default-ts --skip-template-stories --start-from=never --no-link - run: name: Run @storybook/bench on repro command: | - cd ../react-vite-bench + cd bench/react-vite-default-ts rm -rf node_modules mkdir node_modules - npx -p @storybook/bench@0.7.6--canary.14.6702e4f.0 sb-bench 'yarn install' --label react-vite + npx -p @storybook/bench@next sb-bench 'yarn install' --label react-vite + - report-workflow-on-failure - run: name: prep artifacts when: always - command: tar cvzf /tmp/sb-bench.tar.gz ../react-vite-bench + command: tar cvzf /tmp/react-vite-default-ts-bench.tar.gz bench/react-vite-default-ts - store_artifacts: - path: /tmp/sb-bench.tar.gz - destination: sb-bench.tar.gz + path: /tmp/react-vite-default-ts-bench.tar.gz + destination: react-vite-default-ts-bench.tar.gz lint: executor: - class: medium + class: large name: sb_node_16_classic steps: - checkout_advanced: @@ -310,6 +343,7 @@ jobs: command: | cd code yarn lint + - report-workflow-on-failure - cancel-workflow-on-failure check: executor: @@ -325,6 +359,7 @@ jobs: command: | yarn task --task check --start-from=auto --no-link --debug git diff --exit-code + - report-workflow-on-failure - cancel-workflow-on-failure script-unit-tests: executor: sb_node_16_browsers @@ -340,6 +375,7 @@ jobs: yarn test --coverage --ci - store_test_results: path: scripts/junit.xml + - report-workflow-on-failure - cancel-workflow-on-failure unit-tests: executor: @@ -354,13 +390,14 @@ jobs: name: Test command: | cd code - yarn test --coverage --ci + yarn test --coverage --ci --maxWorkers=6 - store_test_results: path: code/junit.xml - persist_to_workspace: root: . paths: - code/coverage + - report-workflow-on-failure - cancel-workflow-on-failure coverage: executor: @@ -376,10 +413,13 @@ jobs: command: | cd code yarn coverage + - report-workflow-on-failure chromatic-internal-storybooks: executor: - class: medium + class: medium+ name: sb_node_16_browsers + environment: + NODE_OPTIONS: --max_old_space_size=6144 steps: # switched this to the CircleCI helper to get the full git history for TurboSnap - checkout @@ -391,6 +431,7 @@ jobs: cd code yarn storybook:ui:chromatic yarn storybook:blocks:chromatic + - report-workflow-on-failure - store_test_results: path: test-results ## new workflow @@ -410,7 +451,9 @@ jobs: at: . - run: name: Creating Sandboxes - command: yarn task --task sandbox --template $(yarn get-template << pipeline.parameters.workflow >> create) --no-link --start-from=never --junit + command: yarn task --task sandbox --template $(yarn get-template << pipeline.parameters.workflow >> sandbox) --no-link --start-from=never --junit + - report-workflow-on-failure: + template: $(yarn get-template << pipeline.parameters.workflow >> sandbox) - persist_to_workspace: root: . paths: @@ -434,6 +477,8 @@ jobs: - run: name: Smoke Testing Sandboxes command: yarn task --task smoke-test --template $(yarn get-template << pipeline.parameters.workflow >> smoke-test) --no-link --start-from=never --junit + - report-workflow-on-failure: + template: $(yarn get-template << pipeline.parameters.workflow >> smoke-test) - store_test_results: path: test-results build-sandboxes: @@ -453,6 +498,8 @@ jobs: - run: name: Building Sandboxes command: yarn task --task build --template $(yarn get-template << pipeline.parameters.workflow >> build) --no-link --start-from=never --junit + - report-workflow-on-failure: + template: $(yarn get-template << pipeline.parameters.workflow >> build) - store_test_results: path: test-results - persist_to_workspace: @@ -476,6 +523,8 @@ jobs: - run: name: Running Test Runner command: yarn task --task test-runner --template $(yarn get-template << pipeline.parameters.workflow >> test-runner) --no-link --start-from=never --junit + - report-workflow-on-failure: + template: $(yarn get-template << pipeline.parameters.workflow >> test-runner) - store_test_results: path: test-results chromatic-sandboxes: @@ -494,6 +543,8 @@ jobs: - run: name: Running Chromatic command: yarn task --task chromatic --template $(yarn get-template << pipeline.parameters.workflow >> chromatic) --no-link --start-from=never --junit + - report-workflow-on-failure: + template: $(yarn get-template << pipeline.parameters.workflow >> chromatic) - store_test_results: path: test-results e2e-sandboxes: @@ -513,6 +564,8 @@ jobs: - run: name: Running E2E Tests command: yarn task --task e2e-tests --template $(yarn get-template << pipeline.parameters.workflow >> e2e-tests) --no-link --start-from=never --junit + - report-workflow-on-failure: + template: $(yarn get-template << pipeline.parameters.workflow >> e2e-tests) - store_test_results: path: test-results - store_artifacts: # this is where playwright puts more complex stuff @@ -523,9 +576,10 @@ workflows: ci: when: and: - - equal: [ api, << pipeline.trigger_source >> ] - - equal: [ ci, << pipeline.parameters.workflow >> ] + - equal: [api, << pipeline.trigger_source >>] + - equal: [ci, << pipeline.parameters.workflow >>] jobs: + - pretty-docs - build - lint: requires: @@ -556,8 +610,9 @@ workflows: - build-sandboxes pr: when: - equal: [ pr, << pipeline.parameters.workflow >> ] + equal: [pr, << pipeline.parameters.workflow >>] jobs: + - pretty-docs - build - lint: requires: @@ -605,8 +660,9 @@ workflows: - build-sandboxes merged: when: - equal: [ merged, << pipeline.parameters.workflow >> ] + equal: [merged, << pipeline.parameters.workflow >>] jobs: + - pretty-docs - build - lint: requires: @@ -633,11 +689,11 @@ workflows: requires: - build - create-sandboxes: - parallelism: 14 + parallelism: 15 requires: - build - build-sandboxes: - parallelism: 14 + parallelism: 15 requires: - create-sandboxes - test-runner-sandboxes: @@ -645,27 +701,27 @@ workflows: requires: - build-sandboxes - chromatic-sandboxes: - parallelism: 14 + parallelism: 15 requires: - build-sandboxes - e2e-sandboxes: - parallelism: 14 + parallelism: 15 requires: - build-sandboxes daily: when: - equal: [ daily, << pipeline.parameters.workflow >> ] + equal: [daily, << pipeline.parameters.workflow >>] jobs: - build - create-sandboxes: - parallelism: 24 + parallelism: 25 requires: - build # - smoke-test-sandboxes: # disabled for now # requires: # - create-sandboxes - build-sandboxes: - parallelism: 24 + parallelism: 25 requires: - create-sandboxes - test-runner-sandboxes: @@ -673,10 +729,10 @@ workflows: requires: - build-sandboxes - chromatic-sandboxes: - parallelism: 24 + parallelism: 25 requires: - build-sandboxes - e2e-sandboxes: - parallelism: 24 + parallelism: 25 requires: - - build-sandboxes \ No newline at end of file + - build-sandboxes diff --git a/.github/workflows/generate-repros-next.yml b/.github/workflows/generate-repros-next.yml index 42b36076d37b..fcd1ee8072c5 100644 --- a/.github/workflows/generate-repros-next.yml +++ b/.github/workflows/generate-repros-next.yml @@ -28,6 +28,12 @@ jobs: run: node ./scripts/check-dependencies.js - name: Compile Storybook libraries run: yarn task --task publish --start-from=auto --no-link + - name: Running local registry + run: yarn local-registry --port 6001 --open & + working-directory: ./code + - name: Wait for registry + run: yarn wait-on http://localhost:6001 + working-directory: ./code - name: Generate repros run: yarn generate-repros-next --local-registry working-directory: ./code diff --git a/.gitignore b/.gitignore index 41baa60da98e..25b6e5a7b525 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ junit.xml test-results /repros /sandbox +/bench .verdaccio-cache # Yarn stuff diff --git a/CHANGELOG.md b/CHANGELOG.md index 5faead8d09d2..39bce5bab28e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,86 @@ +## 7.0.0-alpha.51 (November 19, 2022) + +#### Bug Fixes + +- NextJS: Fix out-of-the-box babel handling [#19842](https://github.com/storybooks/storybook/pull/19842) +- NextJS: Fix import url on windows [#19798](https://github.com/storybooks/storybook/pull/19798) +- UI: Fix panel invisible for any addon listed after the interactions panel [#19771](https://github.com/storybooks/storybook/pull/19771) +- Core: Bail preview builder on failure [#19849](https://github.com/storybooks/storybook/pull/19849) +- Core: Fix double esbuild-register register [#19852](https://github.com/storybooks/storybook/pull/19852) +- Composition: Fix regression in the `#root` to `#storybook-root` change [#19848](https://github.com/storybooks/storybook/pull/19848) +- UI: Fix `showPanel=false` doesn't work on mobile view [#19807](https://github.com/storybooks/storybook/pull/19807) + +#### Maintenance + +- CLI: Replace degit with giget [#19870](https://github.com/storybooks/storybook/pull/19870) +- Build: Bundle lib/channel-websocket with tsup [#19694](https://github.com/storybooks/storybook/pull/19694) +- Maintenance: Upgrade monorepo to TS 4.9 [#19869](https://github.com/storybooks/storybook/pull/19869) + +#### Build + +- Build: Downgrade @types/node [#19890](https://github.com/storybooks/storybook/pull/19890) +- Maintenance: Add angular 14 template and skip test runner on angular 15 for now [#19871](https://github.com/storybooks/storybook/pull/19871) +- Build: Upgrade Jest to 29 [#19863](https://github.com/storybooks/storybook/pull/19863) +- Build: Fix chromatic version to 6.11.2 in local scripts [#19889](https://github.com/storybooks/storybook/pull/19889) +- Build: Pin chromatic version to 6.11.2 to temporary fix flakiness [#19874](https://github.com/storybooks/storybook/pull/19874) + +#### Dependency Upgrades + +- Bump mdx2-csf dependency [#19885](https://github.com/storybooks/storybook/pull/19885) + +## 7.0.0-alpha.50 (November 17, 2022) + +#### Features + +- Expose more CSF types in all renderers [#19833](https://github.com/storybooks/storybook/pull/19833) +- CSF: Renamed Framework to Renderer [#19802](https://github.com/storybooks/storybook/pull/19802) + +#### Bug Fixes + +- Next.js: use file path instead of image contents for next-image-loader-stub [#19858](https://github.com/storybooks/storybook/pull/19858) +- TypeScript: Fix type inference bug with decorators [#19839](https://github.com/storybooks/storybook/pull/19839) +- Vite: Keep using absolute path node_modules splitting [#19836](https://github.com/storybooks/storybook/pull/19836) +- Vite: Fix preview annotation paths on Windows [#19822](https://github.com/storybooks/storybook/pull/19822) +- Fix csf-plugin ignoring options [#19823](https://github.com/storybooks/storybook/pull/19823) +- Controls: Checkbox does not update when using useArgs hook [#19508](https://github.com/storybooks/storybook/pull/19508) + +#### Maintenance + +- Jest: switch from Parameters to StorybookInternalParameters [#19853](https://github.com/storybooks/storybook/pull/19853) +- Blocks: Story stories [#19805](https://github.com/storybooks/storybook/pull/19805) +- Blocks: Canvas stories [#19804](https://github.com/storybooks/storybook/pull/19804) +- Tech: TypeScript should check stories and tests as well [#19831](https://github.com/storybooks/storybook/pull/19831) + +#### Build + +- UI Storybook: Disable sourcemaps when building in CI [#19862](https://github.com/storybooks/storybook/pull/19862) +- Build: Increase max node memory for jobs [#19856](https://github.com/storybooks/storybook/pull/19856) +- CI: improve error reporting mechanism [#19841](https://github.com/storybooks/storybook/pull/19841) +- Fix tests on Windows [#19777](https://github.com/storybooks/storybook/pull/19777) +- Build: Fix benchmark to run on local packages [#19832](https://github.com/storybooks/storybook/pull/19832) +- CI: Report failures on discord [#19801](https://github.com/storybooks/storybook/pull/19801) + +## 7.0.0-alpha.49 (November 13, 2022) + +#### Bug Fixes + +- Essentials: Fix preview annotations for Vite pnpm support [#19689](https://github.com/storybooks/storybook/pull/19689) + +#### Maintenance + +- Build: convert addon-docs to use ts-up [#19790](https://github.com/storybooks/storybook/pull/19790) +- Core: Allow overriding WebView and UrlStore [#19623](https://github.com/storybooks/storybook/pull/19623) +- Storyshots: Support .cjs and .mjs file extensions [#19726](https://github.com/storybooks/storybook/pull/19726) + +#### Build + +- Build: less noise when compiling [#19808](https://github.com/storybooks/storybook/pull/19808) +- Build: Upgrade bench to `next` [#19791](https://github.com/storybooks/storybook/pull/19791) +- Maintenance: improve error feedback when tasks fail in CI [#19786](https://github.com/storybooks/storybook/pull/19786) +- UI: Enable TurboSnap for UI Storybook [#19767](https://github.com/storybooks/storybook/pull/19767) +- CI: Use a new cadence (ci, pr, merged, daily) and trigger CircleCI from github actions [#19768](https://github.com/storybooks/storybook/pull/19768) +- Maintenance: provide expected failure metadata in junit reports [#19775](https://github.com/storybooks/storybook/pull/19775) + ## 7.0.0-alpha.48 (November 7, 2022) #### Breaking Changes @@ -542,9 +625,10 @@ Bad publish #### Bug Fixes -- CLI: Fix race condition in sb init [#19083](https://github.com/storybooks/storybook/pull/19083) -- Vite: Fix framework option checks, and SSv6 [#19062](https://github.com/storybooks/storybook/pull/19062) -- Core: Fix WebProjectAnnotations export in preview-web for back-compat [#19048](https://github.com/storybooks/storybook/pull/19048) +- CLI: Fix race condition in sb init [#19083](https://github.com/storybooks/storybook/pull/19083) +- Vite: Fix framework option checks, and SSv6 [#19062](https://github.com/storybooks/storybook/pull/19062) +- Core: Fix WebProjectAnnotations export in preview-web for back-compat [#19048](https://github.com/storybooks/storybook/pull/19048) +- Blocks: Fix Checkbox control update when using useArgs hook #### Maintenance diff --git a/MIGRATION.md b/MIGRATION.md index 06dac6694ebb..2f9f0c15c407 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -43,7 +43,9 @@ - [7.0 Deprecations](#70-deprecations) - [`Story` type deprecated](#story-type-deprecated) - [`ComponentStory`, `ComponentStoryObj`, `ComponentStoryFn` and `ComponentMeta` types are deprecated](#componentstory-componentstoryobj-componentstoryfn-and-componentmeta-types-are-deprecated) - - [Renamed `renderToDOM` to `renderToCanvas`](#renamed-rendertodom-to-rendertoroot) + - [Renamed `renderToDOM` to `renderToCanvas`](#renamed-rendertodom-to-rendertocanvas) + - [Renamed `XFramework` to `XRenderer`](#renamed-xframework-to-xrenderer) + - [Renamed `DecoratorFn` to `Decorator`](#renamed-decoratorfn-to-decorator) - [From version 6.4.x to 6.5.0](#from-version-64x-to-650) - [Vue 3 upgrade](#vue-3-upgrade) - [React18 new root API](#react18-new-root-api) @@ -841,6 +843,69 @@ CSF2Story.args = { label: 'Label' }; The "rendering" function that renderers (ex-frameworks) must export (`renderToDOM`) has been renamed to `renderToCanvas` to acknowledge that some consumers of frameworks/the preview do not work with DOM elements. +#### Renamed `XFramework` to `XRenderer` + +In 6.x you could import XFramework types: + +```ts +import type { ReactFramework } from '@storybook/react'; +import type { VueFramework } from '@storybook/vue'; +import type { SvelteFramework } from '@storybook/svelte'; + +// etc. +``` + +Those are deprecated in 7.0 as they are renamed to: + +```ts +import type { ReactRenderer } from '@storybook/react'; +import type { VueRenderer } from '@storybook/vue'; +import type { SvelteRenderer } from '@storybook/svelte'; + +// etc. +``` + +#### Renamed `DecoratorFn` to `Decorator` + +In 6.x you could import the type `DecoratorFn`: + +```ts +import type { DecoratorFn } from '@storybook/react'; +``` + +This type is deprecated in 7.0, instead you can use the type `Decorator`, which is now available for all renderers: + +```ts +import type { Decorator } from '@storybook/react'; +// or +import type { Decorator } from '@storybook/vue'; +// or +import type { Decorator } from '@storybook/svelte'; +// etc. +``` + +The type `Decorator` accepts a generic parameter `TArgs`. This can be used like this: + +```tsx +import type { Decorator } from '@storybook/react'; +import { LocaleProvider } from './locale'; + +const withLocale: Decorator<{ locale: 'en' | 'es' }> = (Story, { args }) => ( + + + +); +``` + +If you want to use `Decorator` in a backwards compatible way to `DecoratorFn`, you can use: + +```tsx +import type { Args, Decorator } from '@storybook/react'; + +// Decorator behaves the same as DecoratorFn (without generic) +const withLocale: Decorator = (Story, { args }) => // args has type { [name: string]: any } +``` + ## From version 6.4.x to 6.5.0 ### Vue 3 upgrade diff --git a/README.md b/README.md index fd4b1a777064..7462b6c9fcb7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@

- Storybook + + + Storybook + + +

Build bulletproof UI components faster

diff --git a/code/.eslintignore b/code/.eslintignore index 6f8539b9b7b6..3a410b6472bc 100644 --- a/code/.eslintignore +++ b/code/.eslintignore @@ -1,5 +1,4 @@ dist -lib/**/dll build coverage node_modules diff --git a/code/addons/a11y/jest.config.js b/code/addons/a11y/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/a11y/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/a11y/package.json b/code/addons/a11y/package.json index 94be93335614..212f173d2ce2 100644 --- a/code/addons/a11y/package.json +++ b/code/addons/a11y/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-a11y", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Test component compliance with web accessibility standards", "keywords": [ "a11y", @@ -62,15 +62,15 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addon-highlight": "7.0.0-alpha.48", - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/channels": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/addon-highlight": "7.0.0-alpha.51", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/channels": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "axe-core": "^4.2.0", "global": "^4.4.0", "lodash": "^4.17.21", @@ -78,7 +78,7 @@ }, "devDependencies": { "@testing-library/react": "^11.2.2", - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -102,7 +102,7 @@ "./src/preview.tsx" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Accessibility", "icon": "https://user-images.githubusercontent.com/263385/101991665-47042f80-3c7c-11eb-8f00-64b5a18f498a.png", diff --git a/code/addons/actions/jest.config.js b/code/addons/actions/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/actions/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/actions/package.json b/code/addons/actions/package.json index cd45f1d91c8e..bd85b1c9ba07 100644 --- a/code/addons/actions/package.json +++ b/code/addons/actions/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-actions", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Get UI feedback when an action is performed on an interactive element", "keywords": [ "storybook", @@ -52,6 +52,19 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -63,13 +76,13 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "dequal": "^2.0.2", "global": "^4.4.0", "lodash": "^4.17.21", @@ -82,7 +95,7 @@ }, "devDependencies": { "@types/lodash": "^4.14.167", - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -107,7 +120,7 @@ "./src/preview.ts" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Actions", "unsupportedFrameworks": [ diff --git a/code/addons/actions/src/addArgsHelpers.ts b/code/addons/actions/src/addArgsHelpers.ts index 6a91c6e1ddef..530cb76c0621 100644 --- a/code/addons/actions/src/addArgsHelpers.ts +++ b/code/addons/actions/src/addArgsHelpers.ts @@ -1,4 +1,4 @@ -import type { Args, Framework, ArgsEnhancer } from '@storybook/types'; +import type { Args, Renderer, ArgsEnhancer } from '@storybook/types'; import { action } from './runtime/action'; // interface ActionsParameter { @@ -14,7 +14,7 @@ const isInInitialArgs = (name: string, initialArgs: Args) => * matches a regex, such as `^on.*` for react-style `onClick` etc. */ -export const inferActionsFromArgTypesRegex: ArgsEnhancer = (context) => { +export const inferActionsFromArgTypesRegex: ArgsEnhancer = (context) => { const { initialArgs, argTypes, @@ -40,7 +40,7 @@ export const inferActionsFromArgTypesRegex: ArgsEnhancer = (context) /** * Add action args for list of strings. */ -export const addActionsFromArgTypes: ArgsEnhancer = (context) => { +export const addActionsFromArgTypes: ArgsEnhancer = (context) => { const { initialArgs, argTypes, diff --git a/code/addons/actions/tsconfig.json b/code/addons/actions/tsconfig.json index 25de4fbd3e60..a4429176e35f 100644 --- a/code/addons/actions/tsconfig.json +++ b/code/addons/actions/tsconfig.json @@ -3,13 +3,5 @@ "compilerOptions": { "strict": true }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/backgrounds/jest.config.js b/code/addons/backgrounds/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/backgrounds/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/backgrounds/package.json b/code/addons/backgrounds/package.json index 2584ee916f76..b001b099307f 100644 --- a/code/addons/backgrounds/package.json +++ b/code/addons/backgrounds/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-backgrounds", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Switch backgrounds to view components in different settings", "keywords": [ "addon", @@ -51,6 +51,19 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -62,19 +75,19 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "global": "^4.4.0", "memoizerific": "^1.11.3", "ts-dedent": "^2.0.0" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -98,7 +111,7 @@ "./src/preview.tsx" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Backgrounds", "icon": "https://user-images.githubusercontent.com/263385/101991667-479cc600-3c7c-11eb-96d3-410e936252e7.png", diff --git a/code/addons/backgrounds/src/decorators/withBackground.ts b/code/addons/backgrounds/src/decorators/withBackground.ts index 49500b8a7c12..309c6a8f7599 100644 --- a/code/addons/backgrounds/src/decorators/withBackground.ts +++ b/code/addons/backgrounds/src/decorators/withBackground.ts @@ -1,5 +1,5 @@ import { useMemo, useEffect } from '@storybook/addons'; -import type { Framework, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; +import type { Renderer, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; import { PARAM_KEY as BACKGROUNDS_PARAM_KEY } from '../constants'; import { @@ -10,8 +10,8 @@ import { } from '../helpers'; export const withBackground = ( - StoryFn: StoryFunction, - context: StoryContext + StoryFn: StoryFunction, + context: StoryContext ) => { const { globals, parameters } = context; const globalsBackgroundColor = globals[BACKGROUNDS_PARAM_KEY]?.value; diff --git a/code/addons/backgrounds/src/decorators/withGrid.ts b/code/addons/backgrounds/src/decorators/withGrid.ts index 8e129dcf5af9..3647dd2f4cad 100644 --- a/code/addons/backgrounds/src/decorators/withGrid.ts +++ b/code/addons/backgrounds/src/decorators/withGrid.ts @@ -1,10 +1,10 @@ import { useMemo, useEffect } from '@storybook/addons'; -import type { Framework, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; +import type { Renderer, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; import { clearStyles, addGridStyle } from '../helpers'; import { PARAM_KEY as BACKGROUNDS_PARAM_KEY } from '../constants'; -export const withGrid = (StoryFn: StoryFunction, context: StoryContext) => { +export const withGrid = (StoryFn: StoryFunction, context: StoryContext) => { const { globals, parameters } = context; const gridParameters = parameters[BACKGROUNDS_PARAM_KEY].grid; const isActive = globals[BACKGROUNDS_PARAM_KEY]?.grid === true && gridParameters.disable !== true; diff --git a/code/addons/backgrounds/tsconfig.json b/code/addons/backgrounds/tsconfig.json index d23f9a406fc2..52d43eaaa9b9 100644 --- a/code/addons/backgrounds/tsconfig.json +++ b/code/addons/backgrounds/tsconfig.json @@ -1,12 +1,4 @@ { "extends": "../../tsconfig.json", - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/controls/jest.config.js b/code/addons/controls/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/controls/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/controls/package.json b/code/addons/controls/package.json index c51bf2682882..051c62d9dc00 100644 --- a/code/addons/controls/package.json +++ b/code/addons/controls/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-controls", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Interact with component inputs dynamically in the Storybook UI", "keywords": [ "addon", @@ -46,6 +46,16 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -57,16 +67,16 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/blocks": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/node-logger": "7.0.0-alpha.48", - "@storybook/store": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/blocks": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-common": "7.0.0-alpha.51", + "@storybook/node-logger": "7.0.0-alpha.51", + "@storybook/store": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "lodash": "^4.17.21", "ts-dedent": "^2.0.0" }, @@ -92,7 +102,7 @@ ], "platform": "browser" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Controls", "icon": "https://user-images.githubusercontent.com/263385/101991669-479cc600-3c7c-11eb-93d9-38b67e8371f2.png", diff --git a/code/addons/controls/tsconfig.json b/code/addons/controls/tsconfig.json index 25de4fbd3e60..a4429176e35f 100644 --- a/code/addons/controls/tsconfig.json +++ b/code/addons/controls/tsconfig.json @@ -3,13 +3,5 @@ "compilerOptions": { "strict": true }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/docs/jest.config.js b/code/addons/docs/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/docs/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/docs/package.json b/code/addons/docs/package.json index 912874857cd0..e6cfee21fb79 100644 --- a/code/addons/docs/package.json +++ b/code/addons/docs/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-docs", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Document component usage and properties in Markdown", "keywords": [ "addon", @@ -24,9 +24,44 @@ "url": "https://opencollective.com/storybook" }, "license": "MIT", - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", - "types": "dist/types/index.d.ts", + "exports": { + ".": { + "require": "./dist/index.js", + "import": "./dist/index.mjs", + "types": "./dist/index.d.ts" + }, + "./preview": { + "require": "./dist/preview.js", + "import": "./dist/preview.mjs", + "types": "./dist/preview.d.ts" + }, + "./preset": { + "require": "./dist/preset.js", + "import": "./dist/preset.mjs", + "types": "./dist/preset.d.ts" + }, + "./dist/preview": { + "require": "./dist/preview.js", + "import": "./dist/preview.mjs", + "types": "./dist/preview.d.ts" + }, + "./dist/preset": { + "require": "./dist/preset.js", + "import": "./dist/preset.mjs", + "types": "./dist/preset.d.ts" + }, + "./svelte/HOC.svelte": "./svelte/HOC.svelte", + "./ember": "./ember/index.js", + "./ember/index.js": "./ember/index.js", + "./angular": "./angular/index.js", + "./angular/index.js": "./angular/index.js", + "./web-components/index.js": "./web-components/index.js", + "./jest-transform-mdx": "./jest-transform-mdx.js", + "./package.json": "./package.json" + }, + "main": "dist/index.js", + "module": "dist/index.mjs", + "types": "dist/index.d.ts", "files": [ "dist/**/*", "angular/**/*", @@ -46,29 +81,21 @@ ], "scripts": { "check": "../../../scripts/node_modules/.bin/tsc --noEmit", - "prep": "node ../../../scripts/prepare.js" + "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@babel/plugin-transform-react-jsx": "^7.12.12", - "@jest/transform": "^26.6.2", + "@babel/plugin-transform-react-jsx": "^7.19.0", + "@jest/transform": "^29.3.1", "@mdx-js/react": "^2.1.5", - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/blocks": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/csf-plugin": "7.0.0-alpha.48", - "@storybook/csf-tools": "7.0.0-alpha.48", - "@storybook/docs-tools": "7.0.0-alpha.48", + "@storybook/blocks": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/csf-plugin": "7.0.0-alpha.51", + "@storybook/csf-tools": "7.0.0-alpha.51", "@storybook/mdx2-csf": "next", - "@storybook/node-logger": "7.0.0-alpha.48", - "@storybook/postinstall": "7.0.0-alpha.48", - "@storybook/preview-web": "7.0.0-alpha.48", - "@storybook/store": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", - "dequal": "^2.0.2", + "@storybook/node-logger": "7.0.0-alpha.51", + "@storybook/postinstall": "7.0.0-alpha.51", + "@storybook/preview-web": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "fs-extra": "^9.0.1", "global": "^4.4.0", "remark-external-links": "^8.0.0", @@ -76,8 +103,8 @@ "ts-dedent": "^2.0.0" }, "devDependencies": { - "@babel/core": "^7.12.10", - "typescript": "~4.6.3" + "@babel/core": "^7.20.2", + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -94,7 +121,14 @@ "publishConfig": { "access": "public" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "bundler": { + "entries": [ + "./src/index.ts", + "./src/preset.ts", + "./src/preview.ts" + ] + }, + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Docs", "icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png", diff --git a/code/addons/docs/preset.js b/code/addons/docs/preset.js index e45ac5b4cec0..a83f95279e7f 100644 --- a/code/addons/docs/preset.js +++ b/code/addons/docs/preset.js @@ -1 +1 @@ -module.exports = require('./dist/cjs/preset'); +module.exports = require('./dist/preset'); diff --git a/code/addons/docs/preview.js b/code/addons/docs/preview.js index e726cab5a1b6..49ad602f79f4 100644 --- a/code/addons/docs/preview.js +++ b/code/addons/docs/preview.js @@ -1 +1 @@ -export * from './dist/esm/preview'; +export * from './dist/preview'; diff --git a/code/addons/docs/src/DocsRenderer.tsx b/code/addons/docs/src/DocsRenderer.tsx index fb55fcb33f06..b1c6a6391a16 100644 --- a/code/addons/docs/src/DocsRenderer.tsx +++ b/code/addons/docs/src/DocsRenderer.tsx @@ -1,6 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import type { Framework, Parameters } from '@storybook/types'; +import type { Renderer, Parameters } from '@storybook/types'; import type { DocsContextProps, DocsRenderFunction } from '@storybook/preview-web'; import { components as htmlComponents } from '@storybook/components'; import { Docs, CodeOrSourceMdx, AnchorMdx, HeadersMdx } from '@storybook/blocks'; @@ -14,14 +14,14 @@ export const defaultComponents: Record = { ...HeadersMdx, }; -export class DocsRenderer { - public render: DocsRenderFunction; +export class DocsRenderer { + public render: DocsRenderFunction; public unmount: (element: HTMLElement) => void; constructor() { this.render = ( - context: DocsContextProps, + context: DocsContextProps, docsParameter: Parameters, element: HTMLElement, callback: () => void @@ -33,6 +33,7 @@ export class DocsRenderer { ...defaultComponents, ...docsParameter?.components, }; + ReactDOM.render( diff --git a/code/addons/docs/src/blocks.ts b/code/addons/docs/src/blocks.ts deleted file mode 100644 index 119f7ce62757..000000000000 --- a/code/addons/docs/src/blocks.ts +++ /dev/null @@ -1 +0,0 @@ -export * from '@storybook/blocks'; diff --git a/code/addons/docs/src/index.ts b/code/addons/docs/src/index.ts index 807e2656e5b8..b74399955f12 100644 --- a/code/addons/docs/src/index.ts +++ b/code/addons/docs/src/index.ts @@ -1,2 +1,2 @@ -export * from './blocks'; +export * from '@storybook/blocks'; export { DocsRenderer } from './DocsRenderer'; diff --git a/code/addons/docs/src/preset.ts b/code/addons/docs/src/preset.ts index 0538a94fabd6..df92976b9696 100644 --- a/code/addons/docs/src/preset.ts +++ b/code/addons/docs/src/preset.ts @@ -16,12 +16,11 @@ import { loadCsf } from '@storybook/csf-tools'; // the jsx to transpile mdx, for now there will be a flag for that // for more complex solutions we can find alone that we need to add '@babel/plugin-transform-react-jsx' type BabelParams = { - babelOptions?: any; mdxBabelOptions?: any; configureJSX?: boolean; }; -function createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }: BabelParams) { - const babelPlugins = mdxBabelOptions?.plugins || babelOptions?.plugins || []; +function createBabelOptions({ mdxBabelOptions, configureJSX }: BabelParams) { + const babelPlugins = mdxBabelOptions?.plugins || []; const filteredBabelPlugins = babelPlugins.filter((p: any) => { const name = Array.isArray(p) ? p[0] : p; @@ -40,13 +39,12 @@ function createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }: Bab // don't use the root babelrc by default (users can override this in mdxBabelOptions) babelrc: false, configFile: false, - ...babelOptions, ...mdxBabelOptions, plugins, }; } -export async function webpack( +async function webpack( webpackConfig: any = {}, options: Options & BabelParams & { @@ -65,7 +63,6 @@ export async function webpack( // it will reuse babel options that are already in use in storybook // also, these babel options are chained with other presets. const { - babelOptions, mdxBabelOptions, configureJSX = true, csfPluginOptions = {}, @@ -100,7 +97,7 @@ export async function webpack( use: [ { loader: resolvedBabelLoader, - options: createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }), + options: createBabelOptions({ mdxBabelOptions, configureJSX }), }, { loader: mdxLoader, @@ -128,7 +125,7 @@ export async function webpack( use: [ { loader: resolvedBabelLoader, - options: createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }), + options: createBabelOptions({ mdxBabelOptions, configureJSX }), }, { loader: mdxLoader, @@ -145,7 +142,7 @@ export async function webpack( use: [ { loader: resolvedBabelLoader, - options: createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }), + options: createBabelOptions({ mdxBabelOptions, configureJSX }), }, { loader: mdxLoader, @@ -160,7 +157,7 @@ export async function webpack( return result; } -export const storyIndexers = (indexers: CoreCommon_StoryIndexer[] | null) => { +const storyIndexers = (indexers: CoreCommon_StoryIndexer[] | null) => { const mdxIndexer = async (fileName: string, opts: CoreCommon_IndexerOptions) => { let code = (await fs.readFile(fileName, 'utf-8')).toString(); const { compile } = await import('@storybook/mdx2-csf'); @@ -176,7 +173,7 @@ export const storyIndexers = (indexers: CoreCommon_StoryIndexer[] | null) => { ]; }; -export const docs = (docsOptions: DocsOptions) => { +const docs = (docsOptions: DocsOptions) => { return { ...docsOptions, enabled: true, @@ -184,3 +181,13 @@ export const docs = (docsOptions: DocsOptions) => { docsPage: true, }; }; + +/* + * This is a workaround for https://github.com/Swatinem/rollup-plugin-dts/issues/162 + * something down the dependency chain is using typescript namespaces, which are not supported by rollup-plugin-dts + */ +const webpackX = webpack as any; +const storyIndexersX = storyIndexers as any; +const docsX = docs as any; + +export { webpackX as webpack, storyIndexersX as storyIndexers, docsX as docs }; diff --git a/code/addons/docs/src/shared.ts b/code/addons/docs/src/shared.ts deleted file mode 100644 index 178bf46ca387..000000000000 --- a/code/addons/docs/src/shared.ts +++ /dev/null @@ -1,28 +0,0 @@ -export const ADDON_ID = 'storybook/docs'; -export const PANEL_ID = `${ADDON_ID}/panel`; -export const PARAM_KEY = `docs`; - -export const SNIPPET_RENDERED = `${ADDON_ID}/snippet-rendered`; - -export enum SourceType { - /** - * AUTO is the default - * - * Use the CODE logic if: - * - the user has set a custom source snippet in `docs.source.code` story parameter - * - the story is not an args-based story - * - * Use the DYNAMIC rendered snippet if the story is an args story - */ - AUTO = 'auto', - - /** - * Render the code extracted by source-loader - */ - CODE = 'code', - - /** - * Render dynamically-rendered source snippet from the story's virtual DOM (currently React only) - */ - DYNAMIC = 'dynamic', -} diff --git a/code/addons/docs/tsconfig.json b/code/addons/docs/tsconfig.json index b1bd17fc8aed..cf1e09965901 100644 --- a/code/addons/docs/tsconfig.json +++ b/code/addons/docs/tsconfig.json @@ -3,12 +3,5 @@ "compilerOptions": { "skipLibCheck": true }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/essentials/jest.config.js b/code/addons/essentials/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/essentials/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/essentials/package.json b/code/addons/essentials/package.json index 7445ad9c83d3..65ed32752123 100644 --- a/code/addons/essentials/package.json +++ b/code/addons/essentials/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-essentials", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Curated addons to bring out the best of Storybook", "keywords": [ "addon", @@ -27,6 +27,76 @@ "import": "./dist/index.mjs", "types": "./dist/index.d.ts" }, + "./actions/preview": { + "require": "./dist/actions/preview.js", + "import": "./dist/actions/preview.mjs", + "types": "./dist/actions/preview.d.ts" + }, + "./actions/manager": { + "require": "./dist/actions/manager.js", + "import": "./dist/actions/manager.mjs", + "types": "./dist/actions/manager.d.ts" + }, + "./backgrounds/preview": { + "require": "./dist/backgrounds/preview.js", + "import": "./dist/backgrounds/preview.mjs", + "types": "./dist/backgrounds/preview.d.ts" + }, + "./backgrounds/manager": { + "require": "./dist/backgrounds/manager.js", + "import": "./dist/backgrounds/manager.mjs", + "types": "./dist/backgrounds/manager.d.ts" + }, + "./controls/manager": { + "require": "./dist/controls/manager.js", + "import": "./dist/controls/manager.mjs", + "types": "./dist/controls/manager.d.ts" + }, + "./docs/preview": { + "require": "./dist/docs/preview.js", + "import": "./dist/docs/preview.mjs", + "types": "./dist/docs/preview.d.ts" + }, + "./docs/preset": { + "require": "./dist/docs/preset.js", + "import": "./dist/docs/preset.mjs", + "types": "./dist/docs/preset.d.ts" + }, + "./highlight/preview": { + "require": "./dist/highlight/preview.js", + "import": "./dist/highlight/preview.mjs", + "types": "./dist/highlight/preview.d.ts" + }, + "./measure/preview": { + "require": "./dist/measure/preview.js", + "import": "./dist/measure/preview.mjs", + "types": "./dist/measure/preview.d.ts" + }, + "./measure/manager": { + "require": "./dist/measure/manager.js", + "import": "./dist/measure/manager.mjs", + "types": "./dist/measure/manager.d.ts" + }, + "./outline/preview": { + "require": "./dist/outline/preview.js", + "import": "./dist/outline/preview.mjs", + "types": "./dist/outline/preview.d.ts" + }, + "./outline/manager": { + "require": "./dist/outline/manager.js", + "import": "./dist/outline/manager.mjs", + "types": "./dist/outline/manager.d.ts" + }, + "./toolbars/manager": { + "require": "./dist/toolbars/manager.js", + "import": "./dist/toolbars/manager.mjs", + "types": "./dist/toolbars/manager.d.ts" + }, + "./viewport/manager": { + "require": "./dist/viewport/manager.js", + "import": "./dist/viewport/manager.mjs", + "types": "./dist/viewport/manager.d.ts" + }, "./package.json": "./package.json" }, "main": "dist/index.js", @@ -41,76 +111,51 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addon-actions": "7.0.0-alpha.48", - "@storybook/addon-backgrounds": "7.0.0-alpha.48", - "@storybook/addon-controls": "7.0.0-alpha.48", - "@storybook/addon-docs": "7.0.0-alpha.48", - "@storybook/addon-highlight": "7.0.0-alpha.48", - "@storybook/addon-measure": "7.0.0-alpha.48", - "@storybook/addon-outline": "7.0.0-alpha.48", - "@storybook/addon-toolbars": "7.0.0-alpha.48", - "@storybook/addon-viewport": "7.0.0-alpha.48", - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/node-logger": "7.0.0-alpha.48", + "@storybook/addon-actions": "7.0.0-alpha.51", + "@storybook/addon-backgrounds": "7.0.0-alpha.51", + "@storybook/addon-controls": "7.0.0-alpha.51", + "@storybook/addon-docs": "7.0.0-alpha.51", + "@storybook/addon-highlight": "7.0.0-alpha.51", + "@storybook/addon-measure": "7.0.0-alpha.51", + "@storybook/addon-outline": "7.0.0-alpha.51", + "@storybook/addon-toolbars": "7.0.0-alpha.51", + "@storybook/addon-viewport": "7.0.0-alpha.51", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/core-common": "7.0.0-alpha.51", + "@storybook/node-logger": "7.0.0-alpha.51", "ts-dedent": "^2.0.0" }, "devDependencies": { - "@babel/core": "^7.12.10", - "@storybook/vue": "7.0.0-alpha.48", - "@types/jest": "^26.0.16", - "typescript": "~4.6.3" + "@babel/core": "^7.20.2", + "@storybook/vue": "7.0.0-alpha.51", + "typescript": "^4.9.3" }, "peerDependencies": { "@babel/core": "^7.9.6" }, - "peerDependenciesMeta": { - "@storybook/angular": { - "optional": true - }, - "@storybook/html": { - "optional": true - }, - "@storybook/vue": { - "optional": true - }, - "@storybook/vue3": { - "optional": true - }, - "@storybook/web-components": { - "optional": true - }, - "lit": { - "optional": true - }, - "lit-html": { - "optional": true - }, - "react": { - "optional": true - }, - "react-dom": { - "optional": true - }, - "svelte": { - "optional": true - }, - "sveltedoc-parser": { - "optional": true - }, - "vue": { - "optional": true - } - }, "publishConfig": { "access": "public" }, "bundler": { "entries": [ - "./src/index.ts" + "./src/index.ts", + "./src/actions/preview.ts", + "./src/actions/manager.ts", + "./src/backgrounds/preview.ts", + "./src/backgrounds/manager.ts", + "./src/controls/manager.ts", + "./src/docs/preview.ts", + "./src/docs/preset.ts", + "./src/highlight/preview.ts", + "./src/measure/preview.ts", + "./src/measure/manager.ts", + "./src/outline/preview.ts", + "./src/outline/manager.ts", + "./src/toolbars/manager.ts", + "./src/viewport/manager.ts" ], "platform": "node" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd" + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded" } diff --git a/code/addons/essentials/src/actions/manager.ts b/code/addons/essentials/src/actions/manager.ts new file mode 100644 index 000000000000..7e125b743169 --- /dev/null +++ b/code/addons/essentials/src/actions/manager.ts @@ -0,0 +1,2 @@ +// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762 +export * from '@storybook/addon-actions/manager'; diff --git a/code/addons/essentials/src/actions/preview.ts b/code/addons/essentials/src/actions/preview.ts new file mode 100644 index 000000000000..86c6d5f2e656 --- /dev/null +++ b/code/addons/essentials/src/actions/preview.ts @@ -0,0 +1,4 @@ +/* eslint-disable import/export */ +// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered + +export * from '@storybook/addon-actions/preview'; diff --git a/code/addons/essentials/src/backgrounds/manager.ts b/code/addons/essentials/src/backgrounds/manager.ts new file mode 100644 index 000000000000..bc51f1b22b4e --- /dev/null +++ b/code/addons/essentials/src/backgrounds/manager.ts @@ -0,0 +1,2 @@ +// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762 +export * from '@storybook/addon-backgrounds/manager'; diff --git a/code/addons/essentials/src/backgrounds/preview.ts b/code/addons/essentials/src/backgrounds/preview.ts new file mode 100644 index 000000000000..5e56121e4a03 --- /dev/null +++ b/code/addons/essentials/src/backgrounds/preview.ts @@ -0,0 +1,4 @@ +/* eslint-disable import/export */ +// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered + +export * from '@storybook/addon-backgrounds/preview'; diff --git a/code/addons/essentials/src/controls/manager.ts b/code/addons/essentials/src/controls/manager.ts new file mode 100644 index 000000000000..49e403523565 --- /dev/null +++ b/code/addons/essentials/src/controls/manager.ts @@ -0,0 +1,2 @@ +// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762 +export * from '@storybook/addon-controls/manager'; diff --git a/code/addons/essentials/src/docs/preset.ts b/code/addons/essentials/src/docs/preset.ts new file mode 100644 index 000000000000..dca808a37dd7 --- /dev/null +++ b/code/addons/essentials/src/docs/preset.ts @@ -0,0 +1,2 @@ +/* eslint-disable import/export */ +export * from '@storybook/addon-docs/dist/preset'; diff --git a/code/addons/essentials/src/docs/preview.ts b/code/addons/essentials/src/docs/preview.ts new file mode 100644 index 000000000000..176a03c1f83f --- /dev/null +++ b/code/addons/essentials/src/docs/preview.ts @@ -0,0 +1 @@ +export * from '@storybook/addon-docs/dist/preview'; diff --git a/code/addons/essentials/src/highlight/preview.ts b/code/addons/essentials/src/highlight/preview.ts new file mode 100644 index 000000000000..ffcf62555af2 --- /dev/null +++ b/code/addons/essentials/src/highlight/preview.ts @@ -0,0 +1,4 @@ +/* eslint-disable import/export */ +// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered + +export * from '@storybook/addon-highlight/preview'; diff --git a/code/addons/essentials/src/index.ts b/code/addons/essentials/src/index.ts index 861fd91162da..96fd171146bb 100644 --- a/code/addons/essentials/src/index.ts +++ b/code/addons/essentials/src/index.ts @@ -1,4 +1,4 @@ -import path, { dirname, join } from 'path'; +import path from 'path'; import { logger } from '@storybook/node-logger'; import { serverRequire } from '@storybook/core-common'; @@ -24,7 +24,8 @@ const requireMain = (configDir: string) => { }; export function addons(options: PresetOptions) { - const checkInstalled = (addon: string, main: any) => { + const checkInstalled = (addonName: string, main: any) => { + const addon = `@storybook/addon-${addonName}`; const existingAddon = main.addons?.find((entry: string | { name: string }) => { const name = typeof entry === 'string' ? entry : entry.name; return name?.startsWith(addon); @@ -36,35 +37,21 @@ export function addons(options: PresetOptions) { }; const main = requireMain(options.configDir); - return ( - [ - 'docs', - 'controls', - 'actions', - 'backgrounds', - 'viewport', - 'toolbars', - 'measure', - 'outline', - 'highlight', - ] - .filter((key) => (options as any)[key] !== false) - .map((key) => `@storybook/addon-${key}`) - .filter((addon) => !checkInstalled(addon, main)) - // Use `require.resolve` to ensure Yarn PnP compatibility - // Files of various addons should be resolved in the context of `addon-essentials` as they are listed as deps here - // and not in `@storybook/core` nor in SB user projects. If `@storybook/core` make the require itself Yarn 2 will - // throw an error saying that the package to require must be added as a dependency. Doing `require.resolve` will - // allow `@storybook/core` to work with absolute path directly, no more require of dep no more issue. - // File to load can be `preset.js`, `register.js`, or the package entry point, so we need to check all these cases - // as it's done in `lib/core/src/server/presets.js`. - .map((addon) => { - try { - return dirname(require.resolve(join(addon, 'package.json'))); - // eslint-disable-next-line no-empty - } catch (err) {} - - return require.resolve(addon); - }) - ); + return [ + 'docs', + 'controls', + 'actions', + 'backgrounds', + 'viewport', + 'toolbars', + 'measure', + 'outline', + 'highlight', + ] + .filter((key) => (options as any)[key] !== false) + .filter((addon) => !checkInstalled(addon, main)) + .map((addon) => { + // We point to the re-export from addon-essentials to support yarn pnp and pnpm. + return `@storybook/addon-essentials/${addon}`; + }); } diff --git a/code/addons/essentials/src/measure/manager.ts b/code/addons/essentials/src/measure/manager.ts new file mode 100644 index 000000000000..cf95d95a76da --- /dev/null +++ b/code/addons/essentials/src/measure/manager.ts @@ -0,0 +1,2 @@ +// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762 +export * from '@storybook/addon-measure/manager'; diff --git a/code/addons/essentials/src/measure/preview.ts b/code/addons/essentials/src/measure/preview.ts new file mode 100644 index 000000000000..f18769ff001a --- /dev/null +++ b/code/addons/essentials/src/measure/preview.ts @@ -0,0 +1,4 @@ +/* eslint-disable import/export */ +// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered + +export * from '@storybook/addon-measure/preview'; diff --git a/code/addons/essentials/src/outline/manager.ts b/code/addons/essentials/src/outline/manager.ts new file mode 100644 index 000000000000..07a0a1e4879a --- /dev/null +++ b/code/addons/essentials/src/outline/manager.ts @@ -0,0 +1,2 @@ +// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762 +export * from '@storybook/addon-outline/manager'; diff --git a/code/addons/essentials/src/outline/preview.ts b/code/addons/essentials/src/outline/preview.ts new file mode 100644 index 000000000000..1cc44b9689a8 --- /dev/null +++ b/code/addons/essentials/src/outline/preview.ts @@ -0,0 +1,4 @@ +/* eslint-disable import/export */ +// TODO: We need to configure an eslint-import typescript resolver for export maps to be considered + +export * from '@storybook/addon-outline/preview'; diff --git a/code/addons/essentials/src/toolbars/manager.ts b/code/addons/essentials/src/toolbars/manager.ts new file mode 100644 index 000000000000..8c4868b1e254 --- /dev/null +++ b/code/addons/essentials/src/toolbars/manager.ts @@ -0,0 +1,2 @@ +// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762 +export * from '@storybook/addon-toolbars/manager'; diff --git a/code/addons/essentials/src/viewport/manager.ts b/code/addons/essentials/src/viewport/manager.ts new file mode 100644 index 000000000000..7c052f303800 --- /dev/null +++ b/code/addons/essentials/src/viewport/manager.ts @@ -0,0 +1,2 @@ +// @ts-expect-error The generated definition file is empty. https://github.com/egoist/tsup/issues/762 +export * from '@storybook/addon-viewport/manager'; diff --git a/code/addons/essentials/tsconfig.json b/code/addons/essentials/tsconfig.json index 25de4fbd3e60..a4429176e35f 100644 --- a/code/addons/essentials/tsconfig.json +++ b/code/addons/essentials/tsconfig.json @@ -3,13 +3,5 @@ "compilerOptions": { "strict": true }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/highlight/jest.config.js b/code/addons/highlight/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/highlight/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/highlight/package.json b/code/addons/highlight/package.json index c8a7d9ef48e6..aa74943371d2 100644 --- a/code/addons/highlight/package.json +++ b/code/addons/highlight/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-highlight", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Highlight DOM nodes within your stories", "keywords": [ "storybook-addons", @@ -30,15 +30,25 @@ "types": "./dist/index.d.ts" }, "./preview": { - "require": "./dist/highlight.js", - "import": "./dist/highlight.mjs", - "types": "./dist/highlight.d.ts" + "require": "./dist/preview.js", + "import": "./dist/preview.mjs", + "types": "./dist/preview.d.ts" }, "./package.json": "./package.json" }, "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -50,13 +60,13 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", "global": "^4.4.0" }, "devDependencies": { "@types/webpack-env": "^1.16.0", - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "publishConfig": { "access": "public" @@ -64,10 +74,10 @@ "bundler": { "entries": [ "./src/index.ts", - "./src/highlight.ts" + "./src/preview.ts" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "sbmodern": "dist/modern/index.js", "storybook": { "displayName": "Highlight", diff --git a/code/addons/highlight/preview.js b/code/addons/highlight/preview.js index f7dfc599138c..49ad602f79f4 100644 --- a/code/addons/highlight/preview.js +++ b/code/addons/highlight/preview.js @@ -1 +1 @@ -export * from './dist/highlight'; +export * from './dist/preview'; diff --git a/code/addons/highlight/src/highlight.ts b/code/addons/highlight/src/preview.ts similarity index 100% rename from code/addons/highlight/src/highlight.ts rename to code/addons/highlight/src/preview.ts diff --git a/code/addons/highlight/tsconfig.json b/code/addons/highlight/tsconfig.json index 6b79f028c19c..c94fb6fc9dd5 100644 --- a/code/addons/highlight/tsconfig.json +++ b/code/addons/highlight/tsconfig.json @@ -4,13 +4,5 @@ "rootDir": "./src", "types": ["webpack-env"] }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/interactions/jest.config.js b/code/addons/interactions/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/interactions/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/interactions/package.json b/code/addons/interactions/package.json index 0eb7130861b4..6f120a25e357 100644 --- a/code/addons/interactions/package.json +++ b/code/addons/interactions/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-interactions", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Automate, test and debug user interactions", "keywords": [ "storybook-addons", @@ -33,9 +33,9 @@ "types": "./dist/manager.d.ts" }, "./preview": { - "require": "./dist/preset/preview.js", - "import": "./dist/preset/preview.mjs", - "types": "./dist/preset/preview.d.ts" + "require": "./dist/preview.js", + "import": "./dist/preview.mjs", + "types": "./dist/preview.d.ts" }, "./register.js": { "require": "./dist/manager.js", @@ -47,6 +47,19 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -59,15 +72,15 @@ }, "dependencies": { "@devtools-ds/object-inspector": "^1.1.2", - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/instrumenter": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-common": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/instrumenter": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "global": "^4.4.0", "jest-mock": "^27.0.6", "polished": "^4.2.2", @@ -76,9 +89,9 @@ "devDependencies": { "@storybook/jest": "^0.0.10", "@storybook/testing-library": "0.0.14-next.0", - "@types/node": "^16.0.0", + "@types/node": "^16.0.0 || ^18.0.0", "formik": "^2.2.9", - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -99,12 +112,12 @@ "entries": [ "./src/index.ts", "./src/manager.tsx", - "./src/preset/preview.ts", + "./src/preview.ts", "./src/preset/checkActionsLoaded.ts" ], "platform": "node" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Interactions", "unsupportedFrameworks": [ diff --git a/code/addons/interactions/preview.js b/code/addons/interactions/preview.js index 48714cc6fba3..49ad602f79f4 100644 --- a/code/addons/interactions/preview.js +++ b/code/addons/interactions/preview.js @@ -1 +1 @@ -export * from './dist/preset/preview'; +export * from './dist/preview'; diff --git a/code/addons/interactions/src/components/InteractionsPanel.stories.tsx b/code/addons/interactions/src/components/InteractionsPanel.stories.tsx index f55d28944c5a..179023b84906 100644 --- a/code/addons/interactions/src/components/InteractionsPanel.stories.tsx +++ b/code/addons/interactions/src/components/InteractionsPanel.stories.tsx @@ -1,4 +1,3 @@ -/* eslint-disable jest/no-standalone-expect */ import React from 'react'; import type { StoryObj, Meta } from '@storybook/react'; import { CallStates } from '@storybook/instrumenter'; diff --git a/code/addons/interactions/src/preset/preview.ts b/code/addons/interactions/src/preview.ts similarity index 95% rename from code/addons/interactions/src/preset/preview.ts rename to code/addons/interactions/src/preview.ts index d36c4bbf4f55..b4f094b7b986 100644 --- a/code/addons/interactions/src/preset/preview.ts +++ b/code/addons/interactions/src/preview.ts @@ -3,7 +3,7 @@ import { addons } from '@storybook/addons'; import { FORCE_REMOUNT, STORY_RENDER_PHASE_CHANGED } from '@storybook/core-events'; import type { - Framework, + Renderer, ArgsEnhancer, PlayFunction, PlayFunctionContext, @@ -52,7 +52,7 @@ const addSpies = (id: string, val: any, key?: string): any => { return val; }; -const addActionsFromArgTypes: ArgsEnhancer = ({ id, initialArgs }) => +const addActionsFromArgTypes: ArgsEnhancer = ({ id, initialArgs }) => addSpies(id, initialArgs); export const argsEnhancers = [addActionsFromArgTypes]; diff --git a/code/addons/interactions/template/stories/basics.stories.ts b/code/addons/interactions/template/stories/basics.stories.ts index 57af27cc34fa..9a1919e748c9 100644 --- a/code/addons/interactions/template/stories/basics.stories.ts +++ b/code/addons/interactions/template/stories/basics.stories.ts @@ -1,4 +1,3 @@ -/* eslint-disable jest/no-standalone-expect */ import globalThis from 'global'; import { within, diff --git a/code/addons/interactions/tsconfig.json b/code/addons/interactions/tsconfig.json index d23f9a406fc2..52d43eaaa9b9 100644 --- a/code/addons/interactions/tsconfig.json +++ b/code/addons/interactions/tsconfig.json @@ -1,12 +1,4 @@ { "extends": "../../tsconfig.json", - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/jest/jest.config.js b/code/addons/jest/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/jest/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/jest/package.json b/code/addons/jest/package.json index 96f77afe0c62..dd08248b8e0c 100644 --- a/code/addons/jest/package.json +++ b/code/addons/jest/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-jest", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "React storybook addon that show component jest report", "keywords": [ "addon", @@ -48,6 +48,16 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -59,18 +69,18 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", "global": "^4.4.0", "react-sizeme": "^3.0.1", "upath": "^1.2.0" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -94,7 +104,7 @@ ], "platform": "browser" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Jest", "icon": "https://pbs.twimg.com/profile_images/821713465245102080/mMtKIMax_400x400.jpg", diff --git a/code/addons/jest/src/shared.test.ts b/code/addons/jest/src/shared.test.ts index e051f4563f61..ddc3a0c71b17 100644 --- a/code/addons/jest/src/shared.test.ts +++ b/code/addons/jest/src/shared.test.ts @@ -27,7 +27,7 @@ describe('defineJestParameter', () => { }); test('returns null if filename is a module ID that cannot be inferred from', () => { - // @ts-expect-error (Converted from ts-ignore) + // @ts-expect-error Storybook's fileName type is string, but according to this test it could be number in case it is a module id. expect(defineJestParameter({ fileName: 1234 })).toBeNull(); }); }); diff --git a/code/addons/jest/src/shared.ts b/code/addons/jest/src/shared.ts index 9b761e1d9dec..ef078b7af8a8 100644 --- a/code/addons/jest/src/shared.ts +++ b/code/addons/jest/src/shared.ts @@ -1,4 +1,4 @@ -import type { Parameters } from '@storybook/types'; +import type { StorybookInternalParameters } from '@storybook/types'; // addons, panels and events get unique names using a prefix export const PARAM_KEY = 'test'; @@ -7,7 +7,7 @@ export const PANEL_ID = `${ADDON_ID}/panel`; export const ADD_TESTS = `${ADDON_ID}/add_tests`; -interface AddonParameters extends Parameters { +interface AddonParameters extends StorybookInternalParameters { jest?: string | string[] | { disabled: true }; } diff --git a/code/addons/jest/tsconfig.json b/code/addons/jest/tsconfig.json index f8b60c90fdef..73a65ef2ef6e 100644 --- a/code/addons/jest/tsconfig.json +++ b/code/addons/jest/tsconfig.json @@ -1,13 +1,5 @@ { "extends": "../../tsconfig.json", "compilerOptions": {}, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/links/jest.config.js b/code/addons/links/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/links/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/links/package.json b/code/addons/links/package.json index 92cc62a00d09..c26f963e48ed 100644 --- a/code/addons/links/package.json +++ b/code/addons/links/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-links", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Link stories together to build demos and prototypes with your UI components", "keywords": [ "addon", @@ -52,6 +52,19 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -63,18 +76,18 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", "@storybook/csf": "next", - "@storybook/router": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/router": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "global": "^4.4.0", "prop-types": "^15.7.2", "ts-dedent": "^2.0.0" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -99,7 +112,7 @@ "./src/react/index.ts" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Links", "icon": "https://user-images.githubusercontent.com/263385/101991673-48355c80-3c7c-11eb-9b6e-b627c96a75f6.png", diff --git a/code/addons/links/src/react/components/link.test.tsx b/code/addons/links/src/react/components/link.test.tsx index 664670baa264..9b1d5e09552a 100644 --- a/code/addons/links/src/react/components/link.test.tsx +++ b/code/addons/links/src/react/components/link.test.tsx @@ -14,7 +14,6 @@ jest.mock('global', () => ({ search: 'search', }, }, - // @ts-expect-error (Converted from ts-ignore) window: global, __STORYBOOK_STORY_STORE__: { fromId: jest.fn(() => ({})), diff --git a/code/addons/links/src/utils.test.ts b/code/addons/links/src/utils.test.ts index 443886653810..291b613c7edb 100644 --- a/code/addons/links/src/utils.test.ts +++ b/code/addons/links/src/utils.test.ts @@ -5,9 +5,7 @@ import { linkTo, hrefTo } from './utils'; jest.mock('@storybook/addons'); jest.mock('global', () => ({ - // @ts-expect-error (Converted from ts-ignore) document: global.document, - // @ts-expect-error (Converted from ts-ignore) window: global, })); @@ -41,6 +39,7 @@ describe('preview', () => { it('should select the story (only) provided', () => { // simulate a currently selected, but not found as ID + // @ts-expect-error (not strict) const handler = linkTo(undefined, 'name'); handler(); diff --git a/code/addons/links/src/utils.ts b/code/addons/links/src/utils.ts index b4ece3c80fea..73ba6e0d3322 100644 --- a/code/addons/links/src/utils.ts +++ b/code/addons/links/src/utils.ts @@ -49,7 +49,6 @@ export const hrefTo = (title: ComponentTitle, name: StoryName): Promise }); }; -// eslint-disable-next-line @typescript-eslint/no-shadow const valueOrCall = (args: string[]) => (value: string | ((...args: string[]) => string)) => typeof value === 'function' ? value(...args) : value; diff --git a/code/addons/links/tsconfig.json b/code/addons/links/tsconfig.json index 25de4fbd3e60..a4429176e35f 100644 --- a/code/addons/links/tsconfig.json +++ b/code/addons/links/tsconfig.json @@ -3,13 +3,5 @@ "compilerOptions": { "strict": true }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/measure/jest.config.js b/code/addons/measure/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/measure/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/measure/package.json b/code/addons/measure/package.json index 6ab70183b27a..6305042530ad 100644 --- a/code/addons/measure/package.json +++ b/code/addons/measure/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-measure", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Inspect layouts by visualizing the box model", "keywords": [ "storybook-addons", @@ -50,6 +50,19 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -61,16 +74,16 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "global": "^4.4.0" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -94,7 +107,7 @@ "./src/preview.tsx" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Measure", "unsupportedFrameworks": [ diff --git a/code/addons/measure/src/withMeasure.ts b/code/addons/measure/src/withMeasure.ts index e0a0fa1a101b..4dea5601dc7a 100644 --- a/code/addons/measure/src/withMeasure.ts +++ b/code/addons/measure/src/withMeasure.ts @@ -1,6 +1,6 @@ /* eslint-env browser */ import { useEffect } from '@storybook/addons'; -import type { Framework, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; +import type { Renderer, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; import { drawSelectedElement } from './box-model/visualizer'; import { init, rescale, destroy } from './box-model/canvas'; import { deepElementFromPoint } from './util'; @@ -13,10 +13,7 @@ function findAndDrawElement(x: number, y: number) { drawSelectedElement(nodeAtPointerRef); } -export const withMeasure = ( - StoryFn: StoryFunction, - context: StoryContext -) => { +export const withMeasure = (StoryFn: StoryFunction, context: StoryContext) => { const { measureEnabled } = context.globals; useEffect(() => { diff --git a/code/addons/measure/tsconfig.json b/code/addons/measure/tsconfig.json index d23f9a406fc2..52d43eaaa9b9 100644 --- a/code/addons/measure/tsconfig.json +++ b/code/addons/measure/tsconfig.json @@ -1,12 +1,4 @@ { "extends": "../../tsconfig.json", - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/outline/jest.config.js b/code/addons/outline/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/outline/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/outline/package.json b/code/addons/outline/package.json index 478b1d9b23a6..90d030b061be 100644 --- a/code/addons/outline/package.json +++ b/code/addons/outline/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-outline", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Outline all elements with CSS to help with layout placement and alignment", "keywords": [ "storybook-addons", @@ -39,9 +39,9 @@ "types": "./dist/manager.d.ts" }, "./preview": { - "require": "./dist/preset/preview.js", - "import": "./dist/preset/preview.mjs", - "types": "./dist/preset/preview.d.ts" + "require": "./dist/preview.js", + "import": "./dist/preview.mjs", + "types": "./dist/preview.d.ts" }, "./register": { "require": "./dist/manager.js", @@ -53,6 +53,19 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -64,17 +77,17 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "global": "^4.4.0", "ts-dedent": "^2.0.0" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -95,10 +108,10 @@ "entries": [ "./src/index.ts", "./src/manager.tsx", - "./src/preset/preview.tsx" + "./src/preview.tsx" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Outline", "unsupportedFrameworks": [ diff --git a/code/addons/outline/preview.js b/code/addons/outline/preview.js index 48714cc6fba3..49ad602f79f4 100644 --- a/code/addons/outline/preview.js +++ b/code/addons/outline/preview.js @@ -1 +1 @@ -export * from './dist/preset/preview'; +export * from './dist/preview'; diff --git a/code/addons/outline/src/preset/preview.tsx b/code/addons/outline/src/preview.tsx similarity index 51% rename from code/addons/outline/src/preset/preview.tsx rename to code/addons/outline/src/preview.tsx index 1abee6e575c6..65161c6c4f29 100644 --- a/code/addons/outline/src/preset/preview.tsx +++ b/code/addons/outline/src/preview.tsx @@ -1,5 +1,5 @@ -import { withOutline } from '../withOutline'; -import { PARAM_KEY } from '../constants'; +import { withOutline } from './withOutline'; +import { PARAM_KEY } from './constants'; export const decorators = [withOutline]; diff --git a/code/addons/outline/src/withOutline.ts b/code/addons/outline/src/withOutline.ts index 1fc20affb60d..455d84ae945a 100644 --- a/code/addons/outline/src/withOutline.ts +++ b/code/addons/outline/src/withOutline.ts @@ -1,14 +1,11 @@ import { useMemo, useEffect } from '@storybook/addons'; -import type { Framework, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; +import type { Renderer, PartialStoryFn as StoryFunction, StoryContext } from '@storybook/types'; import { clearStyles, addOutlineStyles } from './helpers'; import { PARAM_KEY } from './constants'; import outlineCSS from './outlineCSS'; -export const withOutline = ( - StoryFn: StoryFunction, - context: StoryContext -) => { +export const withOutline = (StoryFn: StoryFunction, context: StoryContext) => { const { globals } = context; const isActive = globals[PARAM_KEY] === true; const isInDocs = context.viewMode === 'docs'; diff --git a/code/addons/outline/tsconfig.json b/code/addons/outline/tsconfig.json index d23f9a406fc2..52d43eaaa9b9 100644 --- a/code/addons/outline/tsconfig.json +++ b/code/addons/outline/tsconfig.json @@ -1,12 +1,4 @@ { "extends": "../../tsconfig.json", - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/storyshots/jest.config.js b/code/addons/storyshots/jest.config.js new file mode 100644 index 000000000000..0115c67e5629 --- /dev/null +++ b/code/addons/storyshots/jest.config.js @@ -0,0 +1,12 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + snapshotSerializers: [...baseConfig.snapshotSerializers, 'enzyme-to-json/serializer'], + transform: { + ...baseConfig.transform, + '^.+\\.stories\\.[jt]sx?$': '@storybook/addon-storyshots/injectFileName', + }, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/storyshots/storyshots-core/package.json b/code/addons/storyshots/storyshots-core/package.json index 539ef73cb34a..d4da0a55e08f 100644 --- a/code/addons/storyshots/storyshots-core/package.json +++ b/code/addons/storyshots/storyshots-core/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-storyshots", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Take a code snapshot of every story automatically with Jest", "keywords": [ "addon", @@ -37,23 +37,22 @@ "storybook": "yarn sb dev -p 6006" }, "dependencies": { - "@jest/transform": "^26.6.2", - "@storybook/addons": "7.0.0-alpha.48", + "@jest/transform": "^29.3.1", + "@storybook/addons": "7.0.0-alpha.51", "@storybook/babel-plugin-require-context-hook": "1.0.1", - "@storybook/client-api": "7.0.0-alpha.48", - "@storybook/core-client": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/core-webpack": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", + "@storybook/client-api": "7.0.0-alpha.51", + "@storybook/core-client": "7.0.0-alpha.51", + "@storybook/core-common": "7.0.0-alpha.51", + "@storybook/core-webpack": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", "@types/glob": "^7.1.3", - "@types/jest": "^26.0.16", - "@types/jest-specific-snapshot": "^0.5.3", + "@types/jest-specific-snapshot": "^0.5.6", "core-js": "^3.8.2", "glob": "^7.1.6", "global": "^4.4.0", - "jest-specific-snapshot": "^4.0.0", + "jest-specific-snapshot": "^6.0.0", "preact-render-to-string": "^5.1.19", - "pretty-format": "^26.6.2", + "pretty-format": "^28.0.0", "react-test-renderer": "^16.8.0 || ^17.0.0 || ^18.0.0", "read-pkg-up": "^7.0.1", "ts-dedent": "^2.0.0" @@ -62,12 +61,12 @@ "@angular/core": "^13.3.6", "@angular/platform-browser-dynamic": "^13.3.6", "@emotion/jest": "^11.8.0", - "@storybook/addon-docs": "7.0.0-alpha.48", - "@storybook/angular": "7.0.0-alpha.48", - "@storybook/react": "7.0.0-alpha.48", - "@storybook/vue": "7.0.0-alpha.48", - "@storybook/vue3": "7.0.0-alpha.48", - "babel-loader": "^8.2.5", + "@storybook/addon-docs": "7.0.0-alpha.51", + "@storybook/angular": "7.0.0-alpha.51", + "@storybook/react": "7.0.0-alpha.51", + "@storybook/vue": "7.0.0-alpha.51", + "@storybook/vue3": "7.0.0-alpha.51", + "babel-loader": "^8.3.0", "enzyme": "^3.11.0", "enzyme-to-json": "^3.6.1", "jest-preset-angular": "^8.3.2", @@ -144,7 +143,7 @@ "publishConfig": { "access": "public" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Storyshots", "icon": "https://user-images.githubusercontent.com/263385/101991676-48cdf300-3c7c-11eb-8aa1-944dab6ab29b.png", diff --git a/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.test.ts b/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.test.ts index 168849f26be5..d066d1226e58 100644 --- a/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.test.ts +++ b/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.test.ts @@ -4,33 +4,33 @@ const target = new Stories2SnapsConverter(); describe('getSnapshotFileName', () => { it('fileName is provided - snapshot is stored in __snapshots__ dir', () => { - const context = { fileName: 'foo.js' }; + const context = { fileName: 'foo.js', kind: 'kind' }; - // @ts-expect-error (TODO) const result = target.getSnapshotFileName(context); const platformAgnosticResult = result.replace(/\\|\//g, '/'); - expect(platformAgnosticResult).toBe('__snapshots__/foo.storyshot'); + // This is an absolute path, so we need to use `toContain()` + expect(platformAgnosticResult).toContain('__snapshots__/foo.storyshot'); }); it('fileName with multiple extensions is provided - only the last extension is replaced', () => { - const context = { fileName: 'foo.web.stories.js' }; + const context = { fileName: 'foo.web.stories.js', kind: 'kind' }; - // @ts-expect-error (TODO) const result = target.getSnapshotFileName(context); const platformAgnosticResult = result.replace(/\\|\//g, '/'); - expect(platformAgnosticResult).toBe('__snapshots__/foo.web.stories.storyshot'); + // This is an absolute path, so we need to use `toContain()` + expect(platformAgnosticResult).toContain('__snapshots__/foo.web.stories.storyshot'); }); it('fileName with dir is provided - __snapshots__ dir is created inside another dir', () => { - const context = { fileName: 'test/foo.js' }; + const context = { fileName: 'test/foo.js', kind: 'kind' }; - // @ts-expect-error (TODO) const result = target.getSnapshotFileName(context); const platformAgnosticResult = result.replace(/\\|\//g, '/'); - expect(platformAgnosticResult).toBe('test/__snapshots__/foo.storyshot'); + // This is an absolute path, so we need to use `toContain()` + expect(platformAgnosticResult).toContain('test/__snapshots__/foo.storyshot'); }); }); diff --git a/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.ts b/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.ts index 527a946847c8..439a514f7bd4 100644 --- a/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.ts +++ b/code/addons/storyshots/storyshots-core/src/Stories2SnapsConverter.ts @@ -29,7 +29,15 @@ export class Stories2SnapsConverter { const { dir, name } = path.parse(fileName); const { snapshotsDirName, snapshotExtension } = this.options; - return path.format({ dir: path.join(dir, snapshotsDirName), name, ext: snapshotExtension }); + // Convert to absolute path, in case jest is not running in CWD, + // else it will create snapshots with the wrong path + const absDir = path.isAbsolute(dir) ? dir : path.resolve(dir); + + return path.format({ + dir: path.join(absDir, snapshotsDirName), + name, + ext: snapshotExtension, + }); } getSnapshotFileName(context: { fileName?: string; kind: any }) { diff --git a/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts b/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts index b4fb63b582ff..d52260268104 100644 --- a/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts +++ b/code/addons/storyshots/storyshots-core/src/api/integrityTestTemplate.ts @@ -52,7 +52,6 @@ function integrityTest(integrityOptions: any, stories2snapsConverter: any) { const snapshotExtension = stories2snapsConverter.getSnapshotExtension(); const storyshots = glob.sync(`**/*${snapshotExtension}`, integrityOptions); - // @ts-expect-error (Converted from ts-ignore) expect(storyshots).notToBeAbandoned(stories2snapsConverter); }); }); diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/Loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/Loader.ts index c844fe11973d..80b863c51102 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/Loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/Loader.ts @@ -1,11 +1,11 @@ -import type { Framework, Addon_Loadable } from '@storybook/types'; +import type { Renderer, Addon_Loadable } from '@storybook/types'; import type { ClientApi as ClientApiClass } from '@storybook/client-api'; import type { StoryshotsOptions } from '../api/StoryshotsOptions'; import type { SupportedFramework } from './SupportedFramework'; export type RenderTree = (story: any, context?: any, options?: any) => any; -export interface ClientApi extends ClientApiClass { +export interface ClientApi extends ClientApiClass { configure( loader: Addon_Loadable, module: NodeModule | false, @@ -19,7 +19,7 @@ export interface Loader { framework: SupportedFramework; renderTree: RenderTree; renderShallowTree: any; - storybook: ClientApi; + storybook: ClientApi; }; test: (options: StoryshotsOptions) => boolean; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/angular/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/angular/loader.ts index 401b25764122..40a7def7ffa7 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/angular/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/angular/loader.ts @@ -33,17 +33,35 @@ function test(options: StoryshotsOptions): boolean { function load(options: StoryshotsOptions) { setupAngularJestPreset(); - const storybook = jest.requireActual('@storybook/angular'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); + + jest.mock('@storybook/angular', () => { + const renderAPI = jest.requireActual('@storybook/angular'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/angular'); configure({ ...options, - storybook: api, + storybook, }); return { @@ -52,7 +70,7 @@ function load(options: StoryshotsOptions) { renderShallowTree: () => { throw new Error('Shallow renderer is not supported for angular'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts b/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts index 25c03f8622e8..aafc21c96f6c 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/configure.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import type { - Framework, + Renderer, ArgsEnhancer, ArgTypesEnhancer, CoreCommon_NormalizedStoriesSpecifier, @@ -87,9 +87,9 @@ function getConfigPathParts(input: string): Output { return { preview: configDir }; } -function configure( +function configure( options: { - storybook: ClientApi; + storybook: ClientApi; } & StoryshotsOptions ): void { const { configPath = '.storybook', config, storybook } = options; @@ -125,7 +125,7 @@ function configure( } = jest.requireActual(preview); if (decorators) { - decorators.forEach((decorator: DecoratorFunction) => + decorators.forEach((decorator: DecoratorFunction) => storybook.addDecorator(decorator) ); } @@ -136,12 +136,12 @@ function configure( storybook.addStepRunner(runStep); } if (argsEnhancers) { - argsEnhancers.forEach((enhancer: ArgsEnhancer) => + argsEnhancers.forEach((enhancer: ArgsEnhancer) => storybook.addArgsEnhancer(enhancer as any) ); } if (argTypesEnhancers) { - argTypesEnhancers.forEach((enhancer: ArgTypesEnhancer) => + argTypesEnhancers.forEach((enhancer: ArgTypesEnhancer) => storybook.addArgTypesEnhancer(enhancer as any) ); } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts index 6cc2b9d3e943..55a8dfdd6b12 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/html/loader.ts @@ -10,17 +10,35 @@ function test(options: StoryshotsOptions): boolean { function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'html'; - const storybook = jest.requireActual('@storybook/html'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; + + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/html', () => { + const renderAPI = jest.requireActual('@storybook/html'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/html'); configure({ ...options, - storybook: api, + storybook, }); return { @@ -29,7 +47,7 @@ function load(options: StoryshotsOptions) { renderShallowTree: () => { throw new Error('Shallow renderer is not supported for HTML'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts index c45f7c9b8efc..986dcf5f911f 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/preact/loader.ts @@ -16,17 +16,35 @@ function test(options: StoryshotsOptions): boolean { function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'preact'; - const storybook = jest.requireActual('@storybook/preact'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); + + jest.mock('@storybook/preact', () => { + const renderAPI = jest.requireActual('@storybook/preact'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/preact'); configure({ ...options, - storybook: api, + storybook, }); return { @@ -35,7 +53,7 @@ function load(options: StoryshotsOptions) { renderShallowTree: () => { throw new Error('Shallow renderer is not supported for preact'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts index 86284861d29b..2d14593fd096 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/rax/loader.ts @@ -11,17 +11,35 @@ function test(options: StoryshotsOptions): boolean { function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'rax'; - const storybook = jest.requireActual('@storybook/rax'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; + + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/rax', () => { + const renderAPI = jest.requireActual('@storybook/rax'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/rax'); configure({ ...options, - storybook: api, + storybook, }); return { @@ -30,7 +48,7 @@ function load(options: StoryshotsOptions) { renderShallowTree: () => { throw new Error('Shallow renderer is not supported for rax'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/react-native/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/react-native/loader.ts index a31758cdc2b9..7c0e51d23f0f 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/react-native/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/react-native/loader.ts @@ -25,20 +25,14 @@ function configure(options: StoryshotsOptions, storybook: any) { function load(options: StoryshotsOptions) { const storybook = jest.requireActual('@storybook/react-native'); - const clientAPI = jest.requireActual('@storybook/client-api'); - const api = { - ...clientAPI, - ...storybook, - }; - - configure(options, api); + configure(options, storybook); return { renderTree: require('../react/renderTree').default, renderShallowTree: require('../react/renderShallowTree').default, framework: 'react-native' as const, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/react/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/react/loader.ts index 1ba371b1d622..bc6f9153f10f 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/react/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/react/loader.ts @@ -8,24 +8,42 @@ function test(options: StoryshotsOptions): boolean { } function load(options: StoryshotsOptions) { - const storybook = jest.requireActual('@storybook/react'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); + + jest.mock('@storybook/react', () => { + const renderAPI = jest.requireActual('@storybook/react'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/react'); configure({ ...options, - storybook: api, + storybook, }); return { framework: 'react' as const, renderTree: jest.requireActual('./renderTree').default, renderShallowTree: jest.requireActual('./renderShallowTree').default, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts index 1e352031dfba..bd131ba1f80f 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/riot/loader.ts @@ -16,17 +16,35 @@ function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'riot'; mockRiotToIncludeCompiler(); - const storybook = jest.requireActual('@storybook/riot'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); + + jest.mock('@storybook/riot', () => { + const renderAPI = jest.requireActual('@storybook/riot'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/riot'); configure({ ...options, - storybook: api, + storybook, }); return { @@ -35,7 +53,7 @@ function load(options: StoryshotsOptions) { renderShallowTree: () => { throw new Error('Shallow renderer is not supported for riot'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts index 8f874c7468bd..d7a45bc58466 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/svelte/loader.ts @@ -13,26 +13,43 @@ function test(options: StoryshotsOptions): boolean { function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'svelte'; - const storybook = jest.requireActual('@storybook/svelte'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; + + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/svelte', () => { + const renderAPI = jest.requireActual('@storybook/svelte'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/svelte'); configure({ ...options, - storybook: api, + storybook, }); - return { framework: 'svelte' as const, renderTree: jest.requireActual('./renderTree').default, renderShallowTree: () => { throw new Error('Shallow renderer is not supported for svelte'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts index 3748e7713633..bb97cd1560b5 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/vue/loader.ts @@ -16,26 +16,43 @@ function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'vue'; mockVueToIncludeCompiler(); - const storybook = jest.requireActual('@storybook/vue'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); + + jest.mock('@storybook/vue', () => { + const renderAPI = jest.requireActual('@storybook/vue'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/vue'); configure({ ...options, - storybook: api, + storybook, }); - return { framework: 'vue' as const, renderTree: jest.requireActual('./renderTree').default, renderShallowTree: () => { throw new Error('Shallow renderer is not supported for vue'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts index 980b26e14c98..01de29fa01cc 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/vue3/loader.ts @@ -11,17 +11,35 @@ function test(options: StoryshotsOptions): boolean { function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'vue3'; - const storybook = jest.requireActual('@storybook/vue'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; + + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/vue3', () => { + const renderAPI = jest.requireActual('@storybook/vue3'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/vue3'); configure({ ...options, - storybook: api, + storybook, }); return { @@ -30,7 +48,7 @@ function load(options: StoryshotsOptions) { renderShallowTree: () => { throw new Error('Shallow renderer is not supported for Vue 3'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts b/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts index 35f8020718f3..b17cd8f4474f 100644 --- a/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts +++ b/code/addons/storyshots/storyshots-core/src/frameworks/web-components/loader.ts @@ -10,17 +10,35 @@ function test(options: StoryshotsOptions): boolean { function load(options: StoryshotsOptions) { global.STORYBOOK_ENV = 'web-components'; - const storybook = jest.requireActual('@storybook/html'); - const clientAPI = jest.requireActual('@storybook/client-api'); + let mockStartedAPI: any; + + jest.mock('@storybook/core-client', () => { + const coreClientAPI = jest.requireActual('@storybook/core-client'); + + return { + ...coreClientAPI, + start: (...args: any[]) => { + mockStartedAPI = coreClientAPI.start(...args); + return mockStartedAPI; + }, + }; + }); - const api = { - ...clientAPI, - ...storybook, - }; + jest.mock('@storybook/html', () => { + const renderAPI = jest.requireActual('@storybook/html'); + + renderAPI.addDecorator = mockStartedAPI.clientApi.addDecorator; + renderAPI.addParameters = mockStartedAPI.clientApi.addParameters; + + return renderAPI; + }); + + // eslint-disable-next-line global-require + const storybook = require('@storybook/html'); configure({ ...options, - storybook: api, + storybook, }); return { @@ -29,7 +47,7 @@ function load(options: StoryshotsOptions) { renderShallowTree: () => { throw new Error('Shallow renderer is not supported for web-components'); }, - storybook: api, + storybook, }; } diff --git a/code/addons/storyshots/storyshots-puppeteer/package.json b/code/addons/storyshots/storyshots-puppeteer/package.json index 50097f24f000..125d5283599a 100644 --- a/code/addons/storyshots/storyshots-puppeteer/package.json +++ b/code/addons/storyshots/storyshots-puppeteer/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-storyshots-puppeteer", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Image snapshots addition to StoryShots based on puppeteer", "keywords": [ "addon", @@ -35,17 +35,17 @@ "dependencies": { "@axe-core/puppeteer": "^4.2.0", "@storybook/csf": "next", - "@storybook/node-logger": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", - "@types/jest-image-snapshot": "^4.1.3", - "jest-image-snapshot": "^4.3.0" + "@storybook/node-logger": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", + "@types/jest-image-snapshot": "^5.1.0", + "jest-image-snapshot": "^6.0.0" }, "devDependencies": { "@types/puppeteer": "^5.4.0", "puppeteer": "^2.0.0 || ^3.0.0" }, "peerDependencies": { - "@storybook/addon-storyshots": "7.0.0-alpha.48", + "@storybook/addon-storyshots": "7.0.0-alpha.51", "puppeteer": ">=2.0.0" }, "peerDependenciesMeta": { @@ -56,5 +56,5 @@ "publishConfig": { "access": "public" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd" + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded" } diff --git a/code/addons/storyshots/storyshots-puppeteer/tsconfig.json b/code/addons/storyshots/storyshots-puppeteer/tsconfig.json index 8198a4b0a167..d16da0e1d60f 100644 --- a/code/addons/storyshots/storyshots-puppeteer/tsconfig.json +++ b/code/addons/storyshots/storyshots-puppeteer/tsconfig.json @@ -5,6 +5,5 @@ "types": ["node"], "declaration": true }, - "include": ["src/**/*"], - "exclude": [] + "include": ["src/**/*"] } diff --git a/code/addons/storysource/jest.config.js b/code/addons/storysource/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/storysource/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/storysource/package.json b/code/addons/storysource/package.json index 587615a846c7..a18a4f13d23b 100644 --- a/code/addons/storysource/package.json +++ b/code/addons/storysource/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-storysource", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "View a story’s source code to see how it works and paste into your app", "keywords": [ "addon", @@ -53,21 +53,21 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/router": "7.0.0-alpha.48", - "@storybook/source-loader": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/router": "7.0.0-alpha.51", + "@storybook/source-loader": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", "estraverse": "^5.2.0", "prop-types": "^15.7.2", "react-syntax-highlighter": "^15.5.0" }, "devDependencies": { - "@types/react": "^16.14.23", + "@types/react": "^16.14.34", "@types/react-syntax-highlighter": "11.0.5", - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -91,7 +91,7 @@ "./src/preset.ts" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Storysource", "icon": "https://user-images.githubusercontent.com/263385/101991675-48cdf300-3c7c-11eb-9400-58de5ac6daa7.png", diff --git a/code/addons/storysource/tsconfig.json b/code/addons/storysource/tsconfig.json index 13c4f6e9ee64..cf1e09965901 100644 --- a/code/addons/storysource/tsconfig.json +++ b/code/addons/storysource/tsconfig.json @@ -3,13 +3,5 @@ "compilerOptions": { "skipLibCheck": true }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/toolbars/jest.config.js b/code/addons/toolbars/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/toolbars/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/toolbars/package.json b/code/addons/toolbars/package.json index 0b4cbde72ca5..8dce94d497bf 100644 --- a/code/addons/toolbars/package.json +++ b/code/addons/toolbars/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-toolbars", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Create your own toolbar items that control story rendering", "keywords": [ "addon", @@ -46,6 +46,16 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -57,14 +67,14 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48" + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -88,7 +98,7 @@ ], "platform": "browser" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Toolbars", "icon": "https://user-images.githubusercontent.com/263385/101991677-48cdf300-3c7c-11eb-93b4-19b0e3366959.png", diff --git a/code/addons/toolbars/tsconfig.json b/code/addons/toolbars/tsconfig.json index 25de4fbd3e60..a4429176e35f 100644 --- a/code/addons/toolbars/tsconfig.json +++ b/code/addons/toolbars/tsconfig.json @@ -3,13 +3,5 @@ "compilerOptions": { "strict": true }, - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/addons/viewport/jest.config.js b/code/addons/viewport/jest.config.js new file mode 100644 index 000000000000..4396fbc7010d --- /dev/null +++ b/code/addons/viewport/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.browser'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/addons/viewport/package.json b/code/addons/viewport/package.json index 35d69a6bc5b9..1174a56e8339 100644 --- a/code/addons/viewport/package.json +++ b/code/addons/viewport/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/addon-viewport", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Build responsive components by adjusting Storybook’s viewport size and orientation", "keywords": [ "addon", @@ -48,6 +48,19 @@ "main": "dist/index.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", + "typesVersions": { + "*": { + "*": [ + "dist/index.d.ts" + ], + "manager": [ + "dist/manager.d.ts" + ], + "preview": [ + "dist/preview.d.ts" + ] + } + }, "files": [ "dist/**/*", "README.md", @@ -59,18 +72,18 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/components": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/theming": "7.0.0-alpha.48", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/components": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/theming": "7.0.0-alpha.51", "global": "^4.4.0", "memoizerific": "^1.11.3", "prop-types": "^15.7.2" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0", @@ -95,7 +108,7 @@ "./src/preview.ts" ] }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd", + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded", "storybook": { "displayName": "Viewport", "icon": "https://user-images.githubusercontent.com/263385/101991678-48cdf300-3c7c-11eb-9764-f8af293c1b28.png", diff --git a/code/addons/viewport/src/shortcuts.ts b/code/addons/viewport/src/shortcuts.ts index 779726eb9e23..6e9b7302b1c1 100644 --- a/code/addons/viewport/src/shortcuts.ts +++ b/code/addons/viewport/src/shortcuts.ts @@ -1,6 +1,11 @@ import type { API } from '@storybook/api'; import { ADDON_ID } from './constants'; +type State = { + selected: string; + isRotated: boolean; +}; + const getCurrentViewportIndex = (viewportsKeys: string[], current: string): number => viewportsKeys.indexOf(current); @@ -24,7 +29,7 @@ export const registerShortcuts = async (api: API, setState: any, viewportsKeys: defaultShortcut: ['shift', 'V'], actionName: 'previous', action: () => { - const { selected, isRotated } = api.getAddonState(ADDON_ID); + const { selected, isRotated } = api.getAddonState(ADDON_ID); setState({ selected: getPreviousViewport(viewportsKeys, selected), isRotated, @@ -37,7 +42,7 @@ export const registerShortcuts = async (api: API, setState: any, viewportsKeys: defaultShortcut: ['V'], actionName: 'next', action: () => { - const { selected, isRotated } = api.getAddonState(ADDON_ID); + const { selected, isRotated } = api.getAddonState(ADDON_ID); setState({ selected: getNextViewport(viewportsKeys, selected), isRotated, @@ -50,7 +55,7 @@ export const registerShortcuts = async (api: API, setState: any, viewportsKeys: defaultShortcut: ['alt', 'V'], actionName: 'reset', action: () => { - const { isRotated } = api.getAddonState(ADDON_ID); + const { isRotated } = api.getAddonState(ADDON_ID); setState({ selected: 'reset', isRotated, diff --git a/code/addons/viewport/tsconfig.json b/code/addons/viewport/tsconfig.json index d23f9a406fc2..52d43eaaa9b9 100644 --- a/code/addons/viewport/tsconfig.json +++ b/code/addons/viewport/tsconfig.json @@ -1,12 +1,4 @@ { "extends": "../../tsconfig.json", - "include": ["src/**/*"], - "exclude": [ - "src/**/*.test.*", - "src/**/tests/**/*", - "src/**/__tests__/**/*", - "src/**/*.stories.*", - "src/**/*.mockdata.*", - "src/**/__testfixtures__/**" - ] + "include": ["src/**/*"] } diff --git a/code/frameworks/angular/jest.config.js b/code/frameworks/angular/jest.config.js index 687a16f155b2..dc0ffa5cecd4 100644 --- a/code/frameworks/angular/jest.config.js +++ b/code/frameworks/angular/jest.config.js @@ -1,5 +1,12 @@ +const path = require('path'); + module.exports = { + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), preset: 'jest-preset-angular', setupFilesAfterEnv: ['/setup-jest.ts'], - transformIgnorePatterns: ['^.+\\.js$'], + transformIgnorePatterns: ['/node_modules/(?!@angular|rxjs|nanoid|uuid)'], + snapshotFormat: { + escapeString: true, + printBasicPrototype: true, + }, }; diff --git a/code/frameworks/angular/package.json b/code/frameworks/angular/package.json index 52275544488c..6dcb8e151f57 100644 --- a/code/frameworks/angular/package.json +++ b/code/frameworks/angular/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/angular", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Storybook for Angular: Develop Angular components in isolation with hot reloading.", "keywords": [ "storybook", @@ -34,23 +34,24 @@ "prep": "rimraf dist && ../../../scripts/node_modules/.bin/tsc --project tsconfig.build.json && echo \"Preventing passing flags to tsc\"" }, "dependencies": { - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/api": "7.0.0-alpha.48", - "@storybook/builder-webpack5": "7.0.0-alpha.48", - "@storybook/client-logger": "7.0.0-alpha.48", - "@storybook/core-client": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/core-events": "7.0.0-alpha.48", - "@storybook/core-server": "7.0.0-alpha.48", - "@storybook/core-webpack": "7.0.0-alpha.48", - "@storybook/docs-tools": "7.0.0-alpha.48", - "@storybook/node-logger": "7.0.0-alpha.48", - "@storybook/store": "7.0.0-alpha.48", - "@storybook/types": "7.0.0-alpha.48", - "@types/node": "^16.0.0", - "@types/react": "^16.14.23", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/api": "7.0.0-alpha.51", + "@storybook/builder-webpack5": "7.0.0-alpha.51", + "@storybook/client-logger": "7.0.0-alpha.51", + "@storybook/core-client": "7.0.0-alpha.51", + "@storybook/core-common": "7.0.0-alpha.51", + "@storybook/core-events": "7.0.0-alpha.51", + "@storybook/core-server": "7.0.0-alpha.51", + "@storybook/core-webpack": "7.0.0-alpha.51", + "@storybook/docs-tools": "7.0.0-alpha.51", + "@storybook/node-logger": "7.0.0-alpha.51", + "@storybook/store": "7.0.0-alpha.51", + "@storybook/types": "7.0.0-alpha.51", + "@types/node": "^16.0.0 || ^18.0.0", + "@types/react": "^16.14.34", "@types/react-dom": "^16.9.14", "@types/semver": "^7.3.4", + "@types/webpack-env": "^1.18.0", "core-js": "^3.8.2", "find-up": "^5.0.0", "global": "^4.4.0", @@ -80,12 +81,12 @@ "@types/rimraf": "^3.0.2", "@types/tmp": "^0.2.3", "cross-spawn": "^7.0.3", - "jest": "^27.5.1", + "jest": "^29.3.1", "jest-preset-angular": "^12.0.0", - "jest-specific-snapshot": "^5.0.0", + "jest-specific-snapshot": "^6.0.0", "rimraf": "^3.0.2", "tmp": "^0.2.1", - "typescript": "~4.6.3", + "typescript": "^4.9.3", "webpack": "5", "zone.js": "^0.11.0" }, @@ -122,5 +123,5 @@ "access": "public" }, "builders": "dist/builders/builders.json", - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd" + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded" } diff --git a/code/frameworks/angular/setup-jest.ts b/code/frameworks/angular/setup-jest.ts index 3caa91649606..06e753a2e78e 100644 --- a/code/frameworks/angular/setup-jest.ts +++ b/code/frameworks/angular/setup-jest.ts @@ -1,4 +1,12 @@ // eslint-disable-next-line import/no-extraneous-dependencies import 'jest-preset-angular/setup-jest'; +import { webcrypto } from 'node:crypto'; + +Object.defineProperty(window, 'crypto', { + get() { + return webcrypto; + }, +}); + global.EventSource = class {} as any; diff --git a/code/frameworks/angular/src/builders/build-storybook/index.spec.ts b/code/frameworks/angular/src/builders/build-storybook/index.spec.ts index f539e00793a0..c5164efcf99e 100644 --- a/code/frameworks/angular/src/builders/build-storybook/index.spec.ts +++ b/code/frameworks/angular/src/builders/build-storybook/index.spec.ts @@ -3,8 +3,13 @@ import { TestingArchitectHost } from '@angular-devkit/architect/testing'; import { schema } from '@angular-devkit/core'; import * as path from 'path'; -const buildStandaloneMock = jest.fn(); -jest.doMock('@storybook/angular/standalone', () => buildStandaloneMock); +const buildDevStandaloneMock = jest.fn(); +const buildStaticStandaloneMock = jest.fn(); +const buildMock = { + buildDevStandalone: buildDevStandaloneMock, + buildStaticStandalone: buildStaticStandaloneMock, +}; +jest.doMock('@storybook/core-server', () => buildMock); jest.doMock('find-up', () => ({ sync: () => './storybook/tsconfig.ts' })); const cpSpawnMock = { @@ -50,7 +55,7 @@ describe('Build Storybook Builder', () => { }); beforeEach(() => { - buildStandaloneMock.mockImplementation((_options: unknown) => Promise.resolve()); + buildStaticStandaloneMock.mockImplementation((_options: unknown) => Promise.resolve()); cpSpawnMock.spawn.mockImplementation(() => ({ stdout: { on: () => {} }, stderr: { on: () => {} }, @@ -74,14 +79,16 @@ describe('Build Storybook Builder', () => { expect(output.success).toBeTruthy(); expect(cpSpawnMock.spawn).not.toHaveBeenCalledWith(); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildStaticStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: 'angular-cli:build-2', angularBuilderContext: expect.any(Object), angularBuilderOptions: {}, configDir: '.storybook', + docs: undefined, loglevel: undefined, quiet: false, outputDir: 'storybook-static', + packageJson: expect.any(Object), mode: 'static', tsConfig: './storybook/tsconfig.ts', webpackStatsJson: false, @@ -100,14 +107,16 @@ describe('Build Storybook Builder', () => { expect(output.success).toBeTruthy(); expect(cpSpawnMock.spawn).not.toHaveBeenCalledWith(); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildStaticStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: null, angularBuilderContext: expect.any(Object), angularBuilderOptions: {}, configDir: '.storybook', + docs: undefined, loglevel: undefined, quiet: false, outputDir: 'storybook-static', + packageJson: expect.any(Object), mode: 'static', tsConfig: 'path/to/tsConfig.json', webpackStatsJson: false, @@ -127,14 +136,16 @@ describe('Build Storybook Builder', () => { expect(output.success).toBeTruthy(); expect(cpSpawnMock.spawn).not.toHaveBeenCalledWith(); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildStaticStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: null, angularBuilderContext: expect.any(Object), angularBuilderOptions: {}, configDir: '.storybook', + docs: undefined, loglevel: undefined, quiet: false, outputDir: 'storybook-static', + packageJson: expect.any(Object), mode: 'static', tsConfig: 'path/to/tsConfig.json', webpackStatsJson: true, @@ -142,7 +153,7 @@ describe('Build Storybook Builder', () => { }); it('should throw error', async () => { - buildStandaloneMock.mockRejectedValue(true); + buildStaticStandaloneMock.mockRejectedValue(true); const run = await architect.scheduleBuilder('@storybook/angular:start-storybook', { browserTarget: 'angular-cli:build-2', @@ -177,16 +188,19 @@ describe('Build Storybook Builder', () => { ['compodoc', '-p', './storybook/tsconfig.ts', '-d', '', '-e', 'json'], { cwd: '', + shell: true, } ); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildStaticStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: 'angular-cli:build-2', angularBuilderContext: expect.any(Object), angularBuilderOptions: {}, configDir: '.storybook', + docs: undefined, loglevel: undefined, quiet: false, outputDir: 'storybook-static', + packageJson: expect.any(Object), mode: 'static', tsConfig: './storybook/tsconfig.ts', webpackStatsJson: false, @@ -206,14 +220,16 @@ describe('Build Storybook Builder', () => { expect(output.success).toBeTruthy(); expect(cpSpawnMock.spawn).not.toHaveBeenCalledWith(); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildStaticStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: null, angularBuilderContext: expect.any(Object), angularBuilderOptions: { styles: ['style.scss'] }, configDir: '.storybook', + docs: undefined, loglevel: undefined, quiet: false, outputDir: 'storybook-static', + packageJson: expect.any(Object), mode: 'static', tsConfig: 'path/to/tsConfig.json', webpackStatsJson: false, diff --git a/code/frameworks/angular/src/builders/start-storybook/index.spec.ts b/code/frameworks/angular/src/builders/start-storybook/index.spec.ts index aacd352b6a8c..c70d7cbf5b37 100644 --- a/code/frameworks/angular/src/builders/start-storybook/index.spec.ts +++ b/code/frameworks/angular/src/builders/start-storybook/index.spec.ts @@ -3,8 +3,13 @@ import { TestingArchitectHost } from '@angular-devkit/architect/testing'; import { schema } from '@angular-devkit/core'; import * as path from 'path'; -const buildStandaloneMock = jest.fn(); -jest.doMock('@storybook/angular/standalone', () => buildStandaloneMock); +const buildDevStandaloneMock = jest.fn(); +const buildStaticStandaloneMock = jest.fn(); +const buildMock = { + buildDevStandalone: buildDevStandaloneMock, + buildStaticStandalone: buildStaticStandaloneMock, +}; +jest.doMock('@storybook/core-server', () => buildMock); jest.doMock('find-up', () => ({ sync: () => './storybook/tsconfig.ts' })); const cpSpawnMock = { @@ -49,7 +54,7 @@ describe('Start Storybook Builder', () => { }); beforeEach(() => { - buildStandaloneMock.mockImplementation((_options: unknown) => Promise.resolve()); + buildDevStandaloneMock.mockImplementation((_options: unknown) => Promise.resolve()); cpSpawnMock.spawn.mockImplementation(() => ({ stdout: { on: () => {} }, stderr: { on: () => {} }, @@ -74,14 +79,16 @@ describe('Start Storybook Builder', () => { expect(output.success).toBeTruthy(); expect(cpSpawnMock.spawn).not.toHaveBeenCalledWith(); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildDevStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: 'angular-cli:build-2', angularBuilderContext: expect.any(Object), angularBuilderOptions: {}, ci: false, configDir: '.storybook', + docs: undefined, host: 'localhost', https: false, + packageJson: expect.any(Object), port: 4400, quiet: false, smokeTest: false, @@ -105,14 +112,16 @@ describe('Start Storybook Builder', () => { expect(output.success).toBeTruthy(); expect(cpSpawnMock.spawn).not.toHaveBeenCalledWith(); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildDevStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: null, angularBuilderContext: expect.any(Object), angularBuilderOptions: {}, ci: false, configDir: '.storybook', + docs: undefined, host: 'localhost', https: false, + packageJson: expect.any(Object), port: 4400, quiet: false, smokeTest: false, @@ -124,7 +133,7 @@ describe('Start Storybook Builder', () => { }); it('should throw error', async () => { - buildStandaloneMock.mockRejectedValue(true); + buildDevStandaloneMock.mockRejectedValue(true); const run = await architect.scheduleBuilder('@storybook/angular:start-storybook', { browserTarget: 'angular-cli:build-2', @@ -159,16 +168,19 @@ describe('Start Storybook Builder', () => { ['compodoc', '-p', './storybook/tsconfig.ts', '-d', '', '-e', 'json'], { cwd: '', + shell: true, } ); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildDevStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: 'angular-cli:build-2', angularBuilderContext: expect.any(Object), angularBuilderOptions: {}, ci: false, configDir: '.storybook', + docs: undefined, host: 'localhost', https: false, + packageJson: expect.any(Object), port: 9009, quiet: false, smokeTest: false, @@ -193,7 +205,7 @@ describe('Start Storybook Builder', () => { expect(output.success).toBeTruthy(); expect(cpSpawnMock.spawn).not.toHaveBeenCalledWith(); - expect(buildStandaloneMock).toHaveBeenCalledWith({ + expect(buildDevStandaloneMock).toHaveBeenCalledWith({ angularBrowserTarget: null, angularBuilderContext: expect.any(Object), angularBuilderOptions: { @@ -201,9 +213,11 @@ describe('Start Storybook Builder', () => { }, ci: false, configDir: '.storybook', + docs: undefined, host: 'localhost', https: false, port: 4400, + packageJson: expect.any(Object), quiet: false, smokeTest: false, sslCa: undefined, diff --git a/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts b/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts index 900bc6a7669f..06d0f37a5223 100644 --- a/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts +++ b/code/frameworks/angular/src/builders/utils/run-compodoc.spec.ts @@ -51,6 +51,7 @@ describe('runCompodoc', () => { ['compodoc', '-p', 'path/to/tsconfig.json', '-d', 'path/to/project'], { cwd: 'path/to/project', + shell: true, } ); }); @@ -74,6 +75,7 @@ describe('runCompodoc', () => { ['compodoc', '-d', 'path/to/project', '-p', 'path/to/tsconfig.stories.json'], { cwd: 'path/to/project', + shell: true, } ); }); diff --git a/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts b/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts index 0129a09f68a2..a50a8c5ff80c 100644 --- a/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts +++ b/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts @@ -18,8 +18,8 @@ describe('RendererFactory', () => { beforeEach(async () => { rendererFactory = new RendererFactory(); document.body.innerHTML = - '
'; - rootTargetDOMNode = global.document.getElementById('root'); + '
'; + rootTargetDOMNode = global.document.getElementById('storybook-root'); rootDocstargetDOMNode = global.document.getElementById('root-docs'); (platformBrowserDynamic as any).mockImplementation(platformBrowserDynamicTesting); jest.spyOn(console, 'log').mockImplementation(() => {}); @@ -301,14 +301,16 @@ describe('RendererFactory', () => { }); it('should reset root HTML', async () => { - global.document.getElementById('root').appendChild(global.document.createElement('👾')); + global.document + .getElementById('storybook-root') + .appendChild(global.document.createElement('👾')); - expect(global.document.getElementById('root').innerHTML).toContain('Canvas 🖼'); + expect(global.document.getElementById('storybook-root').innerHTML).toContain('Canvas 🖼'); const render = await rendererFactory.getRendererInstance( 'my-story-in-docs', rootDocstargetDOMNode ); - expect(global.document.getElementById('root').innerHTML).toBe(''); + expect(global.document.getElementById('storybook-root').innerHTML).toBe(''); }); }); diff --git a/code/frameworks/angular/src/client/angular/helpers.ts b/code/frameworks/angular/src/client/angular/helpers.ts index ce0c1fcd9f1c..10ce71718090 100644 --- a/code/frameworks/angular/src/client/angular/helpers.ts +++ b/code/frameworks/angular/src/client/angular/helpers.ts @@ -7,7 +7,7 @@ import { Subscriber, Observable, ReplaySubject } from 'rxjs'; import { PartialStoryFn } from '@storybook/types'; import { AppComponent } from './app.component'; import { STORY } from './app.token'; -import { NgModuleMetadata, StoryFnAngularReturnType, AngularFramework } from '../types'; +import { NgModuleMetadata, StoryFnAngularReturnType, AngularRenderer } from '../types'; const { document } = global; @@ -131,7 +131,7 @@ const getExistenceOfComponentInModules = ( }); }; -const initModule = (storyFn: PartialStoryFn) => { +const initModule = (storyFn: PartialStoryFn) => { const storyObj = storyFn(); const { component, template, props, styles, moduleMetadata = {} } = storyObj; @@ -198,7 +198,7 @@ const draw = (newModule: DynamicComponentType): void => { } }; -export const renderNgApp = (storyFn: PartialStoryFn, forced: boolean) => { +export const renderNgApp = (storyFn: PartialStoryFn, forced: boolean) => { if (!forced) { draw(initModule(storyFn)); } else { diff --git a/code/frameworks/angular/src/client/decorateStory.test.ts b/code/frameworks/angular/src/client/decorateStory.test.ts index 646f56398c80..bf5d7b6dd5bb 100644 --- a/code/frameworks/angular/src/client/decorateStory.test.ts +++ b/code/frameworks/angular/src/client/decorateStory.test.ts @@ -3,12 +3,12 @@ import { DecoratorFunction, StoryContext } from '@storybook/types'; import { componentWrapperDecorator } from './decorators'; import decorateStory from './decorateStory'; -import { AngularFramework } from './types'; +import { AngularRenderer } from './types'; describe('decorateStory', () => { describe('angular behavior', () => { it('should use componentWrapperDecorator with args', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ componentWrapperDecorator(ParentComponent, ({ args }) => args), componentWrapperDecorator( (story) => `${story}`, @@ -42,7 +42,7 @@ describe('decorateStory', () => { }); it('should use componentWrapperDecorator with input / output', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ componentWrapperDecorator(ParentComponent, { parentInput: 'Parent input', parentOutput: () => {}, @@ -81,7 +81,7 @@ describe('decorateStory', () => { }); it('should use componentWrapperDecorator', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ componentWrapperDecorator(ParentComponent), componentWrapperDecorator((story) => `${story}`), componentWrapperDecorator((story) => `${story}`), @@ -96,7 +96,7 @@ describe('decorateStory', () => { }); it('should use template in preference to component parameters', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ (s) => { const story = s(); return { @@ -129,7 +129,7 @@ describe('decorateStory', () => { }); it('should include story templates in decorators', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ (s) => { const story = s(); return { @@ -162,7 +162,7 @@ describe('decorateStory', () => { }); it('should include story components in decorators', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ (s) => { const story = s(); return { @@ -195,7 +195,7 @@ describe('decorateStory', () => { }); it('should include legacy story components in decorators', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ (s) => { const story = s(); return { @@ -229,7 +229,7 @@ describe('decorateStory', () => { }); it('should keep template with an empty value', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ componentWrapperDecorator(ParentComponent), ]; const decorated = decorateStory(() => ({ template: '' }), decorators); @@ -272,7 +272,7 @@ describe('decorateStory', () => { describe('default behavior', () => { it('calls decorators in out to in order', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ (s) => { const story = s(); return { ...story, props: { a: [...story.props.a, 1] } }; @@ -292,7 +292,7 @@ describe('decorateStory', () => { }); it('passes context through to sub decorators', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ (s, c) => { const story = s({ ...c, k: 1 }); return { ...story, props: { a: [...story.props.a, c.k] } }; @@ -312,7 +312,7 @@ describe('decorateStory', () => { }); it('DOES NOT merge parameter or pass through parameters key in context', () => { - const decorators: DecoratorFunction[] = [ + const decorators: DecoratorFunction[] = [ (s, c) => { const story = s({ ...c, k: 1, parameters: { p: 1 } }); return { @@ -347,7 +347,7 @@ describe('decorateStory', () => { }); }); -function makeContext(input: Record): StoryContext { +function makeContext(input: Record): StoryContext { return { id: 'id', kind: 'kind', @@ -355,7 +355,7 @@ function makeContext(input: Record): StoryContext; + } as StoryContext; } @Component({ diff --git a/code/frameworks/angular/src/client/decorateStory.ts b/code/frameworks/angular/src/client/decorateStory.ts index a7816084f232..2b3daf651371 100644 --- a/code/frameworks/angular/src/client/decorateStory.ts +++ b/code/frameworks/angular/src/client/decorateStory.ts @@ -2,15 +2,15 @@ import { DecoratorFunction, LegacyStoryFn, StoryContext } from '@storybook/types import { sanitizeStoryContextUpdate } from '@storybook/store'; import { computesTemplateFromComponent } from './angular-beta/ComputesTemplateFromComponent'; -import { AngularFramework } from './types'; +import { AngularRenderer } from './types'; export default function decorateStory( - mainStoryFn: LegacyStoryFn, - decorators: DecoratorFunction[] -): LegacyStoryFn { + mainStoryFn: LegacyStoryFn, + decorators: DecoratorFunction[] +): LegacyStoryFn { const returnDecorators = [cleanArgsDecorator, ...decorators].reduce( - (previousStoryFn: LegacyStoryFn, decorator) => - (context: StoryContext) => { + (previousStoryFn: LegacyStoryFn, decorator) => + (context: StoryContext) => { const decoratedStory = decorator((update) => { return previousStoryFn({ ...context, @@ -29,9 +29,9 @@ export default function decorateStory( export { decorateStory }; const prepareMain = ( - story: AngularFramework['storyResult'], - context: StoryContext -): AngularFramework['storyResult'] => { + story: AngularRenderer['storyResult'], + context: StoryContext +): AngularRenderer['storyResult'] => { let { template } = story; const component = story.component ?? context.component; @@ -50,7 +50,7 @@ function hasNoTemplate(template: string | null | undefined): template is undefin return template === null || template === undefined; } -const cleanArgsDecorator: DecoratorFunction = (storyFn, context) => { +const cleanArgsDecorator: DecoratorFunction = (storyFn, context) => { if (!context.argTypes || !context.args) { return storyFn(); } diff --git a/code/frameworks/angular/src/client/decorators.test.ts b/code/frameworks/angular/src/client/decorators.test.ts index 3f7651051f2a..8ed4e347c55a 100644 --- a/code/frameworks/angular/src/client/decorators.test.ts +++ b/code/frameworks/angular/src/client/decorators.test.ts @@ -2,9 +2,9 @@ import { Addon_StoryContext } from '@storybook/types'; import { Component } from '@angular/core'; import { moduleMetadata } from './decorators'; -import { AngularFramework } from './types'; +import { AngularRenderer } from './types'; -const defaultContext: Addon_StoryContext = { +const defaultContext: Addon_StoryContext = { componentId: 'unspecified', kind: 'unspecified', title: 'unspecified', diff --git a/code/frameworks/angular/src/client/decorators.ts b/code/frameworks/angular/src/client/decorators.ts index 9e5a59ca04e6..b34b416e71a2 100644 --- a/code/frameworks/angular/src/client/decorators.ts +++ b/code/frameworks/angular/src/client/decorators.ts @@ -3,12 +3,12 @@ import { Type } from '@angular/core'; import { DecoratorFunction, StoryContext } from '@storybook/types'; import { computesTemplateFromComponent } from './angular-beta/ComputesTemplateFromComponent'; import { isComponent } from './angular-beta/utils/NgComponentAnalyzer'; -import { ICollection, NgModuleMetadata, AngularFramework } from './types'; +import { ICollection, NgModuleMetadata, AngularRenderer } from './types'; // We use `any` here as the default type rather than `Args` because we need something that is // castable to any component-specific args type when the user is being careful. export const moduleMetadata = - (metadata: Partial): DecoratorFunction => + (metadata: Partial): DecoratorFunction => (storyFn) => { const story = storyFn(); const storyMetadata = story.moduleMetadata || {}; @@ -32,8 +32,8 @@ export const moduleMetadata = export const componentWrapperDecorator = ( element: Type | ((story: string) => string), - props?: ICollection | ((storyContext: StoryContext) => ICollection) - ): DecoratorFunction => + props?: ICollection | ((storyContext: StoryContext) => ICollection) + ): DecoratorFunction => (storyFn, storyContext) => { const story = storyFn(); const currentProps = typeof props === 'function' ? (props(storyContext) as ICollection) : props; diff --git a/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-posix.snapshot b/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-posix.snapshot index dbb2d4c08edf..de95727d81f5 100644 --- a/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-posix.snapshot +++ b/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-posix.snapshot @@ -10,7 +10,7 @@ Object { "getSignature": Object { "description": "

Getter for inputValue.

", - "line": 115, + "line": 116, "name": "inputValue", "rawdescription": " Getter for \`inputValue\`.", @@ -42,7 +42,7 @@ Getter for \`inputValue\`.", "type": "string", }, ], - "line": 110, + "line": 111, "name": "inputValue", "rawdescription": " Setter for \`inputValue\` that is also an \`@Input\`.", @@ -74,7 +74,7 @@ Setter for \`inputValue\` that is also an \`@Input\`.", "type": "T[]", }, ], - "line": 195, + "line": 196, "name": "item", "returnType": "void", "type": "void", @@ -84,7 +84,7 @@ Setter for \`inputValue\` that is also an \`@Input\`.", "getSignature": Object { "description": "

Get the private value.

", - "line": 154, + "line": 155, "name": "value", "rawdescription": " Get the private value.", @@ -116,7 +116,7 @@ Get the private value.", "type": "string | number", }, ], - "line": 149, + "line": 150, "name": "value", "rawdescription": " Set the private value.", @@ -137,14 +137,14 @@ like bold, italic, and inline code.

", "encapsulation": Array [], "entryComponents": Array [], - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "hostBindings": Array [ Object { "decorators": Array [], "defaultValue": "false", "deprecated": false, "deprecationMessage": "", - "line": 124, + "line": 125, "name": "class.focused", "type": "boolean", }, @@ -164,7 +164,7 @@ like bold, italic, and inline code.

], "deprecated": false, "deprecationMessage": "", - "line": 120, + "line": 121, "name": "click", }, ], @@ -177,7 +177,7 @@ like bold, italic, and inline code.

"deprecationMessage": "", "description": "

Specify the accent-type of the button

", - "line": 56, + "line": 57, "name": "accent", "rawdescription": " Specify the accent-type of the button", @@ -190,7 +190,7 @@ Specify the accent-type of the button", "deprecationMessage": "", "description": "

Appearance style of the button.

", - "line": 52, + "line": 53, "name": "appearance", "rawdescription": " Appearance style of the button.", @@ -202,7 +202,7 @@ Appearance style of the button.", "deprecationMessage": "", "description": "

Setter for inputValue that is also an @Input.

", - "line": 110, + "line": 111, "name": "inputValue", "rawdescription": " Setter for \`inputValue\` that is also an \`@Input\`.", @@ -215,7 +215,7 @@ Setter for \`inputValue\` that is also an \`@Input\`.", "deprecationMessage": "", "description": "

Sets the button to a disabled state.

", - "line": 60, + "line": 61, "name": "isDisabled", "rawdescription": " Sets the button to a disabled state.", @@ -225,7 +225,7 @@ Sets the button to a disabled state.", "decorators": Array [], "deprecated": false, "deprecationMessage": "", - "line": 195, + "line": 196, "name": "item", "type": "T[]", }, @@ -238,24 +238,24 @@ Sets the button to a disabled state.", "jsdoctags": Array [ Object { "comment": "", - "end": 1525, + "end": 1587, "flags": 4227072, "kind": 325, "modifierFlagsCache": 0, - "pos": 1512, + "pos": 1574, "tagName": Object { - "end": 1521, + "end": 1583, "escapedText": "required", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 1513, + "pos": 1575, "transformFlags": 0, }, "transformFlags": 0, }, ], - "line": 68, + "line": 69, "name": "label", "rawdescription": " @@ -268,7 +268,7 @@ The inner text of the button. "decorators": Array [], "deprecated": false, "deprecationMessage": "", - "line": 192, + "line": 193, "name": "showKeyAlias", "type": "", }, @@ -279,7 +279,7 @@ The inner text of the button. "deprecationMessage": "", "description": "

Size of the button.

", - "line": 72, + "line": 73, "name": "size", "rawdescription": " Size of the button.", @@ -291,7 +291,7 @@ Size of the button.", "deprecationMessage": "", "description": "

Specifies some arbitrary object

", - "line": 75, + "line": 76, "name": "someDataObject", "rawdescription": " Specifies some arbitrary object", @@ -307,24 +307,24 @@ Specifies some arbitrary object", "jsdoctags": Array [ Object { "comment": "", - "end": 1802, + "end": 1864, "flags": 4227072, "kind": 329, "modifierFlagsCache": 0, - "pos": 1787, + "pos": 1849, "tagName": Object { - "end": 1798, + "end": 1860, "escapedText": "deprecated", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 1788, + "pos": 1850, "transformFlags": 0, }, "transformFlags": 0, }, ], - "line": 83, + "line": 84, "name": "somethingYouShouldNotUse", "rawdescription": " @@ -361,21 +361,21 @@ Some input you shouldn't use. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 3518, + "end": 3580, "escapedText": "x", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3517, + "pos": 3579, "transformFlags": 0, }, "tagName": Object { - "end": 3516, + "end": 3578, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3511, + "pos": 3573, "transformFlags": 0, }, "type": "number", @@ -386,27 +386,27 @@ Some input you shouldn't use. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 3563, + "end": 3625, "escapedText": "y", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3562, + "pos": 3624, "transformFlags": 0, }, "tagName": Object { - "end": 3561, + "end": 3623, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3556, + "pos": 3618, "transformFlags": 0, }, "type": "string | number", }, ], - "line": 164, + "line": 165, "modifierKind": Array [ 123, ], @@ -448,7 +448,7 @@ An internal calculation method which adds \`x\` and \`y\` together. "type": "", }, ], - "line": 120, + "line": 121, "name": "onClickListener", "optional": false, "returnType": "void", @@ -474,27 +474,27 @@ An internal calculation method which adds \`x\` and \`y\` together. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 4079, + "end": 4141, "escapedText": "password", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 4071, + "pos": 4133, "transformFlags": 0, }, "tagName": Object { - "end": 4070, + "end": 4132, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 4065, + "pos": 4127, "transformFlags": 0, }, "type": "string", }, ], - "line": 187, + "line": 188, "modifierKind": Array [ 121, ], @@ -529,28 +529,28 @@ A private method. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 3938, + "end": 4000, "escapedText": "id", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3936, + "pos": 3998, "transformFlags": 0, }, "optional": true, "tagName": Object { - "end": 3935, + "end": 3997, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3930, + "pos": 3992, "transformFlags": 0, }, "type": "number", }, ], - "line": 178, + "line": 179, "modifierKind": Array [ 122, ], @@ -588,7 +588,7 @@ A protected method. "type": "ISomeInterface", }, ], - "line": 169, + "line": 170, "modifierKind": Array [ 123, ], @@ -610,7 +610,7 @@ A public method using an interface.", "description": "

Handler to be called when the button is clicked by a user.

Will also block the emission of the event if isDisabled is true.

", - "line": 91, + "line": 92, "name": "onClick", "rawdescription": " @@ -627,7 +627,7 @@ Will also block the emission of the event if \`isDisabled\` is true. "deprecated": false, "deprecationMessage": "", "description": "", - "line": 106, + "line": 107, "modifierKind": Array [ 121, ], @@ -641,7 +641,7 @@ Will also block the emission of the event if \`isDisabled\` is true. "deprecationMessage": "", "description": "

Private value.

", - "line": 146, + "line": 147, "modifierKind": Array [ 121, ], @@ -661,7 +661,7 @@ Private value.", "deprecated": false, "deprecationMessage": "", "description": "", - "line": 48, + "line": 49, "name": "buttonRef", "optional": false, "type": "ElementRef", @@ -677,7 +677,7 @@ Private value.", "deprecated": false, "deprecationMessage": "", "description": "", - "line": 124, + "line": 125, "name": "focus", "optional": false, "type": "", @@ -688,7 +688,7 @@ Private value.", "deprecationMessage": "", "description": "

Public value.

", - "line": 143, + "line": 144, "modifierKind": Array [ 123, ], @@ -702,7 +702,7 @@ Public value.", "deprecated": false, "deprecationMessage": "", "description": "", - "line": 199, + "line": 200, "modifierKind": Array [ 123, ], @@ -937,7 +937,7 @@ export class InputComponent { Object { "coverageCount": "16/25", "coveragePercent": 64, - "filePath": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "filePath": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "linktype": "component", "name": "InputComponent", "status": "good", @@ -946,7 +946,7 @@ export class InputComponent { Object { "coverageCount": "0/4", "coveragePercent": 0, - "filePath": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "filePath": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "linktype": "interface", "name": "ISomeInterface", "status": "low", @@ -955,7 +955,7 @@ export class InputComponent { Object { "coverageCount": "0/1", "coveragePercent": 0, - "filePath": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "filePath": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "linksubtype": "variable", "linktype": "miscellaneous", "name": "exportedConstant", @@ -973,7 +973,7 @@ export class InputComponent { Object { "deprecated": false, "deprecationMessage": "", - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "id": "interface-ISomeInterface-d145da25329b094ee29610c45a9e46387cb39eddb2a67b4c9fadb84bcec76eacd60d131e48d98b2ee5725dedd25f2eb299b704e8e0a34307d6e84f6e57d57044", "indexSignatures": Array [], "kind": 165, @@ -984,7 +984,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "line": 25, + "line": 26, "name": "one", "optional": false, "type": "string", @@ -993,7 +993,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "line": 27, + "line": 28, "name": "three", "optional": false, "type": "any[]", @@ -1002,7 +1002,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "line": 26, + "line": 27, "name": "two", "optional": false, "type": "boolean", @@ -1230,14 +1230,14 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "name": "ButtonAccent", "subtype": "enum", }, ], "functions": Array [], "groupedEnumerations": Object { - "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts": Array [ + "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts": Array [ Object { "childs": Array [ Object { @@ -1257,7 +1257,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "name": "ButtonAccent", "subtype": "enum", }, @@ -1265,13 +1265,13 @@ export class InputComponent { }, "groupedFunctions": Object {}, "groupedTypeAliases": Object { - "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts": Array [ + "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts": Array [ Object { "ctype": "miscellaneous", "deprecated": false, "deprecationMessage": "", "description": "", - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "kind": 186, "name": "ButtonSize", "rawtype": "\\"small\\" | \\"medium\\" | \\"large\\" | \\"xlarge\\"", @@ -1280,13 +1280,13 @@ export class InputComponent { ], }, "groupedVariables": Object { - "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts": Array [ + "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts": Array [ Object { "ctype": "miscellaneous", "defaultValue": "'An exported constant'", "deprecated": false, "deprecationMessage": "", - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "name": "exportedConstant", "subtype": "variable", "type": "string", @@ -1299,7 +1299,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "kind": 186, "name": "ButtonSize", "rawtype": "\\"small\\" | \\"medium\\" | \\"large\\" | \\"xlarge\\"", @@ -1312,7 +1312,7 @@ export class InputComponent { "defaultValue": "'An exported constant'", "deprecated": false, "deprecationMessage": "", - "file": "addons/docs/src/frameworks/angular/__testfixtures__/doc-button/input.ts", + "file": "frameworks/angular/src/client/docs/__testfixtures__/doc-button/input.ts", "name": "exportedConstant", "subtype": "variable", "type": "string", diff --git a/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-undefined.snapshot b/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-undefined.snapshot index 012aeb4a1651..de95727d81f5 100644 --- a/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-undefined.snapshot +++ b/code/frameworks/angular/src/client/docs/__testfixtures__/doc-button/compodoc-undefined.snapshot @@ -10,7 +10,7 @@ Object { "getSignature": Object { "description": "

Getter for inputValue.

", - "line": 115, + "line": 116, "name": "inputValue", "rawdescription": " Getter for \`inputValue\`.", @@ -42,7 +42,7 @@ Getter for \`inputValue\`.", "type": "string", }, ], - "line": 110, + "line": 111, "name": "inputValue", "rawdescription": " Setter for \`inputValue\` that is also an \`@Input\`.", @@ -74,7 +74,7 @@ Setter for \`inputValue\` that is also an \`@Input\`.", "type": "T[]", }, ], - "line": 195, + "line": 196, "name": "item", "returnType": "void", "type": "void", @@ -84,7 +84,7 @@ Setter for \`inputValue\` that is also an \`@Input\`.", "getSignature": Object { "description": "

Get the private value.

", - "line": 154, + "line": 155, "name": "value", "rawdescription": " Get the private value.", @@ -116,7 +116,7 @@ Get the private value.", "type": "string | number", }, ], - "line": 149, + "line": 150, "name": "value", "rawdescription": " Set the private value.", @@ -144,7 +144,7 @@ like bold, italic, and inline code.

"defaultValue": "false", "deprecated": false, "deprecationMessage": "", - "line": 124, + "line": 125, "name": "class.focused", "type": "boolean", }, @@ -164,7 +164,7 @@ like bold, italic, and inline code.

], "deprecated": false, "deprecationMessage": "", - "line": 120, + "line": 121, "name": "click", }, ], @@ -177,7 +177,7 @@ like bold, italic, and inline code.

"deprecationMessage": "", "description": "

Specify the accent-type of the button

", - "line": 56, + "line": 57, "name": "accent", "rawdescription": " Specify the accent-type of the button", @@ -190,7 +190,7 @@ Specify the accent-type of the button", "deprecationMessage": "", "description": "

Appearance style of the button.

", - "line": 52, + "line": 53, "name": "appearance", "rawdescription": " Appearance style of the button.", @@ -202,7 +202,7 @@ Appearance style of the button.", "deprecationMessage": "", "description": "

Setter for inputValue that is also an @Input.

", - "line": 110, + "line": 111, "name": "inputValue", "rawdescription": " Setter for \`inputValue\` that is also an \`@Input\`.", @@ -215,7 +215,7 @@ Setter for \`inputValue\` that is also an \`@Input\`.", "deprecationMessage": "", "description": "

Sets the button to a disabled state.

", - "line": 60, + "line": 61, "name": "isDisabled", "rawdescription": " Sets the button to a disabled state.", @@ -225,7 +225,7 @@ Sets the button to a disabled state.", "decorators": Array [], "deprecated": false, "deprecationMessage": "", - "line": 195, + "line": 196, "name": "item", "type": "T[]", }, @@ -238,24 +238,24 @@ Sets the button to a disabled state.", "jsdoctags": Array [ Object { "comment": "", - "end": 1525, + "end": 1587, "flags": 4227072, "kind": 325, "modifierFlagsCache": 0, - "pos": 1512, + "pos": 1574, "tagName": Object { - "end": 1521, + "end": 1583, "escapedText": "required", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 1513, + "pos": 1575, "transformFlags": 0, }, "transformFlags": 0, }, ], - "line": 68, + "line": 69, "name": "label", "rawdescription": " @@ -268,7 +268,7 @@ The inner text of the button. "decorators": Array [], "deprecated": false, "deprecationMessage": "", - "line": 192, + "line": 193, "name": "showKeyAlias", "type": "", }, @@ -279,7 +279,7 @@ The inner text of the button. "deprecationMessage": "", "description": "

Size of the button.

", - "line": 72, + "line": 73, "name": "size", "rawdescription": " Size of the button.", @@ -291,7 +291,7 @@ Size of the button.", "deprecationMessage": "", "description": "

Specifies some arbitrary object

", - "line": 75, + "line": 76, "name": "someDataObject", "rawdescription": " Specifies some arbitrary object", @@ -307,24 +307,24 @@ Specifies some arbitrary object", "jsdoctags": Array [ Object { "comment": "", - "end": 1802, + "end": 1864, "flags": 4227072, "kind": 329, "modifierFlagsCache": 0, - "pos": 1787, + "pos": 1849, "tagName": Object { - "end": 1798, + "end": 1860, "escapedText": "deprecated", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 1788, + "pos": 1850, "transformFlags": 0, }, "transformFlags": 0, }, ], - "line": 83, + "line": 84, "name": "somethingYouShouldNotUse", "rawdescription": " @@ -361,21 +361,21 @@ Some input you shouldn't use. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 3518, + "end": 3580, "escapedText": "x", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3517, + "pos": 3579, "transformFlags": 0, }, "tagName": Object { - "end": 3516, + "end": 3578, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3511, + "pos": 3573, "transformFlags": 0, }, "type": "number", @@ -386,27 +386,27 @@ Some input you shouldn't use. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 3563, + "end": 3625, "escapedText": "y", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3562, + "pos": 3624, "transformFlags": 0, }, "tagName": Object { - "end": 3561, + "end": 3623, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3556, + "pos": 3618, "transformFlags": 0, }, "type": "string | number", }, ], - "line": 164, + "line": 165, "modifierKind": Array [ 123, ], @@ -448,7 +448,7 @@ An internal calculation method which adds \`x\` and \`y\` together. "type": "", }, ], - "line": 120, + "line": 121, "name": "onClickListener", "optional": false, "returnType": "void", @@ -474,27 +474,27 @@ An internal calculation method which adds \`x\` and \`y\` together. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 4079, + "end": 4141, "escapedText": "password", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 4071, + "pos": 4133, "transformFlags": 0, }, "tagName": Object { - "end": 4070, + "end": 4132, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 4065, + "pos": 4127, "transformFlags": 0, }, "type": "string", }, ], - "line": 187, + "line": 188, "modifierKind": Array [ 121, ], @@ -529,28 +529,28 @@ A private method. "deprecated": false, "deprecationMessage": "", "name": Object { - "end": 3938, + "end": 4000, "escapedText": "id", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3936, + "pos": 3998, "transformFlags": 0, }, "optional": true, "tagName": Object { - "end": 3935, + "end": 3997, "escapedText": "param", "flags": 4227072, "kind": 79, "modifierFlagsCache": 0, - "pos": 3930, + "pos": 3992, "transformFlags": 0, }, "type": "number", }, ], - "line": 178, + "line": 179, "modifierKind": Array [ 122, ], @@ -588,7 +588,7 @@ A protected method. "type": "ISomeInterface", }, ], - "line": 169, + "line": 170, "modifierKind": Array [ 123, ], @@ -610,7 +610,7 @@ A public method using an interface.", "description": "

Handler to be called when the button is clicked by a user.

Will also block the emission of the event if isDisabled is true.

", - "line": 91, + "line": 92, "name": "onClick", "rawdescription": " @@ -627,7 +627,7 @@ Will also block the emission of the event if \`isDisabled\` is true. "deprecated": false, "deprecationMessage": "", "description": "", - "line": 106, + "line": 107, "modifierKind": Array [ 121, ], @@ -641,7 +641,7 @@ Will also block the emission of the event if \`isDisabled\` is true. "deprecationMessage": "", "description": "

Private value.

", - "line": 146, + "line": 147, "modifierKind": Array [ 121, ], @@ -661,7 +661,7 @@ Private value.", "deprecated": false, "deprecationMessage": "", "description": "", - "line": 48, + "line": 49, "name": "buttonRef", "optional": false, "type": "ElementRef", @@ -677,7 +677,7 @@ Private value.", "deprecated": false, "deprecationMessage": "", "description": "", - "line": 124, + "line": 125, "name": "focus", "optional": false, "type": "", @@ -688,7 +688,7 @@ Private value.", "deprecationMessage": "", "description": "

Public value.

", - "line": 143, + "line": 144, "modifierKind": Array [ 123, ], @@ -702,7 +702,7 @@ Public value.", "deprecated": false, "deprecationMessage": "", "description": "", - "line": 199, + "line": 200, "modifierKind": Array [ 123, ], @@ -984,7 +984,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "line": 25, + "line": 26, "name": "one", "optional": false, "type": "string", @@ -993,7 +993,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "line": 27, + "line": 28, "name": "three", "optional": false, "type": "any[]", @@ -1002,7 +1002,7 @@ export class InputComponent { "deprecated": false, "deprecationMessage": "", "description": "", - "line": 26, + "line": 27, "name": "two", "optional": false, "type": "boolean", diff --git a/code/frameworks/angular/src/client/docs/sourceDecorator.ts b/code/frameworks/angular/src/client/docs/sourceDecorator.ts index 605112b11b24..7769aa6968aa 100644 --- a/code/frameworks/angular/src/client/docs/sourceDecorator.ts +++ b/code/frameworks/angular/src/client/docs/sourceDecorator.ts @@ -1,7 +1,7 @@ import { addons, useEffect } from '@storybook/addons'; import { PartialStoryFn } from '@storybook/types'; import { SNIPPET_RENDERED, SourceType } from '@storybook/docs-tools'; -import { StoryContext, AngularFramework } from '../types'; +import { StoryContext, AngularRenderer } from '../types'; import { computesTemplateSourceFromComponent } from '../../renderer'; export const skipSourceRender = (context: StoryContext) => { @@ -22,7 +22,7 @@ export const skipSourceRender = (context: StoryContext) => { * @param context StoryContext */ export const sourceDecorator = ( - storyFn: PartialStoryFn, + storyFn: PartialStoryFn, context: StoryContext ) => { const story = storyFn(); diff --git a/code/frameworks/angular/src/client/public-api.ts b/code/frameworks/angular/src/client/public-api.ts index 31c4c273420f..596a5fd1b4a3 100644 --- a/code/frameworks/angular/src/client/public-api.ts +++ b/code/frameworks/angular/src/client/public-api.ts @@ -3,20 +3,20 @@ import { Addon_ClientStoryApi, Addon_Loadable } from '@storybook/types'; import { start } from '@storybook/core-client'; import { renderToCanvas, render } from './render'; import decorateStory from './decorateStory'; -import { AngularFramework } from './types'; +import { AngularRenderer } from './types'; export * from './public-types'; const FRAMEWORK = 'angular'; -interface ClientApi extends Addon_ClientStoryApi { +interface ClientApi extends Addon_ClientStoryApi { configure(loader: Addon_Loadable, module: NodeModule): void; forceReRender(): void; raw: () => any; // todo add type load: (...args: any[]) => void; } -const api = start(renderToCanvas, { decorateStory, render }); +const api = start(renderToCanvas, { decorateStory, render }); export const storiesOf: ClientApi['storiesOf'] = (kind, m) => { return (api.clientApi.storiesOf(kind, m) as ReturnType).addParameters({ diff --git a/code/frameworks/angular/src/client/public-types.ts b/code/frameworks/angular/src/client/public-types.ts index da446898d293..c4a54cf25898 100644 --- a/code/frameworks/angular/src/client/public-types.ts +++ b/code/frameworks/angular/src/client/public-types.ts @@ -1,28 +1,39 @@ -import { AnnotatedStoryFn, Args, ComponentAnnotations, StoryAnnotations } from '@storybook/types'; -import { AngularFramework } from './types'; +import { + AnnotatedStoryFn, + Args, + ComponentAnnotations, + DecoratorFunction, + LoaderFunction, + StoryAnnotations, + StoryContext as GenericStoryContext, + StrictArgs, +} from '@storybook/types'; +import { AngularRenderer } from './types'; -export type { Args, ArgTypes } from '@storybook/types'; +export type { Args, ArgTypes, Parameters, StrictArgs } from '@storybook/types'; +export type { Parameters as AngularParameters } from './types'; +export type { AngularRenderer }; /** * Metadata to configure the stories for a component. * * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export) */ -export type Meta = ComponentAnnotations; +export type Meta = ComponentAnnotations; /** * Story function that represents a CSFv2 component example. * * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports) */ -export type StoryFn = AnnotatedStoryFn; +export type StoryFn = AnnotatedStoryFn; /** * Story function that represents a CSFv3 component example. * * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports) */ -export type StoryObj = StoryAnnotations; +export type StoryObj = StoryAnnotations; /** * @deprecated Use `StoryFn` instead. @@ -34,3 +45,7 @@ export type StoryObj = StoryAnnotations; * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports) */ export type Story = StoryFn; + +export type Decorator = DecoratorFunction; +export type Loader = LoaderFunction; +export type StoryContext = GenericStoryContext; diff --git a/code/frameworks/angular/src/client/render.ts b/code/frameworks/angular/src/client/render.ts index 622fe0ed6e8f..f8d220d93c6f 100644 --- a/code/frameworks/angular/src/client/render.ts +++ b/code/frameworks/angular/src/client/render.ts @@ -1,13 +1,13 @@ import { Store_RenderContext, ArgsStoryFn } from '@storybook/types'; import { renderNgApp } from './angular/helpers'; -import { AngularFramework } from './types'; +import { AngularRenderer } from './types'; import { RendererFactory } from './angular-beta/RendererFactory'; export const rendererFactory = new RendererFactory(); -export const render: ArgsStoryFn = (props) => ({ props }); +export const render: ArgsStoryFn = (props) => ({ props }); export async function renderToCanvas( { @@ -16,7 +16,7 @@ export async function renderToCanvas( forceRemount, storyContext: { parameters, component }, id, - }: Store_RenderContext, + }: Store_RenderContext, element: HTMLElement ) { showMain(); diff --git a/code/frameworks/angular/src/client/types.ts b/code/frameworks/angular/src/client/types.ts index 36ebabc89edd..14f41557d5d5 100644 --- a/code/frameworks/angular/src/client/types.ts +++ b/code/frameworks/angular/src/client/types.ts @@ -1,7 +1,7 @@ import { Parameters as DefaultParameters, StoryContext as DefaultStoryContext, - WebFramework, + WebRenderer, } from '@storybook/types'; export interface NgModuleMetadata { @@ -27,7 +27,11 @@ export interface StoryFnAngularReturnType { userDefinedTemplate?: boolean; } -export interface AngularFramework extends WebFramework { +/** + * @deprecated Use `AngularRenderer` instead. + */ +export type AngularFramework = AngularRenderer; +export interface AngularRenderer extends WebRenderer { component: any; storyResult: StoryFnAngularReturnType; } @@ -38,4 +42,4 @@ export type Parameters = DefaultParameters & { bootstrapModuleOptions?: unknown; }; -export type StoryContext = DefaultStoryContext & { parameters: Parameters }; +export type StoryContext = DefaultStoryContext & { parameters: Parameters }; diff --git a/code/frameworks/angular/src/server/framework-preset-angular-cli.ts b/code/frameworks/angular/src/server/framework-preset-angular-cli.ts index 6342bb1118a6..fcc4a17aea81 100644 --- a/code/frameworks/angular/src/server/framework-preset-angular-cli.ts +++ b/code/frameworks/angular/src/server/framework-preset-angular-cli.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-shadow */ import webpack from 'webpack'; import { logger } from '@storybook/node-logger'; import { BuilderContext, Target, targetFromTargetString } from '@angular-devkit/architect'; diff --git a/code/frameworks/angular/template/cli/Button.stories.ts b/code/frameworks/angular/template/cli/Button.stories.ts index b7154d6c8714..6bcd3ee47389 100644 --- a/code/frameworks/angular/template/cli/Button.stories.ts +++ b/code/frameworks/angular/template/cli/Button.stories.ts @@ -1,20 +1,17 @@ import type { Meta, StoryObj } from '@storybook/angular'; import Button from './button.component'; -// More on how to set up stories at: https://storybook.js.org/docs/angular/writing-stories/introduction#default-export +// More on how to set up stories at: https://storybook.js.org/docs/7.0/angular/writing-stories/introduction const meta: Meta`, context: args, }), - // More on argTypes: https://storybook.js.org/docs/ember/api/argtypes argTypes: { label: { control: 'text' }, }, }; -// More on component templates: https://storybook.js.org/docs/ember/writing-stories/introduction#using-args +// More on writing stories with args: https://storybook.js.org/docs/7.0/ember/writing-stories/args export const Text = { args: { label: 'Button', diff --git a/code/frameworks/ember/tsconfig.json b/code/frameworks/ember/tsconfig.json index 5627221de68f..2cf6db4b14d3 100644 --- a/code/frameworks/ember/tsconfig.json +++ b/code/frameworks/ember/tsconfig.json @@ -4,6 +4,5 @@ "strict": true, "resolveJsonModule": true }, - "include": ["src/**/*", "package.json"], - "exclude": ["src/**/*.test.*"] + "include": ["src/**/*", "package.json"] } diff --git a/code/frameworks/html-webpack5/jest.config.js b/code/frameworks/html-webpack5/jest.config.js new file mode 100644 index 000000000000..343e4c7a7f32 --- /dev/null +++ b/code/frameworks/html-webpack5/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.node'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/frameworks/html-webpack5/package.json b/code/frameworks/html-webpack5/package.json index 5d2e4bd25c5a..dbb83c5852f1 100644 --- a/code/frameworks/html-webpack5/package.json +++ b/code/frameworks/html-webpack5/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/html-webpack5", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Storybook for HTML: View HTML snippets in isolation with Hot Reloading.", "keywords": [ "storybook" @@ -50,17 +50,17 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@storybook/builder-webpack5": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/html": "7.0.0-alpha.48", - "@storybook/preset-html-webpack": "7.0.0-alpha.48", - "@types/node": "^16.0.0", + "@storybook/builder-webpack5": "7.0.0-alpha.51", + "@storybook/core-common": "7.0.0-alpha.51", + "@storybook/html": "7.0.0-alpha.51", + "@storybook/preset-html-webpack": "7.0.0-alpha.51", + "@types/node": "^16.0.0 || ^18.0.0", "global": "^4.4.0", "react": "16.14.0", "react-dom": "16.14.0" }, "devDependencies": { - "typescript": "~4.6.3" + "typescript": "^4.9.3" }, "peerDependencies": { "@babel/core": "*" @@ -78,5 +78,5 @@ ], "platform": "node" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd" + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded" } diff --git a/code/frameworks/html-webpack5/tsconfig.json b/code/frameworks/html-webpack5/tsconfig.json index d9463d503988..a4429176e35f 100644 --- a/code/frameworks/html-webpack5/tsconfig.json +++ b/code/frameworks/html-webpack5/tsconfig.json @@ -3,6 +3,5 @@ "compilerOptions": { "strict": true }, - "include": ["src/**/*"], - "exclude": ["src/**/*.test.*", "src/__tests__/**/*"] + "include": ["src/**/*"] } diff --git a/code/frameworks/nextjs/jest.config.js b/code/frameworks/nextjs/jest.config.js new file mode 100644 index 000000000000..343e4c7a7f32 --- /dev/null +++ b/code/frameworks/nextjs/jest.config.js @@ -0,0 +1,7 @@ +const path = require('path'); +const baseConfig = require('../../jest.config.node'); + +module.exports = { + ...baseConfig, + displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep), +}; diff --git a/code/frameworks/nextjs/package.json b/code/frameworks/nextjs/package.json index 80e845870e81..ca855ed8e16f 100644 --- a/code/frameworks/nextjs/package.json +++ b/code/frameworks/nextjs/package.json @@ -1,6 +1,6 @@ { "name": "@storybook/nextjs", - "version": "7.0.0-alpha.48", + "version": "7.0.0-alpha.51", "description": "Storybook for Next.js", "keywords": [ "storybook", @@ -59,14 +59,13 @@ "prep": "../../../scripts/prepare/bundle.ts" }, "dependencies": { - "@babel/preset-typescript": "^7.18.6", - "@storybook/addons": "7.0.0-alpha.48", - "@storybook/builder-webpack5": "7.0.0-alpha.48", - "@storybook/core-common": "7.0.0-alpha.48", - "@storybook/node-logger": "7.0.0-alpha.48", - "@storybook/preset-react-webpack": "7.0.0-alpha.48", - "@storybook/react": "7.0.0-alpha.48", - "@types/node": "^14.14.20 || ^16.0.0", + "@storybook/addons": "7.0.0-alpha.51", + "@storybook/builder-webpack5": "7.0.0-alpha.51", + "@storybook/core-common": "7.0.0-alpha.51", + "@storybook/node-logger": "7.0.0-alpha.51", + "@storybook/preset-react-webpack": "7.0.0-alpha.51", + "@storybook/react": "7.0.0-alpha.51", + "@types/node": "^16.0.0 || ^18.0.0", "find-up": "^5.0.0", "fs-extra": "^9.0.1", "image-size": "^1.0.0", @@ -81,10 +80,9 @@ "tsconfig-paths-webpack-plugin": "^3.5.2" }, "devDependencies": { - "@storybook/addon-actions": "7.0.0-alpha.48", - "@types/loader-utils": "^2.0.3", + "@storybook/addon-actions": "7.0.0-alpha.51", "next": "^12.2.4", - "typescript": "~4.6.3", + "typescript": "^4.9.3", "webpack": "^5.65.0" }, "peerDependencies": { @@ -121,5 +119,5 @@ ], "platform": "node" }, - "gitHead": "b58a29b785462f8a8b711b6bb2d7223fd6dc17fd" + "gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded" } diff --git a/code/frameworks/nextjs/src/config/babel.ts b/code/frameworks/nextjs/src/config/babel.ts deleted file mode 100644 index cceba0dc534d..000000000000 --- a/code/frameworks/nextjs/src/config/babel.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { TransformOptions } from '@babel/core'; -import { loadConfig } from 'tsconfig-paths'; - -export const configureTypescript = async (baseConfig: TransformOptions) => { - const configLoadResult = loadConfig(); - - // if tsconfig is successfully loaded, this is a typescript project - if (configLoadResult.resultType === 'success') { - baseConfig.presets ||= []; - - if (!baseConfig.presets.includes('@babel/preset-typescript')) { - baseConfig.presets.push('@babel/preset-typescript'); - } - } -}; diff --git a/code/frameworks/nextjs/src/config/webpack.ts b/code/frameworks/nextjs/src/config/webpack.ts index 2bd4ba751691..924b9311795c 100644 --- a/code/frameworks/nextjs/src/config/webpack.ts +++ b/code/frameworks/nextjs/src/config/webpack.ts @@ -5,6 +5,7 @@ import { pathExists } from 'fs-extra'; import type { NextConfig } from 'next'; import dedent from 'ts-dedent'; import { DefinePlugin } from 'webpack'; +import { pathToFileURL } from 'node:url'; import { addScopedAlias } from '../utils'; export const configureConfig = async ({ @@ -60,7 +61,7 @@ const resolveNextConfig = async ({ ); } - const nextConfigExport = await import(nextConfigFile); + const nextConfigExport = await import(pathToFileURL(nextConfigFile).href); const nextConfig = typeof nextConfigExport === 'function' diff --git a/code/frameworks/nextjs/src/next-image-loader-stub.ts b/code/frameworks/nextjs/src/next-image-loader-stub.ts index bf913e5e85cc..b506cba14e27 100644 --- a/code/frameworks/nextjs/src/next-image-loader-stub.ts +++ b/code/frameworks/nextjs/src/next-image-loader-stub.ts @@ -1,3 +1,4 @@ +// @ts-expect-error (loader-utils has no webpack5 compatible types) import { interpolateName } from 'loader-utils'; import imageSizeOf from 'image-size'; import type { RawLoaderDefinition } from 'webpack'; @@ -15,7 +16,7 @@ const nextImageLoaderStub: RawLoaderDefinition = function (conten this.emitFile(outputPath, content); - const { width, height } = imageSizeOf(content); + const { width, height } = imageSizeOf(this.resourcePath); return `export default ${JSON.stringify({ src: outputPath, @@ -27,4 +28,4 @@ const nextImageLoaderStub: RawLoaderDefinition = function (conten nextImageLoaderStub.raw = true; -export = nextImageLoaderStub; +export default nextImageLoaderStub; diff --git a/code/frameworks/nextjs/src/preset.ts b/code/frameworks/nextjs/src/preset.ts index 2833d9c5752f..5a688210c58f 100644 --- a/code/frameworks/nextjs/src/preset.ts +++ b/code/frameworks/nextjs/src/preset.ts @@ -1,17 +1,17 @@ // https://storybook.js.org/docs/react/addons/writing-presets import { dirname, join } from 'path'; import type { Options, PresetProperty } from '@storybook/types'; -import type { TransformOptions } from '@babel/core'; +import type { ConfigItem, TransformOptions } from '@babel/core'; +import { loadPartialConfig } from '@babel/core'; +import { getProjectRoot } from '@storybook/core-common'; import { configureConfig } from './config/webpack'; import { configureCss } from './css/webpack'; import { configureImports } from './imports/webpack'; import { configureRouting } from './routing/webpack'; import { configureStyledJsx } from './styledJsx/webpack'; -import { configureStyledJsxTransforms } from './styledJsx/babel'; import { configureImages } from './images/webpack'; import { configureRuntimeNextjsVersionResolution } from './utils'; import type { FrameworkOptions, StorybookConfig } from './types'; -import { configureTypescript } from './config/babel'; export const addons: PresetProperty<'addons', StorybookConfig> = [ dirname(require.resolve(join('@storybook/preset-react-webpack', 'package.json'))), @@ -72,10 +72,42 @@ export const config: StorybookConfig['previewAnnotations'] = (entry = []) => [ // You're using a version of Nextjs prior to v10, which is unsupported by this framework. export const babel = async (baseConfig: TransformOptions): Promise => { - configureTypescript(baseConfig); - configureStyledJsxTransforms(baseConfig); + const configPartial = loadPartialConfig({ + ...baseConfig, + filename: `${getProjectRoot()}/__fake__.js`, + }); - return baseConfig; + const options = configPartial?.options; + + const isPresetConfigItem = (preset: any): preset is ConfigItem => { + return typeof preset === 'object' && preset !== null && 'file' in preset; + }; + + const hasNextBabelConfig = options?.presets?.find( + (preset) => + (Array.isArray(preset) && preset[0] === 'next/babel') || + preset === 'next/babel' || + (isPresetConfigItem(preset) && preset.file?.request === 'next/babel') + ); + + if (!hasNextBabelConfig) { + options?.presets?.push('next/babel'); + } + + const presets = options?.presets?.filter( + (preset) => + !( + isPresetConfigItem(preset) && + (preset as ConfigItem).file?.request === require.resolve('@babel/preset-react') + ) + ); + + return { + ...options, + presets, + babelrc: false, + configFile: false, + }; }; export const webpackFinal: StorybookConfig['webpackFinal'] = async (baseConfig, options) => { diff --git a/code/frameworks/nextjs/src/styledJsx/babel.ts b/code/frameworks/nextjs/src/styledJsx/babel.ts deleted file mode 100644 index fe90611129d5..000000000000 --- a/code/frameworks/nextjs/src/styledJsx/babel.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { TransformOptions } from '@babel/core'; - -export const configureStyledJsxTransforms = async (baseConfig: TransformOptions) => { - baseConfig.plugins ||= []; - - if (!baseConfig.plugins.includes('styled-jsx/babel')) { - baseConfig.plugins.push('styled-jsx/babel'); - } -}; diff --git a/code/frameworks/nextjs/template/cli/js/Button.stories.js b/code/frameworks/nextjs/template/cli/js/Button.stories.js new file mode 100644 index 000000000000..d9d3e1b70574 --- /dev/null +++ b/code/frameworks/nextjs/template/cli/js/Button.stories.js @@ -0,0 +1,41 @@ +import { Button } from './Button'; + +// More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction +export default { + title: 'Example/Button', + component: Button, + tags: ['docsPage'], + argTypes: { + backgroundColor: { + control: 'color', + }, + }, +}; + +// More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args +export const Primary = { + args: { + primary: true, + label: 'Button', + }, +}; + +export const Secondary = { + args: { + label: 'Button', + }, +}; + +export const Large = { + args: { + size: 'large', + label: 'Button', + }, +}; + +export const Small = { + args: { + size: 'small', + label: 'Button', + }, +}; diff --git a/code/frameworks/nextjs/template/cli/js/Button.stories.jsx b/code/frameworks/nextjs/template/cli/js/Button.stories.jsx deleted file mode 100644 index bfabf81396b9..000000000000 --- a/code/frameworks/nextjs/template/cli/js/Button.stories.jsx +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react'; - -import { Button } from './Button'; - -// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export -export default { - title: 'Example/Button', - component: Button, - // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/react/writing-docs/docs-page - tags: ['docsPage'], - // More on argTypes: https://storybook.js.org/docs/react/api/argtypes - argTypes: { - backgroundColor: { control: 'color' }, - }, -}; - -// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args -const Template = (args) => ; export const WithToolbar = () => ( - + ); -const Horizontal = styled((props) => )({ +const Horizontal = styled((props: ComponentProps) => )({ display: 'grid', gridTemplateColumns: '100px calc(100vw + 100px) 100px', }); @@ -108,14 +109,15 @@ export const Wide = () => ( export const WithToolbarMulti = () => ( - - + + ); export const WithFullscreenSingle = () => ( ( export const WithFullscreenMulti = () => ( ( }} /> ( export const WithCenteredSingle = () => ( ( export const WithCenteredMulti = () => ( ( }} /> ; @@ -26,3 +36,45 @@ export const Undefined: StoryObj = { value: undefined, }, }; + +export const Toggling: StoryObj = { + args: { + value: undefined, + }, + play: async ({ canvasElement, id }) => { + const channel = addons.getChannel(); + + channel.emit(RESET_STORY_ARGS, { storyId: id }); + await new Promise((resolve) => { + channel.once(STORY_ARGS_UPDATED, resolve); + }); + + const canvas = within(canvasElement); + + // from Undefined to False + const setBooleanControl = canvas.getByText('Set boolean'); + await fireEvent.click(setBooleanControl); + + let toggle = await canvas.findByTitle('Change to true'); + expect(toggle).toBeInTheDocument(); + + // from False to True + await fireEvent.click(toggle); + toggle = await canvas.findByTitle('Change to false'); + expect(toggle).toBeInTheDocument(); + + // from True to False + await fireEvent.click(toggle); + toggle = await canvas.findByTitle('Change to true'); + expect(toggle).toBeInTheDocument(); + }, +}; + +export const TogglingInDocs: StoryObj = { + ...Toggling, + parameters: { + docs: { + autoplay: true, + }, + }, +}; diff --git a/code/ui/blocks/src/controls/Boolean.tsx b/code/ui/blocks/src/controls/Boolean.tsx index 8abec1e34902..556701febca0 100644 --- a/code/ui/blocks/src/controls/Boolean.tsx +++ b/code/ui/blocks/src/controls/Boolean.tsx @@ -86,6 +86,11 @@ const Label = styled.label(({ theme }) => ({ const parse = (value: string | null): boolean => value === 'true'; export type BooleanProps = ControlProps & BooleanConfig; +/** + * # Boolean control + * Renders a switch toggle with "True" or "False". + * or if the value is `undefined`, renders a button to set the boolean. + */ export const BooleanControl: FC = ({ name, value, onChange, onBlur, onFocus }) => { const onSetFalse = useCallback(() => onChange(false), [onChange]); if (value === undefined) { @@ -95,13 +100,14 @@ export const BooleanControl: FC = ({ name, value, onChange, onBlur ); } + const controlId = getControlId(name); const parsedValue = typeof value === 'string' ? parse(value) : value; return ( -