@eldrajs/theme-cli 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/README.md +26 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +203 -0
- package/dist/index.d.ts +174 -0
- package/dist/index.js +3 -0
- package/dist/validate-DprFpjV7.js +535 -0
- package/package.json +50 -2
- package/template/.eldra/block-types.d.ts +429 -0
- package/template/.eldra/manifest.json +9378 -0
- package/template/.eldra/previews.json +36 -0
- package/template/.github/workflows/eldra-deploy.yml +24 -0
- package/template/.gitlab-ci.yml +16 -0
- package/template/.storybook/eldra.ts +123 -0
- package/template/.storybook/i18n.ts +23 -0
- package/template/.storybook/main.ts +59 -0
- package/template/.storybook/nuxt-link-stub.ts +23 -0
- package/template/.storybook/preview.ts +53 -0
- package/template/.storybook/shims-vue.d.ts +10 -0
- package/template/.storybook/virtual-eldra.d.ts +32 -0
- package/template/README.md +293 -0
- package/template/app/app.vue +126 -0
- package/template/app/assets/main.css +404 -0
- package/template/app/components/EldraIcon.vue +66 -0
- package/template/app/components/EldraRouterLink.vue +62 -0
- package/template/app/components/ui/UiImage.stories.ts +30 -0
- package/template/app/components/ui/UiImage.vue +224 -0
- package/template/app/components/ui/__tests__/UiImage.spec.ts +292 -0
- package/template/app/composables/iconComponent.ts +84 -0
- package/template/app/composables/iconFetcher.ts +14 -0
- package/template/app/composables/useBlockData.ts +30 -0
- package/template/app/composables/useEditing.ts +31 -0
- package/template/app/composables/useEldraIcon.ts +46 -0
- package/template/app/composables/useRevalidating.ts +69 -0
- package/template/app/composables/useRichTextScrollRegions.ts +80 -0
- package/template/app/composables/useStorefront.ts +18 -0
- package/template/app/composables/useStorefrontFeedback.ts +49 -0
- package/template/app/composables/useUiId.ts +18 -0
- package/template/app/composables/useWishlist.ts +42 -0
- package/template/app/i18n.d.ts +28 -0
- package/template/app/icons.ts +185 -0
- package/template/app/pages/[...slug].vue +134 -0
- package/template/app/plugins/eldra-i18n.ts +98 -0
- package/template/app/plugins/eldra-storefront.ts +288 -0
- package/template/app/plugins/eldra-ui-messages.ts +112 -0
- package/template/app/storefront/cart.ts +245 -0
- package/template/app/storefront/categories.ts +283 -0
- package/template/app/storefront/collectionSelector.ts +60 -0
- package/template/app/storefront/commerce.ts +58 -0
- package/template/app/storefront/demo.ts +1313 -0
- package/template/app/storefront/facets.ts +476 -0
- package/template/app/storefront/feedback.ts +122 -0
- package/template/app/storefront/gateway.ts +2256 -0
- package/template/app/storefront/history.ts +233 -0
- package/template/app/storefront/money.ts +248 -0
- package/template/app/storefront/options.ts +71 -0
- package/template/app/storefront/prerender.ts +77 -0
- package/template/app/storefront/refresh.ts +222 -0
- package/template/app/storefront/toProductCard.ts +154 -0
- package/template/app/storefront/types.ts +815 -0
- package/template/app/storefront/volatile.ts +211 -0
- package/template/app/templates.ts +544 -0
- package/template/app/utils/classes.ts +40 -0
- package/template/app/utils/links.ts +70 -0
- package/template/app/utils/pageStructure.ts +77 -0
- package/template/app/utils/pageTitle.ts +37 -0
- package/template/app/virtual-eldra.d.ts +12 -0
- package/template/bitbucket-pipelines.yml +19 -0
- package/template/blocks/announcement-bar/Block.vue +203 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +227 -0
- package/template/blocks/announcement-bar/block.json +45 -0
- package/template/blocks/announcement-bar/mock.json +7 -0
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +317 -0
- package/template/blocks/article/__tests__/Block.spec.ts +229 -0
- package/template/blocks/article/block.json +148 -0
- package/template/blocks/article/mock.json +512 -0
- package/template/blocks/article/preview.json +16 -0
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +343 -0
- package/template/blocks/article-list/__tests__/Block.spec.ts +279 -0
- package/template/blocks/article-list/block.json +181 -0
- package/template/blocks/article-list/mock.json +68 -0
- package/template/blocks/article-list/preview.json +84 -0
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +278 -0
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +461 -0
- package/template/blocks/breadcrumbs/block.json +89 -0
- package/template/blocks/breadcrumbs/mock.json +11 -0
- package/template/blocks/breadcrumbs/preview.json +3 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +372 -0
- package/template/blocks/cart/__tests__/Block.spec.ts +561 -0
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +78 -0
- package/template/blocks/cart/__tests__/Summary.spec.ts +245 -0
- package/template/blocks/cart/block.json +74 -0
- package/template/blocks/cart/mock.json +11 -0
- package/template/blocks/cart/parts/CartLines.vue +257 -0
- package/template/blocks/cart/parts/ShippingBar.vue +105 -0
- package/template/blocks/cart/parts/Summary.vue +291 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +1832 -0
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +3037 -0
- package/template/blocks/collection-grid/__tests__/groups.spec.ts +731 -0
- package/template/blocks/collection-grid/block.json +187 -0
- package/template/blocks/collection-grid/mock.json +23 -0
- package/template/blocks/collection-grid/parts/groups.ts +861 -0
- package/template/blocks/collection-grid/preview.json +7 -0
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +533 -0
- package/template/blocks/collection-header/__tests__/Block.spec.ts +381 -0
- package/template/blocks/collection-header/block.json +140 -0
- package/template/blocks/collection-header/mock.json +28 -0
- package/template/blocks/collection-header/preview.json +14 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/Block.vue +621 -0
- package/template/blocks/contact/__tests__/Block.spec.ts +347 -0
- package/template/blocks/contact/block.json +174 -0
- package/template/blocks/contact/mock.json +28 -0
- package/template/blocks/contact/preview.json +9 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/Block.vue +383 -0
- package/template/blocks/cta/__tests__/Block.spec.ts +309 -0
- package/template/blocks/cta/block.json +86 -0
- package/template/blocks/cta/mock.json +10 -0
- package/template/blocks/cta/preview.json +9 -0
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/Block.vue +254 -0
- package/template/blocks/faq/__tests__/Block.spec.ts +312 -0
- package/template/blocks/faq/block.json +113 -0
- package/template/blocks/faq/mock.json +115 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +241 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +311 -0
- package/template/blocks/feature-grid/block.json +106 -0
- package/template/blocks/feature-grid/mock.json +29 -0
- package/template/blocks/feature-grid/preview.json +45 -0
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +652 -0
- package/template/blocks/footer/__tests__/Block.spec.ts +700 -0
- package/template/blocks/footer/block.json +240 -0
- package/template/blocks/footer/mock.json +161 -0
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/gallery/Block.vue +416 -0
- package/template/blocks/gallery/__tests__/Block.spec.ts +289 -0
- package/template/blocks/gallery/block.json +87 -0
- package/template/blocks/gallery/mock.json +16 -0
- package/template/blocks/gallery/preview.json +64 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +378 -0
- package/template/blocks/hero/__tests__/Block.spec.ts +324 -0
- package/template/blocks/hero/block.json +146 -0
- package/template/blocks/hero/mock.json +11 -0
- package/template/blocks/hero/preview.json +55 -0
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/Block.vue +232 -0
- package/template/blocks/image/__tests__/Block.spec.ts +224 -0
- package/template/blocks/image/block.json +67 -0
- package/template/blocks/image/mock.json +7 -0
- package/template/blocks/image/preview.json +9 -0
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/Block.vue +206 -0
- package/template/blocks/logo-cloud/__tests__/Block.spec.ts +210 -0
- package/template/blocks/logo-cloud/block.json +79 -0
- package/template/blocks/logo-cloud/mock.json +15 -0
- package/template/blocks/logo-cloud/preview.json +92 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +1348 -0
- package/template/blocks/navigation/__tests__/Block.spec.ts +2030 -0
- package/template/blocks/navigation/block.json +167 -0
- package/template/blocks/navigation/mock.json +191 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/navigation/useMegaMenuKeys.ts +276 -0
- package/template/blocks/newsletter/Block.vue +399 -0
- package/template/blocks/newsletter/__tests__/Block.spec.ts +365 -0
- package/template/blocks/newsletter/block.json +105 -0
- package/template/blocks/newsletter/mock.json +31 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +754 -0
- package/template/blocks/order-status/__tests__/Block.spec.ts +515 -0
- package/template/blocks/order-status/block.json +138 -0
- package/template/blocks/order-status/mock.json +19 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/Block.vue +297 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +357 -0
- package/template/blocks/pricing-table/block.json +155 -0
- package/template/blocks/pricing-table/mock.json +47 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +459 -0
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +957 -0
- package/template/blocks/product-carousel/block.json +71 -0
- package/template/blocks/product-carousel/mock.json +9 -0
- package/template/blocks/product-carousel/preview.json +7 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +886 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +1492 -0
- package/template/blocks/product-detail/__tests__/stock.spec.ts +119 -0
- package/template/blocks/product-detail/block.json +155 -0
- package/template/blocks/product-detail/mock.json +113 -0
- package/template/blocks/product-detail/parts/Gallery.vue +181 -0
- package/template/blocks/product-detail/parts/StickyBuyBar.vue +99 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/stock.ts +150 -0
- package/template/blocks/quote/Block.vue +206 -0
- package/template/blocks/quote/__tests__/Block.spec.ts +265 -0
- package/template/blocks/quote/block.json +76 -0
- package/template/blocks/quote/mock.json +9 -0
- package/template/blocks/quote/preview.json +16 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/Block.vue +143 -0
- package/template/blocks/rich-text/__tests__/Block.spec.ts +191 -0
- package/template/blocks/rich-text/block.json +57 -0
- package/template/blocks/rich-text/mock.json +87 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +589 -0
- package/template/blocks/search/PopularChips.vue +40 -0
- package/template/blocks/search/TypeSection.vue +148 -0
- package/template/blocks/search/__tests__/Block.spec.ts +718 -0
- package/template/blocks/search/__tests__/results.spec.ts +166 -0
- package/template/blocks/search/block.json +102 -0
- package/template/blocks/search/mock.json +18 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/search/results.ts +85 -0
- package/template/blocks/split-content/Block.vue +195 -0
- package/template/blocks/split-content/__tests__/Block.spec.ts +225 -0
- package/template/blocks/split-content/block.json +70 -0
- package/template/blocks/split-content/mock.json +45 -0
- package/template/blocks/split-content/preview.json +58 -0
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/Block.vue +159 -0
- package/template/blocks/stats/__tests__/Block.spec.ts +194 -0
- package/template/blocks/stats/block.json +73 -0
- package/template/blocks/stats/mock.json +12 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +278 -0
- package/template/blocks/tabs/__tests__/Block.spec.ts +303 -0
- package/template/blocks/tabs/block.json +97 -0
- package/template/blocks/tabs/mock.json +129 -0
- package/template/blocks/tabs/preview.json +153 -0
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/Block.vue +288 -0
- package/template/blocks/team/__tests__/Block.spec.ts +221 -0
- package/template/blocks/team/block.json +125 -0
- package/template/blocks/team/mock.json +39 -0
- package/template/blocks/team/preview.json +62 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/Block.vue +408 -0
- package/template/blocks/testimonials/__tests__/Block.spec.ts +319 -0
- package/template/blocks/testimonials/block.json +121 -0
- package/template/blocks/testimonials/mock.json +46 -0
- package/template/blocks/testimonials/preview.json +68 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/Block.vue +274 -0
- package/template/blocks/timeline/__tests__/Block.spec.ts +310 -0
- package/template/blocks/timeline/block.json +98 -0
- package/template/blocks/timeline/mock.json +27 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +330 -0
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +290 -0
- package/template/blocks/trust-strip/block.json +117 -0
- package/template/blocks/trust-strip/mock.json +37 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/Block.vue +354 -0
- package/template/blocks/video-embed/__tests__/Block.spec.ts +219 -0
- package/template/blocks/video-embed/__tests__/embed.spec.ts +76 -0
- package/template/blocks/video-embed/block.json +94 -0
- package/template/blocks/video-embed/embed.ts +84 -0
- package/template/blocks/video-embed/mock.json +13 -0
- package/template/blocks/video-embed/preview.json +9 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +367 -0
- package/template/blocks/wishlist/__tests__/Block.spec.ts +508 -0
- package/template/blocks/wishlist/block.json +42 -0
- package/template/blocks/wishlist/mock.json +9 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +602 -0
- package/template/i18n/is-IS.json +602 -0
- package/template/nuxt.config.ts +156 -0
- package/template/package.json +56 -0
- package/template/pages/article.page.json +731 -0
- package/template/pages/cart.page.json +85 -0
- package/template/pages/category.page.json +133 -0
- package/template/pages/collection.page.json +194 -0
- package/template/pages/home.page.json +353 -0
- package/template/pages/product.page.json +323 -0
- package/template/pages/products.page.json +144 -0
- package/template/pages/search.page.json +83 -0
- package/template/pages/wishlist.page.json +88 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/demo/article-cover.svg +1 -0
- package/template/public/demo/article-figure.svg +1 -0
- package/template/public/demo/avatar-1.svg +3 -0
- package/template/public/demo/avatar-2.svg +3 -0
- package/template/public/demo/avatar-3.svg +3 -0
- package/template/public/demo/avatar-4.svg +3 -0
- package/template/public/demo/avatar-5.svg +3 -0
- package/template/public/demo/avatar-6.svg +3 -0
- package/template/public/demo/avatar-7.svg +3 -0
- package/template/public/demo/avatar-8.svg +3 -0
- package/template/public/demo/collection-1.svg +1 -0
- package/template/public/demo/collection-2.svg +1 -0
- package/template/public/demo/cta-split.svg +1 -0
- package/template/public/demo/feature-1.svg +1 -0
- package/template/public/demo/feature-2.svg +1 -0
- package/template/public/demo/feature-3.svg +1 -0
- package/template/public/demo/feature-4.svg +1 -0
- package/template/public/demo/gallery-1.svg +1 -0
- package/template/public/demo/gallery-2.svg +1 -0
- package/template/public/demo/gallery-3.svg +1 -0
- package/template/public/demo/gallery-4.svg +1 -0
- package/template/public/demo/gallery-5.svg +1 -0
- package/template/public/demo/gallery-6.svg +1 -0
- package/template/public/demo/gallery-7.svg +1 -0
- package/template/public/demo/gallery-8.svg +1 -0
- package/template/public/demo/hero-slide-1.svg +1 -0
- package/template/public/demo/hero-slide-2.svg +1 -0
- package/template/public/demo/hero-slide-3.svg +1 -0
- package/template/public/demo/hero-slide-4.svg +1 -0
- package/template/public/demo/hero-wide.svg +1 -0
- package/template/public/demo/hero.svg +1 -0
- package/template/public/demo/logo-1.svg +4 -0
- package/template/public/demo/logo-2.svg +4 -0
- package/template/public/demo/logo-3.svg +4 -0
- package/template/public/demo/logo-4.svg +4 -0
- package/template/public/demo/logo-5.svg +4 -0
- package/template/public/demo/logo-6.svg +4 -0
- package/template/public/demo/logo-7.svg +4 -0
- package/template/public/demo/logo-8.svg +4 -0
- package/template/public/demo/logo.svg +3 -0
- package/template/public/demo/map.svg +1 -0
- package/template/public/demo/poster.svg +1 -0
- package/template/public/demo/product-1.svg +4 -0
- package/template/public/demo/product-10.svg +4 -0
- package/template/public/demo/product-11.svg +4 -0
- package/template/public/demo/product-12.svg +4 -0
- package/template/public/demo/product-2.svg +4 -0
- package/template/public/demo/product-3.svg +4 -0
- package/template/public/demo/product-4.svg +4 -0
- package/template/public/demo/product-5.svg +4 -0
- package/template/public/demo/product-6.svg +4 -0
- package/template/public/demo/product-7.svg +4 -0
- package/template/public/demo/product-8.svg +4 -0
- package/template/public/demo/product-9.svg +4 -0
- package/template/public/demo/product-square-1.svg +4 -0
- package/template/public/demo/product-square-2.svg +4 -0
- package/template/public/demo/product-square-3.svg +4 -0
- package/template/public/demo/product-square-4.svg +4 -0
- package/template/public/demo/product-square-5.svg +4 -0
- package/template/public/demo/product-square-6.svg +4 -0
- package/template/public/demo/quote-portrait.svg +4 -0
- package/template/public/demo/split-1.svg +1 -0
- package/template/public/demo/split-2.svg +1 -0
- package/template/public/demo/split-3.svg +1 -0
- package/template/public/demo/split-4.svg +1 -0
- package/template/public/demo/team-1.svg +4 -0
- package/template/public/demo/team-2.svg +4 -0
- package/template/public/demo/team-3.svg +4 -0
- package/template/public/demo/team-4.svg +4 -0
- package/template/public/favicon.ico +0 -0
- package/template/scripts/demo-images.mjs +393 -0
- package/template/scripts/generate-stories.mjs +156 -0
- package/template/scripts/previewHash.mjs +125 -0
- package/template/scripts/previews.mjs +149 -0
- package/template/stories/generated/announcement-bar.stories.ts +44 -0
- package/template/stories/generated/article-list.stories.ts +87 -0
- package/template/stories/generated/article.stories.ts +27 -0
- package/template/stories/generated/breadcrumbs.stories.ts +39 -0
- package/template/stories/generated/cart.stories.ts +38 -0
- package/template/stories/generated/collection-grid.stories.ts +117 -0
- package/template/stories/generated/collection-header.stories.ts +51 -0
- package/template/stories/generated/contact.stories.ts +45 -0
- package/template/stories/generated/cta.stories.ts +51 -0
- package/template/stories/generated/faq.stories.ts +56 -0
- package/template/stories/generated/feature-grid.stories.ts +69 -0
- package/template/stories/generated/footer.stories.ts +50 -0
- package/template/stories/generated/gallery.stories.ts +81 -0
- package/template/stories/generated/hero.stories.ts +75 -0
- package/template/stories/generated/image.stories.ts +99 -0
- package/template/stories/generated/logo-cloud.stories.ts +57 -0
- package/template/stories/generated/navigation.stories.ts +62 -0
- package/template/stories/generated/newsletter.stories.ts +68 -0
- package/template/stories/generated/order-status.stories.ts +32 -0
- package/template/stories/generated/pricing-table.stories.ts +44 -0
- package/template/stories/generated/product-carousel.stories.ts +75 -0
- package/template/stories/generated/product-detail.stories.ts +62 -0
- package/template/stories/generated/quote.stories.ts +69 -0
- package/template/stories/generated/rich-text.stories.ts +50 -0
- package/template/stories/generated/search.stories.ts +56 -0
- package/template/stories/generated/split-content.stories.ts +39 -0
- package/template/stories/generated/stats.stories.ts +68 -0
- package/template/stories/generated/tabs.stories.ts +45 -0
- package/template/stories/generated/team.stories.ts +45 -0
- package/template/stories/generated/testimonials.stories.ts +69 -0
- package/template/stories/generated/timeline.stories.ts +80 -0
- package/template/stories/generated/trust-strip.stories.ts +62 -0
- package/template/stories/generated/video-embed.stories.ts +63 -0
- package/template/stories/generated/wishlist.stories.ts +26 -0
- package/template/stories/pages/article.stories.ts +51 -0
- package/template/stories/pages/cart.stories.ts +56 -0
- package/template/stories/pages/category.stories.ts +56 -0
- package/template/stories/pages/collection.stories.ts +51 -0
- package/template/stories/pages/home.stories.ts +51 -0
- package/template/stories/pages/product.stories.ts +47 -0
- package/template/stories/pages/products.stories.ts +58 -0
- package/template/stories/pages/search.stories.ts +54 -0
- package/template/stories/pages/wishlist.stories.ts +53 -0
- package/template/stories/support/pageBlocks.ts +115 -0
- package/template/test/blocksEmptyData.spec.ts +52 -0
- package/template/test/carouselKeyboard.spec.ts +272 -0
- package/template/test/carouselRing.browser.spec.ts +193 -0
- package/template/test/carouselSlideWidth.browser.spec.ts +102 -0
- package/template/test/cartDrawer.spec.ts +295 -0
- package/template/test/cartToast.spec.ts +86 -0
- package/template/test/countPill.browser.spec.ts +196 -0
- package/template/test/demoImages.spec.ts +140 -0
- package/template/test/deps.spec.ts +102 -0
- package/template/test/eldraIcon.spec.ts +58 -0
- package/template/test/framing.spec.ts +76 -0
- package/template/test/i18n.spec.ts +200 -0
- package/template/test/iconComponent.spec.ts +91 -0
- package/template/test/inlineEditable.spec.ts +335 -0
- package/template/test/localePrefix.spec.ts +342 -0
- package/template/test/mainCss.spec.ts +107 -0
- package/template/test/mockGatewayContract.spec.ts +122 -0
- package/template/test/mocks/blocks.ts +20 -0
- package/template/test/mocks/breakpoints.ts +7 -0
- package/template/test/mocks/manifest.ts +11 -0
- package/template/test/moneyFormatting.spec.ts +85 -0
- package/template/test/pageTitle.spec.ts +49 -0
- package/template/test/pages/article.spec.ts +231 -0
- package/template/test/pages/category.spec.ts +185 -0
- package/template/test/pages/collection.spec.ts +396 -0
- package/template/test/pages/home.spec.ts +295 -0
- package/template/test/pages/hydration.spec.ts +557 -0
- package/template/test/pages/product.spec.ts +396 -0
- package/template/test/pages/seededPages.spec.ts +190 -0
- package/template/test/pages/ssr.spec.ts +387 -0
- package/template/test/prerenderCommerce.spec.ts +134 -0
- package/template/test/prerenderFailure.spec.ts +130 -0
- package/template/test/prerenderRefresh.browser.spec.ts +1431 -0
- package/template/test/previewsFresh.spec.ts +56 -0
- package/template/test/richText.spec.ts +164 -0
- package/template/test/richTextTypography.spec.ts +182 -0
- package/template/test/setup.ts +21 -0
- package/template/test/slugPage.spec.ts +244 -0
- package/template/test/slugPageTemplate.spec.ts +194 -0
- package/template/test/starter.spec.ts +1416 -0
- package/template/test/storefront/cart.spec.ts +404 -0
- package/template/test/storefront/categories.spec.ts +235 -0
- package/template/test/storefront/collectionSelector.spec.ts +74 -0
- package/template/test/storefront/demo.spec.ts +555 -0
- package/template/test/storefront/facets.spec.ts +425 -0
- package/template/test/storefront/feedback.spec.ts +97 -0
- package/template/test/storefront/gateway.spec.ts +2673 -0
- package/template/test/storefront/gatewayCart.spec.ts +289 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +1037 -0
- package/template/test/storefront/history.spec.ts +341 -0
- package/template/test/storefront/money.spec.ts +170 -0
- package/template/test/storefront/toProductCard.spec.ts +138 -0
- package/template/test/storefront/volatile.spec.ts +284 -0
- package/template/test/support/axe.ts +14 -0
- package/template/test/support/dialog.ts +51 -0
- package/template/test/support/hydrate.ts +118 -0
- package/template/test/support/i18nText.ts +11 -0
- package/template/test/support/mockGateway.ts +1017 -0
- package/template/test/support/mountBlock.ts +194 -0
- package/template/test/support/mountPage.spec.ts +72 -0
- package/template/test/support/mountPage.ts +254 -0
- package/template/test/support/mountProbe.client.ts +69 -0
- package/template/test/support/renderSsr.ts +97 -0
- package/template/test/support/staticServer.ts +96 -0
- package/template/test/themeIcons.spec.ts +140 -0
- package/template/test/toastAnnouncement.spec.ts +133 -0
- package/template/test/tokens.spec.ts +102 -0
- package/template/test/uiMessagesPlugin.spec.ts +104 -0
- package/template/test/useBlockData.spec.ts +49 -0
- package/template/test/useEditing.spec.ts +54 -0
- package/template/test/useEldraIcon.spec.ts +126 -0
- package/template/test/useUiId.spec.ts +40 -0
- package/template/tokens.json +149 -0
- package/template/tsconfig.json +3 -0
- package/template/tsconfig.storybook.json +17 -0
- package/template/vitest-axe.d.ts +13 -0
- package/template/vitest.config.ts +44 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
// This file deliberately carries no environment docblock: `vitest.config.ts` defaults to the node
|
|
2
|
+
// environment, so it is the one place in the suite where `window` and `document` do not exist —
|
|
3
|
+
// exactly the environment `nuxi generate` and every SSR request render a page in. Do not write the
|
|
4
|
+
// jsdom environment pragma anywhere in this file, not even inside a comment explaining its absence:
|
|
5
|
+
// Vitest scans the file's leading comments for that pragma and would switch the environment, which
|
|
6
|
+
// makes every assertion below vacuous (the first `it` guards against exactly that).
|
|
7
|
+
//
|
|
8
|
+
// Nothing else in the suite server-renders a block. `test/starter.spec.ts` does run `nuxi generate`,
|
|
9
|
+
// but without gateway credentials it only ever reaches the not-found shell, so no block is server
|
|
10
|
+
// rendered there either. That blind spot is how three `watchEffect`s in `blocks/navigation/Block.vue`
|
|
11
|
+
// could call `window.addEventListener` / `document.documentElement` unguarded with every gate green:
|
|
12
|
+
// a `flush: 'pre'` effect with no callback runs its body immediately, inside `setup()`, and `setup()`
|
|
13
|
+
// runs on the server too — so each server render raised `ReferenceError: window is not defined`,
|
|
14
|
+
// which `nitro.prerender.failOnError` turns into a failed build.
|
|
15
|
+
import { computed, defineComponent, h } from 'vue';
|
|
16
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
17
|
+
import Cart from '../../blocks/cart/Block.vue';
|
|
18
|
+
import Navigation from '../../blocks/navigation/Block.vue';
|
|
19
|
+
import navigationMock from '../../blocks/navigation/mock.json';
|
|
20
|
+
import ProductDetail from '../../blocks/product-detail/Block.vue';
|
|
21
|
+
import productDetailMock from '../../blocks/product-detail/mock.json';
|
|
22
|
+
import ProductCarousel from '../../blocks/product-carousel/Block.vue';
|
|
23
|
+
import productCarouselMock from '../../blocks/product-carousel/mock.json';
|
|
24
|
+
import Search from '../../blocks/search/Block.vue';
|
|
25
|
+
import searchMock from '../../blocks/search/mock.json';
|
|
26
|
+
import Wishlist from '../../blocks/wishlist/Block.vue';
|
|
27
|
+
import wishlistMock from '../../blocks/wishlist/mock.json';
|
|
28
|
+
import { CURRENCY_KEY, LOCALE_KEY } from '@eldrajs/ui';
|
|
29
|
+
import enUS from '../../i18n/en-US.json';
|
|
30
|
+
import { formatMoney } from '../../app/storefront/money';
|
|
31
|
+
import { STOREFRONT_KEY } from '../../app/storefront/types';
|
|
32
|
+
import { createDemoStorefront } from '../../app/storefront/demo';
|
|
33
|
+
import { renderBlockToString, renderPageToString, renderShellToString } from '../support/renderSsr';
|
|
34
|
+
import type { PageFixture } from '../support/mountPage';
|
|
35
|
+
import homePage from '../../pages/home.page.json';
|
|
36
|
+
import productPage from '../../pages/product.page.json';
|
|
37
|
+
import collectionPage from '../../pages/collection.page.json';
|
|
38
|
+
import articlePage from '../../pages/article.page.json';
|
|
39
|
+
import cartPage from '../../pages/cart.page.json';
|
|
40
|
+
import wishlistPage from '../../pages/wishlist.page.json';
|
|
41
|
+
import searchPage from '../../pages/search.page.json';
|
|
42
|
+
|
|
43
|
+
// `app/app.vue` reads `useRoute()` as a bare Nuxt auto-import (it is the shell: that is where closing
|
|
44
|
+
// the cart drawer on a route change belongs). A server render only ever calls it, never navigates.
|
|
45
|
+
vi.stubGlobal('useRoute', () => ({ fullPath: '/' }));
|
|
46
|
+
|
|
47
|
+
const FIXTURES: Array<[string, PageFixture]> = [
|
|
48
|
+
['home', homePage as unknown as PageFixture],
|
|
49
|
+
['product', productPage as unknown as PageFixture],
|
|
50
|
+
['collection', collectionPage as unknown as PageFixture],
|
|
51
|
+
['article', articlePage as unknown as PageFixture],
|
|
52
|
+
// The three seeded pages. They matter here more than the others: each of them is a page
|
|
53
|
+
// `nuxi generate` really does render on the server, where its code-route predecessor rendered
|
|
54
|
+
// no header and no footer at all.
|
|
55
|
+
['cart', cartPage as unknown as PageFixture],
|
|
56
|
+
['wishlist', wishlistPage as unknown as PageFixture],
|
|
57
|
+
['search', searchPage as unknown as PageFixture],
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
describe('server rendering', () => {
|
|
61
|
+
it('runs in an environment with no window and no document', () => {
|
|
62
|
+
// If this ever fails, every other assertion in this file is vacuous.
|
|
63
|
+
expect(typeof window).toBe('undefined');
|
|
64
|
+
expect(typeof document).toBe('undefined');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('server-renders the header block without touching window or document', async () => {
|
|
68
|
+
const html = await renderBlockToString(Navigation, {
|
|
69
|
+
id: 'ssr-header',
|
|
70
|
+
data: navigationMock,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(html).toContain('<header');
|
|
74
|
+
expect(html).toContain('Primary navigation');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* One prerendered header is served to every visitor, so it cannot carry any one of them — but the
|
|
79
|
+
* heart is not any one of them. It is a way into `/wishlist`, the same for everybody, so it is in
|
|
80
|
+
* the file; what cannot be is the **count**, not even for a browser with a saved list, which is
|
|
81
|
+
* what the storage stub below stands in for. So the bag reads "Cart, empty", the heart reads
|
|
82
|
+
* "Wishlist" with no number, and the first client render has the same two names to agree about.
|
|
83
|
+
*/
|
|
84
|
+
it('server-renders the wishlist heart with no count, with a saved list already in storage', async () => {
|
|
85
|
+
const saved = new Map([
|
|
86
|
+
['eldra.storefront.wishlist', JSON.stringify(['merino-crew-sweater', 'speckled-latte-mug'])],
|
|
87
|
+
]);
|
|
88
|
+
// By hand rather than `vi.stubGlobal`, so `unstubAllGlobals` cannot take this file's
|
|
89
|
+
// module-level `useRoute` stub with it.
|
|
90
|
+
Object.defineProperty(globalThis, 'localStorage', {
|
|
91
|
+
configurable: true,
|
|
92
|
+
value: {
|
|
93
|
+
getItem: (key: string) => saved.get(key) ?? null,
|
|
94
|
+
setItem: () => {},
|
|
95
|
+
removeItem: () => {},
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
const html = await renderBlockToString(
|
|
100
|
+
Navigation,
|
|
101
|
+
{ id: 'ssr-header-wishlist', data: navigationMock },
|
|
102
|
+
{ [STOREFRONT_KEY]: createDemoStorefront() }
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(html).toContain(enUS.header.cartEmpty);
|
|
106
|
+
// The control and its destination are both in the file.
|
|
107
|
+
expect(html).toContain(`aria-label="${enUS.header.wishlistEmpty}"`);
|
|
108
|
+
expect(html).toContain('href="/wishlist"');
|
|
109
|
+
// The count is not, under either plural form, and no badge came with it. Two saved products
|
|
110
|
+
// are in storage while this renders, so these are the assertions the gate is worth.
|
|
111
|
+
expect(html).not.toContain(enUS.header.wishlistOne);
|
|
112
|
+
expect(html).not.toContain(enUS.header.wishlistMany.replace('{count}', '2'));
|
|
113
|
+
} finally {
|
|
114
|
+
Reflect.deleteProperty(globalThis, 'localStorage');
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The same rule for the wishlist **block**, which is what `/wishlist` is made of: one prerendered
|
|
120
|
+
* file is served to every visitor and what each of them saved is in their own browser, so the
|
|
121
|
+
* markup a build writes is the empty state and nothing in it is about any one shopper's list —
|
|
122
|
+
* not even with a saved list already in storage, which is what the stub below stands in for.
|
|
123
|
+
* `test/pages/hydration.spec.ts` is the other half: the browser's first render of that file is
|
|
124
|
+
* the same markup, and the cards arrive after it.
|
|
125
|
+
*/
|
|
126
|
+
it('server-renders the wishlist block as its empty state, with a saved list already in storage', async () => {
|
|
127
|
+
const saved = new Map([['eldra.storefront.wishlist', JSON.stringify(['merino-crew-sweater'])]]);
|
|
128
|
+
Object.defineProperty(globalThis, 'localStorage', {
|
|
129
|
+
configurable: true,
|
|
130
|
+
value: {
|
|
131
|
+
getItem: (key: string) => saved.get(key) ?? null,
|
|
132
|
+
setItem: () => {},
|
|
133
|
+
removeItem: () => {},
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
const html = await renderBlockToString(
|
|
138
|
+
Wishlist,
|
|
139
|
+
{ id: 'ssr-wishlist', data: wishlistMock as unknown as Record<string, unknown> },
|
|
140
|
+
{ [STOREFRONT_KEY]: createDemoStorefront() }
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(html).toContain(enUS.wishlist.emptyTitle);
|
|
144
|
+
expect(html).toContain('0 items');
|
|
145
|
+
// Not the product, not a card, not a heart: nothing in the file is about a saved list.
|
|
146
|
+
expect(html).not.toContain('Merino crew sweater');
|
|
147
|
+
expect(html).not.toContain('aria-pressed');
|
|
148
|
+
} finally {
|
|
149
|
+
Reflect.deleteProperty(globalThis, 'localStorage');
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* The `/search` page is prerendered **once** and that one file answers every query: a static host
|
|
155
|
+
* serves the same `search/index.html` for `/search` and for `/search?q=linen`
|
|
156
|
+
* (the page `pages/search.page.json` seeds). So the markup can only honestly be the idle state — and it has to stay
|
|
157
|
+
* that way even when the storefront's route already carries a query, because the server render
|
|
158
|
+
* that produced the file and the browser's first render of it have to be the same markup
|
|
159
|
+
* (`test/pages/hydration.spec.ts` is the other half).
|
|
160
|
+
*/
|
|
161
|
+
it('server-renders the search block as idle, even when the route carries a query', async () => {
|
|
162
|
+
const html = await renderBlockToString(
|
|
163
|
+
Search,
|
|
164
|
+
{ id: 'ssr-search', data: searchMock as unknown as Record<string, unknown> },
|
|
165
|
+
{ [STOREFRONT_KEY]: createDemoStorefront({ query: 'linen' }) }
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
expect(html).toContain(enUS.search.idleTitle);
|
|
169
|
+
expect(html).toContain('type="search"');
|
|
170
|
+
// Neither an answer to the query nor an answer to the empty one.
|
|
171
|
+
expect(html).not.toContain('Results for');
|
|
172
|
+
expect(html).not.toContain('No results for');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The shell's own cart drawer, in the HTML a static host serves: closed (a `<dialog>` without `open`
|
|
177
|
+
* is `display: none`, so nothing of it shows on a page nobody opened the cart on), and exactly one
|
|
178
|
+
* of them even with an authored `drawer`-variant `cart` block on the same page — two in the markup
|
|
179
|
+
* would hydrate into two, and the bag could only ever open one. The rule that makes the authored
|
|
180
|
+
* block defer on the server as well as in the browser is documented on `CartStore`
|
|
181
|
+
* (`app/storefront/cart.ts`).
|
|
182
|
+
*/
|
|
183
|
+
it('server-renders the app shell with one closed cart drawer, authored block or not', async () => {
|
|
184
|
+
const AuthoredCartPage = defineComponent({
|
|
185
|
+
name: 'AuthoredCartPage',
|
|
186
|
+
setup: () => () =>
|
|
187
|
+
h('main', { id: 'main' }, [
|
|
188
|
+
h(Cart, { entry: { id: 'authored-cart', data: { variant: 'drawer' } } } as never),
|
|
189
|
+
]),
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const html = await renderShellToString(AuthoredCartPage);
|
|
193
|
+
|
|
194
|
+
expect(html).toContain(enUS.cart.title);
|
|
195
|
+
expect(html.match(/<dialog/g) ?? []).toHaveLength(1);
|
|
196
|
+
// The attribute, not the `open:flex` utility in its class list.
|
|
197
|
+
expect(html).not.toMatch(/<dialog[^>]*\sopen[=\s>]/);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* And the bag that opens it stays a real link in that HTML, which is what a visitor with no
|
|
202
|
+
* JavaScript — or one reading the page before it hydrates — has. Why it does, and why the swap to a
|
|
203
|
+
* button afterwards is not a hydration correction: `drawerAvailable` in `app/storefront/cart.ts`.
|
|
204
|
+
*/
|
|
205
|
+
it('leaves the header bag an anchor to /cart in the prerendered HTML', async () => {
|
|
206
|
+
const html = await renderShellToString(
|
|
207
|
+
defineComponent({
|
|
208
|
+
name: 'HeaderPage',
|
|
209
|
+
setup: () => () =>
|
|
210
|
+
h(Navigation, { entry: { id: 'ssr-header', data: navigationMock } } as never),
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
expect(html).toContain('href="/cart"');
|
|
215
|
+
expect(html).not.toMatch(/<button[^>]*aria-label="Cart/);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The count is the shopper's own, restored in their browser after the page is up, so the server
|
|
220
|
+
* never has it — and the client's first render must not have it either, or every reload that
|
|
221
|
+
* restores a cart hydrates a bag the server wrote as empty against one already carrying a pill.
|
|
222
|
+
* The block reads the count only once mounted; `onMounted` never runs here, so a storefront that
|
|
223
|
+
* already knows about two items still renders the empty bag.
|
|
224
|
+
*/
|
|
225
|
+
it('prerenders the bag as empty even when the storefront already holds a cart', async () => {
|
|
226
|
+
const storefront = createDemoStorefront();
|
|
227
|
+
const cart = { ...storefront.cart, count: computed(() => 2) };
|
|
228
|
+
const html = await renderBlockToString(
|
|
229
|
+
Navigation,
|
|
230
|
+
{ id: 'ssr-header-count', data: navigationMock },
|
|
231
|
+
{ [STOREFRONT_KEY]: { ...storefront, cart } }
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
expect(html).toContain('aria-label="Cart, empty"');
|
|
235
|
+
expect(html).not.toContain('Cart, 2 items');
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it.each(FIXTURES)(
|
|
239
|
+
'server-renders the %s sample page with its banner, main and contentinfo in order',
|
|
240
|
+
async (_name, fixture) => {
|
|
241
|
+
const html = await renderPageToString(fixture);
|
|
242
|
+
|
|
243
|
+
const header = html.indexOf('<header');
|
|
244
|
+
const main = html.indexOf('<main id="main"');
|
|
245
|
+
const mainEnd = html.indexOf('</main>');
|
|
246
|
+
const footer = html.lastIndexOf('<footer');
|
|
247
|
+
|
|
248
|
+
expect(header).toBeGreaterThanOrEqual(0);
|
|
249
|
+
expect(main).toBeGreaterThan(header);
|
|
250
|
+
expect(footer).toBeGreaterThan(mainEnd);
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The prerender contract (`app/storefront/types.ts`): a commerce block's server render is the
|
|
256
|
+
* page a visitor sees, so it has to carry the real price and the real stock line — not a
|
|
257
|
+
* skeleton the client fills in afterwards — and it has to be the *same* markup the client's first
|
|
258
|
+
* render produces, or hydration mismatches and repaints the block.
|
|
259
|
+
*
|
|
260
|
+
* The refresh state is the trap on that second half: the page hydrates with the storefront about
|
|
261
|
+
* to revalidate, so a block that read `revalidating` straight through would paint spinners and
|
|
262
|
+
* `aria-busy` on the client that the server never wrote. `useRevalidating`
|
|
263
|
+
* (`app/composables/useRevalidating.ts`) is what holds the flag at `false` until after mount, and
|
|
264
|
+
* the absence of both below is what proves it — `onMounted` never runs here.
|
|
265
|
+
*/
|
|
266
|
+
describe('the prerendered commerce blocks', () => {
|
|
267
|
+
it('server-renders product-detail with its price and stock line, and no skeleton', async () => {
|
|
268
|
+
const html = await renderBlockToString(ProductDetail, {
|
|
269
|
+
id: 'ssr-product-detail',
|
|
270
|
+
data: productDetailMock as unknown as Record<string, unknown>,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
expect(html).toContain('Merino crew sweater');
|
|
274
|
+
expect(html).toContain('$96.00');
|
|
275
|
+
expect(html).toContain('In stock, ready to ship');
|
|
276
|
+
expect(html).not.toContain(enUS.storefront.loading);
|
|
277
|
+
expect(html).not.toContain(enUS.storefront.notFound);
|
|
278
|
+
expect(html).not.toContain('eldra-skeleton');
|
|
279
|
+
// `eldra-revalidating` is the dim utility `Price`/`StockBadge` apply to a value being
|
|
280
|
+
// refreshed, and nothing else in the package uses it — its absence is the refresh state's
|
|
281
|
+
// absence. (`aria-busy` on its own is not a usable signal here: the demo cart store starts a
|
|
282
|
+
// read of its own, so the Add to cart button is legitimately busy in this render.)
|
|
283
|
+
expect(html).not.toContain('eldra-revalidating');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* A shopper's saved list is their own browser's state, so it is never in the file a build
|
|
288
|
+
* wrote: the prerendered heart is unpressed however many products that visitor has saved.
|
|
289
|
+
* `createWishlistStore()` is what guarantees it — `items` is empty until `hydrate()`, which
|
|
290
|
+
* only `onMounted` calls (`app/composables/useWishlist.ts`), and `onMounted` never runs here.
|
|
291
|
+
*
|
|
292
|
+
* The storage stub is the whole test: a store that read `localStorage` at construction, the way
|
|
293
|
+
* this one used to, would server-render `aria-pressed="true"` from the list below and every
|
|
294
|
+
* hydrating browser would repaint the buy box.
|
|
295
|
+
*/
|
|
296
|
+
it('server-renders the wishlist heart unpressed, with a saved list already in storage', async () => {
|
|
297
|
+
const saved = new Map([
|
|
298
|
+
['eldra.storefront.wishlist', JSON.stringify(['merino-crew-sweater'])],
|
|
299
|
+
]);
|
|
300
|
+
// Defined and deleted by hand rather than through `vi.stubGlobal`: `unstubAllGlobals` would
|
|
301
|
+
// also restore this file's module-level `useRoute` stub, which the shell renders need.
|
|
302
|
+
Object.defineProperty(globalThis, 'localStorage', {
|
|
303
|
+
configurable: true,
|
|
304
|
+
value: {
|
|
305
|
+
getItem: (key: string) => saved.get(key) ?? null,
|
|
306
|
+
setItem: () => {},
|
|
307
|
+
removeItem: () => {},
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
try {
|
|
311
|
+
const html = await renderBlockToString(
|
|
312
|
+
ProductDetail,
|
|
313
|
+
{ id: 'ssr-wishlist', data: productDetailMock as unknown as Record<string, unknown> },
|
|
314
|
+
{ [STOREFRONT_KEY]: createDemoStorefront() }
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
expect(html).toContain(
|
|
318
|
+
enUS.product.saveToWishlist.replace('{title}', 'Merino crew sweater')
|
|
319
|
+
);
|
|
320
|
+
expect(html).toContain('aria-pressed="false"');
|
|
321
|
+
expect(html).not.toContain('aria-pressed="true"');
|
|
322
|
+
} finally {
|
|
323
|
+
Reflect.deleteProperty(globalThis, 'localStorage');
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* The whole point of reading the store's currency at **build** time: a prerendered page is
|
|
329
|
+
* already formatted in it. A store selling in krónur gets krónur in the HTML a static host
|
|
330
|
+
* serves — not a dollar sign the browser corrects a tick later, and not a bare number.
|
|
331
|
+
*
|
|
332
|
+
* The dollar amounts are listed one by one rather than caught with a `/\$\d/` sweep: this page
|
|
333
|
+
* also carries a `$` the shopper's currency does not decide — an authored FAQ sentence about a
|
|
334
|
+
* $4 gift card. That is content; these are prices. (The footer's own currency text now follows
|
|
335
|
+
* the same store currency as everything else — `ISK kr.` here, not a separate `$`.)
|
|
336
|
+
*/
|
|
337
|
+
it('server-renders the product page in the store’s own currency', async () => {
|
|
338
|
+
const commerce = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
|
|
339
|
+
const html = await renderPageToString(productPage as unknown as PageFixture, {
|
|
340
|
+
[CURRENCY_KEY]: commerce.currency,
|
|
341
|
+
[LOCALE_KEY]: 'is-IS',
|
|
342
|
+
[STOREFRONT_KEY]: createDemoStorefront({ commerce }),
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// The demo product is 96, was 128 (`app/storefront/demo.ts`).
|
|
346
|
+
expect(html).toContain(formatMoney(96, 'ISK', 'is-IS'));
|
|
347
|
+
expect(html).toContain(formatMoney(128, 'ISK', 'is-IS'));
|
|
348
|
+
expect(html).toContain('kr.');
|
|
349
|
+
for (const dollars of ['$96', '$128', '$164', '$28']) {
|
|
350
|
+
expect(html).not.toContain(dollars);
|
|
351
|
+
}
|
|
352
|
+
expect(html).not.toContain('96.00');
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* And the sign is the wide one on an English page (`ISK 96`), in every price and label alike.
|
|
357
|
+
*/
|
|
358
|
+
it('server-renders the store’s currency in its wide sign, never a bare "kr"', async () => {
|
|
359
|
+
const commerce = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
|
|
360
|
+
const html = await renderPageToString(productPage as unknown as PageFixture, {
|
|
361
|
+
[CURRENCY_KEY]: commerce.currency,
|
|
362
|
+
[LOCALE_KEY]: 'en-US',
|
|
363
|
+
[STOREFRONT_KEY]: createDemoStorefront({ commerce }),
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
expect(html).toContain(formatMoney(96, 'ISK', 'en-US'));
|
|
367
|
+
expect(formatMoney(96, 'ISK', 'en-US')).toBe('ISK\u00a096');
|
|
368
|
+
// Not the narrow sign in front of an amount, anywhere: not in a price, not in a button label.
|
|
369
|
+
expect(html).not.toMatch(/\bkr(\s| )\d/);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it('server-renders product-carousel with real cards, and no skeleton', async () => {
|
|
373
|
+
const html = await renderBlockToString(ProductCarousel, {
|
|
374
|
+
id: 'ssr-product-carousel',
|
|
375
|
+
data: productCarouselMock as unknown as Record<string, unknown>,
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
expect(html).toContain('Fisherman rib cardigan');
|
|
379
|
+
expect(html).toContain('$164.00');
|
|
380
|
+
expect(html).toContain('In stock, ships in 1–2 days');
|
|
381
|
+
expect(html).not.toContain('eldra-skeleton');
|
|
382
|
+
expect(html).not.toContain('eldra-revalidating');
|
|
383
|
+
expect(html).not.toContain('aria-busy="true"');
|
|
384
|
+
expect(html).not.toContain('data-part="spinner"');
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { onServerPrefetch } from 'vue';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import type { EldraClient } from '@eldrajs/sdk';
|
|
4
|
+
import ProductDetail from '../blocks/product-detail/Block.vue';
|
|
5
|
+
import productDetailMock from '../blocks/product-detail/mock.json';
|
|
6
|
+
import {
|
|
7
|
+
createGatewayStorefront,
|
|
8
|
+
type StorefrontPrerenderHandle,
|
|
9
|
+
type StorefrontRuntime,
|
|
10
|
+
} from '../app/storefront/gateway';
|
|
11
|
+
import { STOREFRONT_KEY, type StorefrontRoute } from '../app/storefront/types';
|
|
12
|
+
import { renderBlockToString } from './support/renderSsr';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The prerender, end to end: the commerce block a `/products/<slug>` page is built around, server
|
|
16
|
+
* rendered against the **gateway** storefront (not the demo catalogue every other block spec
|
|
17
|
+
* uses), with the storefront runtime doing what the plugin's does on the server — start the read
|
|
18
|
+
* under its key and make the render wait for it.
|
|
19
|
+
*
|
|
20
|
+
* That waiting is the whole change. Before it, `createGatewayResult`'s plain `watch(…, { immediate:
|
|
21
|
+
* true })` was never awaited by anything, so `nuxi generate` wrote the *skeleton* into the HTML and
|
|
22
|
+
* every product page flashed it before hydration refetched the same values. This asserts the
|
|
23
|
+
* opposite from the outside: the price and the stock line are in the markup, and the loading state
|
|
24
|
+
* is not — which is what a visitor sees on a cold, JavaScript-still-parsing first paint.
|
|
25
|
+
*
|
|
26
|
+
* A real `nuxi generate` cannot assert it: `test/starter.spec.ts`'s run has no gateway
|
|
27
|
+
* credentials, so it prerenders `/` and the not-found shell, and no commerce block is rendered by
|
|
28
|
+
* it at all. This is the same render path (`vue/server-renderer`, `onServerPrefetch`) one step
|
|
29
|
+
* closer in.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
function fakeRoute(handle: string): StorefrontRoute {
|
|
33
|
+
return {
|
|
34
|
+
productHandle: handle,
|
|
35
|
+
collectionHandle: null,
|
|
36
|
+
orderToken: null,
|
|
37
|
+
query: null,
|
|
38
|
+
page: 1,
|
|
39
|
+
sort: null,
|
|
40
|
+
columns: null,
|
|
41
|
+
filters: {},
|
|
42
|
+
setQuery: () => {},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* What `app/plugins/eldra-storefront.ts` hands the gateway on the server, minus Nuxt: start the
|
|
48
|
+
* load, make the component's render wait for it (`useAsyncData` registers exactly this hook), and
|
|
49
|
+
* keep the value under its key — the payload a prerendered page ships to the browser.
|
|
50
|
+
*/
|
|
51
|
+
function serverRuntime(payload: Record<string, unknown>): StorefrontRuntime {
|
|
52
|
+
return {
|
|
53
|
+
prerender<T>(key: string, load: () => Promise<T | null>): StorefrontPrerenderHandle<T> {
|
|
54
|
+
const settled = load().then(
|
|
55
|
+
(data) => {
|
|
56
|
+
payload[key] = data;
|
|
57
|
+
return { data, error: null };
|
|
58
|
+
},
|
|
59
|
+
(caught: unknown) => ({ data: null, error: (caught as Error).message })
|
|
60
|
+
);
|
|
61
|
+
onServerPrefetch(() => settled);
|
|
62
|
+
return { answered: null, settled };
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The gateway's own JSON for the product the page is about. */
|
|
68
|
+
function productResponse(): Record<string, unknown> {
|
|
69
|
+
return {
|
|
70
|
+
id: 'p-1',
|
|
71
|
+
slug: 'merino-crew-sweater',
|
|
72
|
+
title: 'Merino crew sweater',
|
|
73
|
+
status: 'ACTIVE',
|
|
74
|
+
variants: [{ id: 'v-1', sku: 'MCS-OAT-M', price: 96, status: 'ACTIVE' }],
|
|
75
|
+
description: { text: 'Extra-fine Merino, knitted in Biella.' },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function gatewayClient(): EldraClient {
|
|
80
|
+
return {
|
|
81
|
+
catalog: {
|
|
82
|
+
getProduct: async () => productResponse(),
|
|
83
|
+
listProducts: async () => ({
|
|
84
|
+
data: [],
|
|
85
|
+
meta: { page: 1, pageSize: 24, total: 0, totalPages: 0, rows: 0 },
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
} as unknown as EldraClient;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
describe('a prerendered product page', () => {
|
|
92
|
+
it('renders the price and the stock line into the HTML, and no loading state', async () => {
|
|
93
|
+
const payload: Record<string, unknown> = {};
|
|
94
|
+
const storefront = createGatewayStorefront(gatewayClient(), {
|
|
95
|
+
route: fakeRoute('merino-crew-sweater'),
|
|
96
|
+
runtime: serverRuntime(payload),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const html = await renderBlockToString(
|
|
100
|
+
ProductDetail,
|
|
101
|
+
{ id: 'product-detail-1', data: { ...productDetailMock, productHandle: '' } },
|
|
102
|
+
{ [STOREFRONT_KEY]: storefront }
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
expect(html).toContain('Merino crew sweater');
|
|
106
|
+
expect(html).toContain('$96.00');
|
|
107
|
+
expect(html).toContain('In stock, ready to ship');
|
|
108
|
+
// The state this whole change exists to remove from a prerendered page.
|
|
109
|
+
expect(html).not.toContain('Loading…');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('leaves the product in the page payload, keyed by the read that produced it', async () => {
|
|
113
|
+
const payload: Record<string, unknown> = {};
|
|
114
|
+
const storefront = createGatewayStorefront(gatewayClient(), {
|
|
115
|
+
route: fakeRoute('merino-crew-sweater'),
|
|
116
|
+
runtime: serverRuntime(payload),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
await renderBlockToString(
|
|
120
|
+
ProductDetail,
|
|
121
|
+
{ id: 'product-detail-1', data: { ...productDetailMock, productHandle: '' } },
|
|
122
|
+
{ [STOREFRONT_KEY]: storefront }
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// The same key the hydrating browser reads back, so it paints this value instead of refetching
|
|
126
|
+
// it (`test/storefront/gatewayPrerender.spec.ts` asserts that half).
|
|
127
|
+
const product = payload['storefront:catalog.product:["merino-crew-sweater"]'] as {
|
|
128
|
+
title: string;
|
|
129
|
+
price: { amount: number };
|
|
130
|
+
};
|
|
131
|
+
expect(product.title).toBe('Merino crew sweater');
|
|
132
|
+
expect(product.price.amount).toBe(96);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { execa } from 'execa';
|
|
2
|
+
import {
|
|
3
|
+
cpSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
readdirSync,
|
|
7
|
+
readFileSync,
|
|
8
|
+
rmSync,
|
|
9
|
+
symlinkSync,
|
|
10
|
+
} from 'node:fs';
|
|
11
|
+
import { tmpdir } from 'node:os';
|
|
12
|
+
import { join, relative, sep } from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
14
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
15
|
+
import {
|
|
16
|
+
COLLECTION_HANDLE,
|
|
17
|
+
ORG_ID,
|
|
18
|
+
startMockGateway,
|
|
19
|
+
type MockGateway,
|
|
20
|
+
} from './support/mockGateway';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* **A route the gateway could not be asked about must not be written as the not-found page.**
|
|
24
|
+
*
|
|
25
|
+
* A storefront's reads fail one at a time: a gateway under load answers one of them 500 and the
|
|
26
|
+
* rest normally. That is not a 404 — a 404 means the object is gone, a 500 means nobody could be
|
|
27
|
+
* asked — and the difference is the whole of this spec, because for one prerendered route the two
|
|
28
|
+
* used to be indistinguishable:
|
|
29
|
+
*
|
|
30
|
+
* * `useEldraPage()` is called twice on every page of this starter — once by
|
|
31
|
+
* `app/plugins/eldra-storefront.ts` for the catalog route it matched, once by
|
|
32
|
+
* `app/pages/[...slug].vue` for the page it renders — under one async-data key. Nuxt keeps one
|
|
33
|
+
* entry per key and runs the **first** registration's handler, so a failure the composable
|
|
34
|
+
* remembered in its own `ref` reached the plugin's call and nothing else: the page's `error`
|
|
35
|
+
* stayed `null` over an empty resolution, which is exactly what "there is no such page" looks
|
|
36
|
+
* like. The page drew its not-found shell.
|
|
37
|
+
* * And `nuxi generate` wrote it: a 10 kB "Page not found" document at
|
|
38
|
+
* `collections/<slug>/index.html`, for a collection with six products in it, with nothing in
|
|
39
|
+
* the build log and exit code 0. On the deployed site every link to that collection — the
|
|
40
|
+
* header's included — landed on a dead end that looked deliberate.
|
|
41
|
+
*
|
|
42
|
+
* So the failure now travels with the resolution (`ResolvedEldraRoute.error`), the theme answers
|
|
43
|
+
* such a route `500` on the server, and `nitro.prerender.failOnError` makes the build say so.
|
|
44
|
+
* Nitro marks a non-200 route failed *before* it writes anything, which is what keeps the wrong
|
|
45
|
+
* page out of the artifact rather than merely out of the happy path.
|
|
46
|
+
*
|
|
47
|
+
* The gateway here fails exactly one read — the collection template's own
|
|
48
|
+
* `GET /catalog/v1/collections/<slug>` — so every other route in the build is unaffected and the
|
|
49
|
+
* assertions are about one route's absence rather than about an empty `.output`.
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
const templateDir = fileURLToPath(new URL('..', import.meta.url));
|
|
53
|
+
const nuxi = join(templateDir, 'node_modules', '.bin', 'nuxi');
|
|
54
|
+
/** Build output and installed dependencies: rebuilt or symlinked in the copy, never copied. */
|
|
55
|
+
const SKIPPED_FROM_COPY = new Set(['node_modules', '.nuxt', '.output', '.git']);
|
|
56
|
+
|
|
57
|
+
let gateway: MockGateway;
|
|
58
|
+
let scratch: string;
|
|
59
|
+
let root: string;
|
|
60
|
+
let generated: { exitCode: number | undefined; stdout: string; stderr: string };
|
|
61
|
+
|
|
62
|
+
const output = (path: string): string => join(root, '.output', 'public', path);
|
|
63
|
+
|
|
64
|
+
describe('a prerendered route whose resolution failed', () => {
|
|
65
|
+
beforeAll(async () => {
|
|
66
|
+
gateway = await startMockGateway({
|
|
67
|
+
failPath: `/catalog/v1/collections/${COLLECTION_HANDLE}`,
|
|
68
|
+
});
|
|
69
|
+
scratch = mkdtempSync(join(tmpdir(), 'eldra-prerender-failure-'));
|
|
70
|
+
root = join(scratch, 'site');
|
|
71
|
+
// The starter itself, minus what a build makes — the same reason
|
|
72
|
+
// `test/prerenderRefresh.browser.spec.ts` copies it: `nuxi generate` writes `.output` into its
|
|
73
|
+
// own working directory, and this suite must not race the one `test/starter.spec.ts` runs.
|
|
74
|
+
cpSync(templateDir, root, {
|
|
75
|
+
recursive: true,
|
|
76
|
+
filter: (source) => {
|
|
77
|
+
const [first] = relative(templateDir, source).split(sep);
|
|
78
|
+
return first === undefined || !SKIPPED_FROM_COPY.has(first);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
symlinkSync(join(templateDir, 'node_modules'), join(root, 'node_modules'), 'dir');
|
|
82
|
+
const run = await execa(nuxi, ['generate'], {
|
|
83
|
+
cwd: root,
|
|
84
|
+
env: { ELDRA_GATEWAY_URL: gateway.url, ELDRA_ORG_ID: ORG_ID },
|
|
85
|
+
reject: false,
|
|
86
|
+
timeout: 600_000,
|
|
87
|
+
});
|
|
88
|
+
generated = { exitCode: run.exitCode, stdout: run.stdout, stderr: run.stderr };
|
|
89
|
+
}, 900_000);
|
|
90
|
+
|
|
91
|
+
afterAll(async () => {
|
|
92
|
+
await gateway?.close();
|
|
93
|
+
if (scratch !== undefined) rmSync(scratch, { recursive: true, force: true });
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('writes no file for it, and no not-found shell anywhere under its path', () => {
|
|
97
|
+
const collectionDir = output(join('collections', COLLECTION_HANDLE));
|
|
98
|
+
expect(existsSync(join(collectionDir, 'index.html')), 'collection page written').toBe(false);
|
|
99
|
+
expect(existsSync(join(collectionDir, '_payload.json')), 'collection payload written').toBe(
|
|
100
|
+
false
|
|
101
|
+
);
|
|
102
|
+
// Nothing under `collections/` at all, in any locale: the one collection this fixture has is
|
|
103
|
+
// the one whose read fails.
|
|
104
|
+
for (const prefix of ['', 'is-IS']) {
|
|
105
|
+
const dir = output(join(prefix, 'collections'));
|
|
106
|
+
const written = existsSync(dir) ? readdirSync(dir) : [];
|
|
107
|
+
expect(written, `${prefix || '/'} collections`).toEqual([]);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('fails the build over it, rather than exiting 0 with the page missing', () => {
|
|
112
|
+
// `nitro.prerender.failOnError` (`nuxt.config.ts`) is the half that makes the *absence* loud:
|
|
113
|
+
// without it the generate still exits 0 and an artifact with a hole in its catalogue is
|
|
114
|
+
// deployable. The route itself is named in the prerender list Nitro prints, which is on the
|
|
115
|
+
// build's console rather than in what `nuxi generate` hands back here.
|
|
116
|
+
expect(generated.exitCode).not.toBe(0);
|
|
117
|
+
expect(`${generated.stdout}\n${generated.stderr}`).toContain('prerender errors');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('still writes every route the gateway could answer', () => {
|
|
121
|
+
// The product template, the home page and the styled not-found shell are untouched by a
|
|
122
|
+
// failure in one collection read — a build that threw them away too would pass the assertions
|
|
123
|
+
// above for the wrong reason.
|
|
124
|
+
expect(existsSync(output(join('products', 'ash-glaze-mug', 'index.html')))).toBe(true);
|
|
125
|
+
expect(existsSync(output('index.html'))).toBe(true);
|
|
126
|
+
const notFound = output(join('404', 'index.html'));
|
|
127
|
+
expect(existsSync(notFound)).toBe(true);
|
|
128
|
+
expect(readFileSync(notFound, 'utf8')).toContain('data-eldra-not-found');
|
|
129
|
+
});
|
|
130
|
+
});
|