create-abcart-theme 0.10.1 → 1.0.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 +133 -127
- package/LICENSE +202 -202
- package/NOTICE +2 -2
- package/README.md +65 -65
- package/bin/create-abcart-theme.mjs +4 -4
- package/package.json +49 -49
- package/src/args.mjs +113 -113
- package/src/banner.mjs +21 -21
- package/src/cli.mjs +119 -119
- package/src/create.mjs +85 -82
- package/src/package-manager.mjs +32 -32
- package/src/style.mjs +17 -17
- package/templates/default/.agents/skills/{wocart-docs → abcart-docs}/SKILL.md +146 -146
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/SKILL.md +58 -58
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/inputs-and-rights.md +47 -47
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/layout-rtl-and-phone.md +36 -36
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/measure-the-design.md +60 -60
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/tokens-sections-content.md +103 -103
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/references/verify-and-report.md +102 -102
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/compare-design.cjs +230 -230
- package/templates/default/.agents/skills/{wocart-theme-from-design → abcart-theme-from-design}/scripts/qa-pages.cjs +219 -219
- package/templates/default/.agents/skills/shopify-theme-asset-collector/SKILL.md +125 -125
- package/templates/default/.agents/skills/shopify-theme-asset-collector/scripts/collect_public_assets.py +370 -370
- package/templates/default/.dev.vars.example +12 -12
- package/templates/default/AGENTS.md +240 -240
- package/templates/default/README.md +184 -184
- package/templates/default/_gitignore +11 -11
- package/templates/default/astro.config.mjs +85 -85
- package/templates/default/package.json +36 -36
- package/templates/default/public/fonts/OFL.txt +96 -96
- package/templates/default/src/actions/index.ts +22 -22
- package/templates/default/src/components/cart/AddToCartButton.astro +45 -45
- package/templates/default/src/components/cart/CartDrawer.astro +47 -47
- package/templates/default/src/components/cart/CartSummary.astro +11 -11
- package/templates/default/src/components/cart/FreeShipping.astro +7 -7
- package/templates/default/src/components/checkout/CheckoutMain.astro +29 -29
- package/templates/default/src/components/checkout/OrderForm.astro +280 -280
- package/templates/default/src/components/checkout/ThankYouMain.astro +68 -68
- package/templates/default/src/components/landing/LandingImages.astro +51 -51
- package/templates/default/src/components/landing/LandingOrder.astro +46 -46
- package/templates/default/src/components/landing/LandingProduct.astro +41 -41
- package/templates/default/src/components/listing/ListingMain.astro +93 -93
- package/templates/default/src/components/listing/PageMain.astro +52 -52
- package/templates/default/src/components/listing/Pagination.astro +31 -31
- package/templates/default/src/components/listing/SortControl.astro +35 -35
- package/templates/default/src/components/product/BuyBox.astro +96 -96
- package/templates/default/src/components/product/Description.astro +24 -24
- package/templates/default/src/components/product/Gallery.astro +66 -66
- package/templates/default/src/components/product/MobileBuyBar.astro +29 -29
- package/templates/default/src/components/product/OfferChoice.astro +66 -66
- package/templates/default/src/components/product/ProductMain.astro +40 -40
- package/templates/default/src/components/product/ProductReviews.astro +72 -72
- package/templates/default/src/components/product/RelatedProducts.astro +30 -30
- package/templates/default/src/components/product/blocks/BenefitsBlock.astro +13 -13
- package/templates/default/src/components/product/blocks/CollapsibleBlock.astro +20 -20
- package/templates/default/src/components/product/blocks/DescriptionBlock.astro +19 -19
- package/templates/default/src/components/product/blocks/DetailsBlock.astro +33 -33
- package/templates/default/src/components/product/blocks/GalleryBlock.astro +12 -12
- package/templates/default/src/components/product/blocks/OrderBlock.astro +30 -30
- package/templates/default/src/components/product/blocks/PriceBlock.astro +23 -23
- package/templates/default/src/components/product/blocks/RatingBlock.astro +16 -16
- package/templates/default/src/components/product/blocks/StockBlock.astro +22 -22
- package/templates/default/src/components/product/blocks/TextBlock.astro +11 -11
- package/templates/default/src/components/product/blocks/TitleBlock.astro +20 -20
- package/templates/default/src/components/reviews/ReviewCard.astro +46 -46
- package/templates/default/src/components/reviews/ReviewForm.astro +113 -113
- package/templates/default/src/components/reviews/VoiceNote.astro +60 -60
- package/templates/default/src/components/sections/CollectionCards.astro +65 -65
- package/templates/default/src/components/sections/Countdown.astro +57 -57
- package/templates/default/src/components/sections/Faq.astro +44 -44
- package/templates/default/src/components/sections/FeaturedProduct.astro +71 -71
- package/templates/default/src/components/sections/Hero.astro +99 -99
- package/templates/default/src/components/sections/ImageBanner.astro +46 -46
- package/templates/default/src/components/sections/ProductGrid.astro +47 -47
- package/templates/default/src/components/sections/RichText.astro +35 -35
- package/templates/default/src/components/sections/Steps.astro +46 -46
- package/templates/default/src/components/sections/Testimonials.astro +57 -57
- package/templates/default/src/components/shell/Footer.astro +80 -80
- package/templates/default/src/components/shell/Header.astro +89 -89
- package/templates/default/src/components/shell/LanguageMenu.astro +33 -33
- package/templates/default/src/components/shell/MobileMenu.astro +65 -65
- package/templates/default/src/components/shell/SearchDialog.astro +19 -19
- package/templates/default/src/components/shell/TopBar.astro +54 -54
- package/templates/default/src/components/shell/WhatsAppWidget.astro +111 -111
- package/templates/default/src/components/store/ContactMain.astro +79 -79
- package/templates/default/src/components/store/SearchMain.astro +56 -56
- package/templates/default/src/components/store/TrackOrderMain.astro +161 -161
- package/templates/default/src/components/surface/Area.astro +20 -20
- package/templates/default/src/components/surface/PreviewBridge.astro +24 -24
- package/templates/default/src/components/surface/Sections.astro +35 -35
- package/templates/default/src/components/ui/Breadcrumbs.astro +36 -36
- package/templates/default/src/components/ui/Button.astro +45 -45
- package/templates/default/src/components/ui/EditorPlaceholder.astro +24 -24
- package/templates/default/src/components/ui/Icon.astro +93 -93
- package/templates/default/src/components/ui/Logo.astro +36 -36
- package/templates/default/src/components/ui/Photo.astro +46 -46
- package/templates/default/src/components/ui/Price.astro +24 -24
- package/templates/default/src/components/ui/ProductCard.astro +41 -41
- package/templates/default/src/components/ui/Rating.astro +22 -22
- package/templates/default/src/components/ui/Section.astro +34 -34
- package/templates/default/src/components/ui/SectionHeading.astro +19 -19
- package/templates/default/src/env.d.ts +23 -23
- package/templates/default/src/layouts/StoreLayout.astro +145 -145
- package/templates/default/src/lib/browser-copy.ts +37 -37
- package/templates/default/src/lib/context.ts +89 -89
- package/templates/default/src/lib/coupon-notice.ts +47 -47
- package/templates/default/src/lib/i18n.ts +32 -32
- package/templates/default/src/lib/images.ts +38 -38
- package/templates/default/src/lib/listing-query.ts +41 -41
- package/templates/default/src/lib/money.ts +16 -16
- package/templates/default/src/lib/motion.ts +16 -16
- package/templates/default/src/lib/nav.ts +26 -26
- package/templates/default/src/lib/offer-tiles.ts +105 -105
- package/templates/default/src/lib/order-outcome.ts +66 -66
- package/templates/default/src/lib/otp-message.ts +21 -21
- package/templates/default/src/lib/products.ts +38 -38
- package/templates/default/src/lib/review-refusals.ts +31 -31
- package/templates/default/src/lib/store.ts +31 -31
- package/templates/default/src/lib/whatsapp.ts +29 -29
- package/templates/default/src/middleware.ts +23 -23
- package/templates/default/src/pages/404.astro +22 -22
- package/templates/default/src/pages/{wocart-preview.astro → abcart-preview.astro} +43 -43
- package/templates/default/src/pages/{wocart-revalidate.ts → abcart-revalidate.ts} +10 -10
- package/templates/default/src/pages/{wocart-styles.css.ts → abcart-styles.css.ts} +5 -5
- package/templates/default/src/pages/{wocart-theme.json.ts → abcart-theme.json.ts} +5 -5
- package/templates/default/src/pages/api/abandoned/convert.ts +4 -4
- package/templates/default/src/pages/api/abandoned/upsert.ts +4 -4
- package/templates/default/src/pages/api/cart/validate.ts +4 -4
- package/templates/default/src/pages/api/communes/[wilayaId].ts +4 -4
- package/templates/default/src/pages/api/otp/send.ts +4 -4
- package/templates/default/src/pages/api/otp/verify.ts +4 -4
- package/templates/default/src/pages/api/reviews/[productId].ts +3 -3
- package/templates/default/src/pages/api/reviews/eligibility.ts +3 -3
- package/templates/default/src/pages/api/reviews/submit.ts +3 -3
- package/templates/default/src/pages/api/reviews/upload.ts +3 -3
- package/templates/default/src/pages/category/[slug].astro +20 -20
- package/templates/default/src/pages/checkout.astro +25 -25
- package/templates/default/src/pages/collections/[handle].astro +20 -20
- package/templates/default/src/pages/contact.astro +17 -17
- package/templates/default/src/pages/index.astro +9 -9
- package/templates/default/src/pages/lp/[slug].astro +47 -47
- package/templates/default/src/pages/pages/[slug].astro +16 -16
- package/templates/default/src/pages/products/[handle].astro +37 -37
- package/templates/default/src/pages/products/index.astro +15 -15
- package/templates/default/src/pages/robots.txt.ts +9 -9
- package/templates/default/src/pages/search.astro +19 -19
- package/templates/default/src/pages/sitemap.xml.ts +12 -12
- package/templates/default/src/pages/thank-you.astro +33 -33
- package/templates/default/src/pages/track-order.astro +17 -17
- package/templates/default/src/scripts/cart.ts +371 -371
- package/templates/default/src/scripts/checkout/coupon.ts +96 -96
- package/templates/default/src/scripts/checkout/delivery.ts +86 -86
- package/templates/default/src/scripts/checkout/form.ts +54 -54
- package/templates/default/src/scripts/checkout/otp.ts +106 -106
- package/templates/default/src/scripts/checkout/picker.ts +169 -169
- package/templates/default/src/scripts/checkout/quote.ts +169 -169
- package/templates/default/src/scripts/checkout/submit.ts +113 -113
- package/templates/default/src/scripts/checkout/tracking.ts +74 -74
- package/templates/default/src/scripts/countdown.ts +29 -29
- package/templates/default/src/scripts/events.ts +4 -4
- package/templates/default/src/scripts/hero.ts +49 -49
- package/templates/default/src/scripts/listing.ts +13 -13
- package/templates/default/src/scripts/order-form.ts +100 -100
- package/templates/default/src/scripts/product.ts +306 -306
- package/templates/default/src/scripts/public-config.ts +79 -79
- package/templates/default/src/scripts/reviews.ts +358 -358
- package/templates/default/src/scripts/site.ts +131 -131
- package/templates/default/src/scripts/thank-you.ts +11 -11
- package/templates/default/src/scripts/voice-note.ts +94 -94
- package/templates/default/src/styles/base.css +1030 -1030
- package/templates/default/src/styles/checkout.css +1111 -1111
- package/templates/default/src/styles/global.css +12 -12
- package/templates/default/src/styles/product.css +871 -871
- package/templates/default/src/styles/reviews.css +533 -533
- package/templates/default/src/styles/sections.css +931 -931
- package/templates/default/src/styles/shell.css +970 -970
- package/templates/default/src/styles/tokens.css +583 -583
- package/templates/default/src/theme/api-routes.ts +10 -10
- package/templates/default/src/theme/content/catalog.ts +117 -117
- package/templates/default/src/theme/content/checkout.ts +168 -168
- package/templates/default/src/theme/content/editor.ts +21 -21
- package/templates/default/src/theme/content/index.ts +45 -45
- package/templates/default/src/theme/content/reviews.ts +76 -76
- package/templates/default/src/theme/content/shell.ts +59 -59
- package/templates/default/src/theme/content/types.ts +12 -12
- package/templates/default/src/theme/documents/catalog.json +11 -11
- package/templates/default/src/theme/documents/category.json +11 -11
- package/templates/default/src/theme/documents/checkout.json +11 -11
- package/templates/default/src/theme/documents/collection.json +11 -11
- package/templates/default/src/theme/documents/contact.json +11 -11
- package/templates/default/src/theme/documents/footer.area.json +11 -11
- package/templates/default/src/theme/documents/header.area.json +16 -16
- package/templates/default/src/theme/documents/home.json +313 -313
- package/templates/default/src/theme/documents/landing.json +8 -8
- package/templates/default/src/theme/documents/page.json +11 -11
- package/templates/default/src/theme/documents/product.json +125 -125
- package/templates/default/src/theme/documents/search.json +11 -11
- package/templates/default/src/theme/documents/thank-you.json +11 -11
- package/templates/default/src/theme/documents/track-order.json +11 -11
- package/templates/default/src/theme/fields.ts +61 -61
- package/templates/default/src/theme/key.ts +11 -11
- package/templates/default/src/theme/labels.ts +231 -231
- package/templates/default/src/theme/locales.ts +11 -11
- package/templates/default/src/theme/palette.ts +14 -14
- package/templates/default/src/theme/sections/collection-cards.ts +65 -65
- package/templates/default/src/theme/sections/faq.ts +74 -74
- package/templates/default/src/theme/sections/featured-product.ts +42 -42
- package/templates/default/src/theme/sections/hero.ts +47 -47
- package/templates/default/src/theme/sections/image-banner.ts +25 -25
- package/templates/default/src/theme/sections/index.ts +40 -40
- package/templates/default/src/theme/sections/landing.ts +150 -150
- package/templates/default/src/theme/sections/listing.ts +84 -84
- package/templates/default/src/theme/sections/product-grid.ts +42 -42
- package/templates/default/src/theme/sections/product.ts +297 -297
- package/templates/default/src/theme/sections/rich-text.ts +39 -39
- package/templates/default/src/theme/sections/shared.ts +54 -54
- package/templates/default/src/theme/sections/shell.ts +85 -85
- package/templates/default/src/theme/sections/store-pages.ts +101 -101
- package/templates/default/src/theme/sections/testimonials.ts +61 -61
- package/templates/default/src/theme/sections/thank-you.ts +35 -35
- package/templates/default/src/theme/settings.ts +124 -124
- package/templates/default/src/theme/theme.ts +65 -65
- package/templates/default/tests/fixtures/canvas-tote.json +62 -62
- package/templates/default/tests/fixtures/linen-shirt.json +128 -128
- package/templates/default/tests/unit/checkout.test.ts +241 -241
- package/templates/default/tests/unit/contract.test.ts +170 -169
- package/templates/default/tests/unit/contrast.test.ts +68 -68
- package/templates/default/tests/unit/copy.test.ts +101 -101
- package/templates/default/tests/unit/design-values.test.ts +95 -95
- package/templates/default/tests/unit/editability.test.ts +180 -180
- package/templates/default/tests/unit/fixtures.ts +91 -91
- package/templates/default/tests/unit/footer.test.ts +54 -54
- package/templates/default/tests/unit/guards.test.ts +340 -340
- package/templates/default/tests/unit/images.test.ts +26 -26
- package/templates/default/tests/unit/landing.test.ts +151 -151
- package/templates/default/tests/unit/languages.test.ts +42 -42
- package/templates/default/tests/unit/middleware.test.ts +53 -53
- package/templates/default/tests/unit/offer-tiles.test.ts +75 -75
- package/templates/default/tests/unit/render.ts +38 -38
- package/templates/default/tests/unit/reviews.test.ts +25 -25
- package/templates/default/tests/unit/rules.test.ts +59 -59
- package/templates/default/tests/unit/source.ts +75 -75
- package/templates/default/tests/unit/store-pages.test.ts +147 -147
- package/templates/default/tests/unit/studio.test.ts +202 -202
- package/templates/default/tests/unit/testimonials.test.ts +52 -52
- package/templates/default/tests/unit/thank-you.test.ts +52 -52
- package/templates/default/tests/unit/tracking.test.ts +29 -29
- package/templates/default/tests/unit/voice-note.test.ts +42 -42
- package/templates/default/tsconfig.json +13 -13
- package/templates/default/vitest.config.ts +15 -15
- package/templates/default/wrangler.jsonc +16 -16
|
@@ -1,340 +1,340 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Source guards: rules every theme keeps, checked on the shipped source under
|
|
3
|
-
* `src/` (tests and build output left out). One walker, so every guard agrees
|
|
4
|
-
* on what "the theme" is; each first proves it found something to check.
|
|
5
|
-
*/
|
|
6
|
-
import { describe, expect, it } from "vitest";
|
|
7
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { SCHEME_MARKER_CLASS } from "@abcart/theme";
|
|
10
|
-
import { STOREFRONT_API_PATHS } from "@abcart/storefront";
|
|
11
|
-
import { content } from "../../src/theme/content";
|
|
12
|
-
import { ROOT, browserModuleGraph, code, files, runtimeImports } from "./source";
|
|
13
|
-
|
|
14
|
-
describe("the theme's browser code", () => {
|
|
15
|
-
const graph = browserModuleGraph();
|
|
16
|
-
|
|
17
|
-
it("is found, so these guards check something", () => {
|
|
18
|
-
expect([...graph.keys()]).toEqual(expect.arrayContaining(["scripts/order-form.ts", "scripts/cart.ts", "scripts/product.ts", "lib/coupon-notice.ts"]));
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("imports no schema and nothing from Zod: the server checked the data", () => {
|
|
22
|
-
const offenders = [...graph.values()].flatMap((file) =>
|
|
23
|
-
runtimeImports(file.text).flatMap(({ from, names }) => [
|
|
24
|
-
...(from === "zod" || from.startsWith("zod/") ? [`${file.path}: zod`] : []),
|
|
25
|
-
...(from.startsWith("@wocart/") ? names.filter((name) => /Schema\b/.test(name)).map((name) => `${file.path}: ${name}`) : []),
|
|
26
|
-
]),
|
|
27
|
-
);
|
|
28
|
-
expect(offenders).toEqual([]);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("never reaches a server-only module, so the API key cannot ship", () => {
|
|
32
|
-
const serverOnly = /^(astro:env\/server|astro:actions|@wocart\/storefront\/(server|astro)|@\/lib\/(store|env)(\.ts)?)$/;
|
|
33
|
-
const offenders = [...graph.values()].flatMap((file) =>
|
|
34
|
-
runtimeImports(file.text).filter(({ from }) => serverOnly.test(from)).map(({ from }) => `${file.path} → ${from}`),
|
|
35
|
-
);
|
|
36
|
-
expect(offenders).toEqual([]);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("takes from @abcart/theme only its browser entries: the lifecycle and the messages", () => {
|
|
40
|
-
const offenders = [...graph.values()].flatMap((file) =>
|
|
41
|
-
runtimeImports(file.text)
|
|
42
|
-
.filter(({ from }) => from.startsWith("@abcart/theme") && !["@abcart/theme/lifecycle", "@abcart/theme/messages"].includes(from))
|
|
43
|
-
.filter(({ from }) => !(from === "@abcart/theme/preview" && file.path.startsWith("components/surface/PreviewBridge")))
|
|
44
|
-
.map(({ from }) => `${file.path} → ${from}`),
|
|
45
|
-
);
|
|
46
|
-
expect(offenders).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("never ships the editor's bridge to a shopper's page", () => {
|
|
50
|
-
const shipsBridge = [...graph.values()].filter((file) => !file.path.startsWith("components/surface/PreviewBridge") && runtimeImports(file.text).some(({ from }) => from === "@abcart/theme/preview")).map((file) => file.path);
|
|
51
|
-
expect(shipsBridge).toEqual([]);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("binds every behaviour through the SDK's lifecycle, so the editor's preview can swap a section or the page", () => {
|
|
55
|
-
// A script that finds its elements once at load would stay bound to markup the preview replaced.
|
|
56
|
-
const scripts = code.filter((file) => file.path.startsWith("scripts/") && !file.path.startsWith("scripts/checkout/") && !["scripts/events.ts", "scripts/public-config.ts", "scripts/cart.ts"].includes(file.path));
|
|
57
|
-
expect(scripts.length).toBeGreaterThanOrEqual(5);
|
|
58
|
-
const unbound = scripts.filter((file) => !runtimeImports(file.text).some(({ from, names }) => from === "@abcart/theme/lifecycle" && names.includes("bindEach"))).map((file) => file.path);
|
|
59
|
-
expect(unbound).toEqual([]);
|
|
60
|
-
// The swap events are the SDK's to name: a theme that listens for them itself has a second lifecycle.
|
|
61
|
-
const ownLifecycle = code.filter((file) => /["'](?:wocart:section-load|astro:page-load|astro:before-swap)["']/.test(file.text)).map((file) => file.path);
|
|
62
|
-
expect(ownLifecycle).toEqual([]);
|
|
63
|
-
const cart = code.find((file) => file.path === "scripts/cart.ts")!;
|
|
64
|
-
expect(cart.text).not.toMatch(/^const \w+ = document\.querySelector/m);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("binds the order form's parts from its one entry: no part binds itself or touches the page on load", () => {
|
|
68
|
-
const parts = code.filter((file) => file.path.startsWith("scripts/checkout/"));
|
|
69
|
-
expect(parts.map((file) => file.path.replace("scripts/checkout/", "")).sort()).toEqual(expect.arrayContaining(["coupon.ts", "delivery.ts", "otp.ts", "quote.ts", "submit.ts"]));
|
|
70
|
-
const entry = code.find((file) => file.path === "scripts/order-form.ts")!.text;
|
|
71
|
-
expect(parts.filter((file) => !entry.includes(`"./checkout/${file.path.replace("scripts/checkout/", "").replace(/\.ts$/, "")}"`)).map((file) => file.path)).toEqual([]);
|
|
72
|
-
expect(parts.filter((file) => runtimeImports(file.text).some(({ names }) => names.includes("bindEach") || names.includes("onEachPage"))).map((file) => file.path)).toEqual([]);
|
|
73
|
-
const onLoad = parts.flatMap((file) => file.text.split("\n").map((line, index) => ({ line, at: `${file.path}:${index + 1}` })).filter(({ line }) => /^(?![\s/*}]).*\b(document|window)\.(querySelector|addEventListener|location)/.test(line)).map(({ at }) => at));
|
|
74
|
-
expect(onLoad).toEqual([]);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("gives every order form its checkout key, so a refresh or a retry places no second order", () => {
|
|
78
|
-
const orderForms = code.filter((file) => /<form\b[^>]*action=\{actions\.placeOrder\}/.test(file.text));
|
|
79
|
-
expect(orderForms.map((file) => file.path)).toEqual(["components/checkout/OrderForm.astro"]);
|
|
80
|
-
expect(orderForms[0]!.text).toMatch(/<form\b[^>]*\bdata-order-form\b/);
|
|
81
|
-
const orderForm = code.find((file) => file.path === "scripts/order-form.ts")!;
|
|
82
|
-
expect(orderForm.text).toMatch(/bindEach<HTMLFormElement>\("\[data-order-form\]", initForm\)/);
|
|
83
|
-
expect(orderForm.text).toMatch(/function initForm\(form: HTMLFormElement\) \{\n(?:\s*\/\/.*\n)*\s*const unbindCheckoutKey = bindCheckoutKey\(form\);/);
|
|
84
|
-
// Every way out of initForm hands back the cleanup that unbinds the key.
|
|
85
|
-
expect(orderForm.text).toMatch(/const cleanups: Cleanup\[\] = \[unbindCheckoutKey(?:, [^\]]+)?\];/);
|
|
86
|
-
const body = orderForm.text.slice(orderForm.text.indexOf("function initForm("));
|
|
87
|
-
const returns = [...body.matchAll(/\breturn\b[^;\n]*/g)].map((match) => match[0]).filter((statement) => !/^return window\.location/.test(statement));
|
|
88
|
-
expect(returns.length).toBeGreaterThanOrEqual(2);
|
|
89
|
-
expect(returns.every((statement) => statement === "return () => cleanups.forEach((cleanup) => cleanup())")).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe("the SDK boundary", () => {
|
|
94
|
-
it("answers a missing product, category, collection, page or landing page through the SDK's notFound, never cached", () => {
|
|
95
|
-
const routes = ["pages/products/[handle].astro", "pages/category/[slug].astro", "pages/collections/[handle].astro", "pages/pages/[slug].astro", "pages/lp/[slug].astro"];
|
|
96
|
-
for (const route of routes) expect(code.find((file) => file.path === route)?.text, route).toMatch(/return notFound\(Astro\);/);
|
|
97
|
-
const handRolled = code.filter((file) => file.path.startsWith("pages/") && file.path !== "pages/404.astro" && /rewrite\(["']\/404["']\)|cache\.set\(false\)/.test(file.text)).map((file) => file.path);
|
|
98
|
-
expect(handRolled).toEqual([]);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("mounts a route file at every API path the browser calls, and none it does not", () => {
|
|
102
|
-
// The SDK's `:wilayaId` is Astro's `[wilayaId]`: each path names exactly one route file.
|
|
103
|
-
const routeFiles = files.filter((file) => file.path.startsWith("pages/api/")).map((file) => `/${file.path.replace(/^pages\//, "").replace(/\.ts$/, "")}`);
|
|
104
|
-
const expected = Object.values(STOREFRONT_API_PATHS).map((path) => path.replace(/:(\w+)/g, "[$1]"));
|
|
105
|
-
expect(expected.filter((path) => !routeFiles.includes(path))).toEqual([]);
|
|
106
|
-
expect(routeFiles.filter((route) => !expected.includes(route))).toEqual([]);
|
|
107
|
-
const ownTables = code.filter((file) => /["'`]\/api\//.test(file.text) && !file.path.startsWith("pages/api/")).map((file) => file.path);
|
|
108
|
-
expect(ownTables).toEqual([]);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("creates SDK clients in one place only", () => {
|
|
112
|
-
const creators = code.filter((file) => /\bcreateStoreClient\s*\(/.test(file.text)).map((file) => file.path);
|
|
113
|
-
expect(creators).toEqual(["lib/store.ts"]);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("shows a store it cannot read through the SDK's unavailable store, built in one place", () => {
|
|
117
|
-
const fallbacks = code.filter((file) => /\bunavailableStoreConfig\s*\(/.test(file.text)).map((file) => file.path);
|
|
118
|
-
expect(fallbacks).toEqual(["middleware.ts"]);
|
|
119
|
-
expect(code.find((file) => file.path === "middleware.ts")!.text).toMatch(/fallback: unavailableStoreConfig\(/);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("imports the SDKs through their published entry points only", () => {
|
|
123
|
-
// What each installed package itself exports: a deep import of anything else is a private path.
|
|
124
|
-
const published = new Set(
|
|
125
|
-
["@abcart/storefront", "@abcart/theme"].flatMap((name) => {
|
|
126
|
-
const { exports } = JSON.parse(readFileSync(join(ROOT, "node_modules", name, "package.json"), "utf8")) as { exports: Record<string, unknown> };
|
|
127
|
-
return Object.keys(exports).filter((entry) => entry !== "./package.json").map((entry) => (entry === "." ? name : `${name}/${entry.slice(2)}`));
|
|
128
|
-
}),
|
|
129
|
-
);
|
|
130
|
-
expect(published).toContain("@abcart/theme/lifecycle");
|
|
131
|
-
const offenders = code.flatMap((file) =>
|
|
132
|
-
[...file.text.matchAll(/from\s+["'](@wocart\/[^"']+)["']|import\s+["'](@wocart\/[^"']+)["']/g)]
|
|
133
|
-
.map((match) => match[1] ?? match[2]!)
|
|
134
|
-
.filter((from) => !published.has(from))
|
|
135
|
-
.map((from) => `${file.path}: ${from}`),
|
|
136
|
-
);
|
|
137
|
-
expect(offenders).toEqual([]);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("builds every link to a platform page with storefrontPath, never by hand", () => {
|
|
141
|
-
const handWritten = [/`\/(products|category|pages|lp|collections)\/\$\{/, /["'`]\/(checkout|thank-you|track-order)["'`]/];
|
|
142
|
-
const offenders = code.flatMap((file) =>
|
|
143
|
-
file.text
|
|
144
|
-
.split("\n")
|
|
145
|
-
.map((line, index) => ({ line, at: `${file.path}:${index + 1}` }))
|
|
146
|
-
.filter(({ line }) => !/^\s*(\/\/|\/?\*)/.test(line) && handWritten.some((pattern) => pattern.test(line)))
|
|
147
|
-
.map(({ at, line }) => `${at} ${line.trim()}`),
|
|
148
|
-
);
|
|
149
|
-
expect(offenders).toEqual([]);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe("the design system", () => {
|
|
154
|
-
const BRAND_VALUES: [RegExp, string][] = [
|
|
155
|
-
[/#[0-9a-f]{3,8}\b/i, "a hex color"],
|
|
156
|
-
[/\b(?:rgba?|hsla?|oklch|oklab|lab|lch)\(/, "a color function"],
|
|
157
|
-
[/(?<![-\w.])(?:white|black)(?![-\w])/, "a named color"],
|
|
158
|
-
[/font-family:(?!\s*var\()/, "a font family"],
|
|
159
|
-
[/border-radius:(?![^;]*var\()[^;]*\d+px/, "a radius"],
|
|
160
|
-
[/box-shadow:(?![^;]*var\()[^;]*\d+px/, "a shadow"],
|
|
161
|
-
[/font-weight:\s*\d/, "a font weight"],
|
|
162
|
-
];
|
|
163
|
-
|
|
164
|
-
it("keeps every brand value in tokens.css, so restyling the theme is one file", () => {
|
|
165
|
-
const sheets = files.filter((file) => file.path.endsWith(".css") && file.path !== "styles/tokens.css");
|
|
166
|
-
expect(sheets.length).toBeGreaterThan(3);
|
|
167
|
-
const offenders = sheets.flatMap((file) =>
|
|
168
|
-
file.text
|
|
169
|
-
.replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, " "))
|
|
170
|
-
.replace(/url\("[^"]*"\)/g, "url()")
|
|
171
|
-
.split("\n")
|
|
172
|
-
.flatMap((line, index) => BRAND_VALUES.filter(([pattern]) => pattern.test(line)).map(([, what]) => `${file.path}:${index + 1} ${what}: ${line.trim()}`)),
|
|
173
|
-
);
|
|
174
|
-
expect(offenders).toEqual([]);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("lays out with logical properties, so right to left needs no rule of its own", () => {
|
|
178
|
-
// A physical side is right only where the rule names one direction or the side the WhatsApp App was set to.
|
|
179
|
-
const physical = /(?:^|[;{\s])(?:left|right)\s*:|(?:margin|padding|border)-(?:left|right)\b|(?:text-align|float|background-position)\s*:\s*(?:left|right)\b/;
|
|
180
|
-
const oneSide = /\[dir="(?:rtl|ltr)"\]|\[data-wa-side=|\[data-position=/;
|
|
181
|
-
const sheets = files.filter((file) => file.path.endsWith(".css"));
|
|
182
|
-
const offenders = sheets.flatMap((file) =>
|
|
183
|
-
[...file.text.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]+)\{([^{}]*)\}/g)]
|
|
184
|
-
.filter((rule) => physical.test(rule[2]!) && !oneSide.test(rule[1]!))
|
|
185
|
-
.map((rule) => `${file.path}: ${rule[1]!.trim().replace(/\s+/g, " ")}`),
|
|
186
|
-
);
|
|
187
|
-
expect(sheets.length).toBeGreaterThan(3);
|
|
188
|
-
expect(offenders).toEqual([]);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("styles components from the theme's stylesheets, never from a scoped <style> block", () => {
|
|
192
|
-
const scoped = code.filter((file) => file.path.endsWith(".astro") && /<style\b(?![^>]*is:inline)/.test(file.text)).map((file) => file.path);
|
|
193
|
-
expect(scoped).toEqual([]);
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
describe("what a shopper reads and loads", () => {
|
|
198
|
-
it("derives its colours on the SDK's scheme marker, never on a marker of its own", () => {
|
|
199
|
-
// schemeClass() always emits the marker; tokens derived on any other selector miss the merchant's colours.
|
|
200
|
-
const derivers = files
|
|
201
|
-
.filter((file) => file.path.endsWith(".css"))
|
|
202
|
-
.flatMap((file) =>
|
|
203
|
-
[...file.text.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]+)\{([^{}]*)\}/g)]
|
|
204
|
-
.filter((rule) => /--[\w-]+:\s*var\(--
|
|
205
|
-
.map((rule) => `${file.path}: ${rule[1]!.trim().replace(/\s+/g, " ")}`),
|
|
206
|
-
);
|
|
207
|
-
expect(derivers).toEqual([`styles/tokens.css: :root, .${SCHEME_MARKER_CLASS}`]);
|
|
208
|
-
expect(code.filter((file) => /\bschemeClass\(/.test(file.text)).length).toBeGreaterThanOrEqual(7);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("asks for no consent in a form: the store's legal pages are linked in the footer", () => {
|
|
212
|
-
const consent = /consent|توافق على|vous acceptez|you agree/i;
|
|
213
|
-
const copy = (["ar", "fr", "en"] as const).flatMap((locale) => Object.entries(content[locale]).filter(([key, text]) => consent.test(key) || consent.test(text)).map(([key]) => `${locale}: ${key}`));
|
|
214
|
-
expect([...copy, ...code.filter((file) => !file.path.startsWith("theme/content/") && consent.test(file.text)).map((file) => file.path)]).toEqual([]);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("self-hosts two font families, each file used, licensed and preloaded for its direction", () => {
|
|
218
|
-
const tokens = files.find((file) => file.path === "styles/tokens.css")!.text;
|
|
219
|
-
const faces = [...tokens.matchAll(/@font-face\s*\{[^}]*font-family:\s*"([^"]+)"[^}]*url\("\/fonts\/([^"]+)"\)[^}]*unicode-range:/g)].map((match) => ({ family: match[1]!, file: match[2]! }));
|
|
220
|
-
expect(new Set(faces.map((face) => face.family)).size).toBe(2);
|
|
221
|
-
const fontDir = join(ROOT, "public/fonts");
|
|
222
|
-
const shipped = readdirSync(fontDir).filter((name) => name.endsWith(".woff2"));
|
|
223
|
-
expect(shipped.sort()).toEqual(faces.map((face) => face.file).sort());
|
|
224
|
-
const license = readFileSync(join(fontDir, "OFL.txt"), "utf8");
|
|
225
|
-
expect(shipped.filter((name) => !license.includes(name))).toEqual([]);
|
|
226
|
-
const layout = files.find((file) => file.path === "layouts/StoreLayout.astro")!.text;
|
|
227
|
-
const preload = /\{isRTL \? \(\s*<link rel="preload" href="\/fonts\/([^"]+)"[^>]*\/>\s*\) : \(\s*<link rel="preload" href="\/fonts\/([^"]+)"/.exec(layout);
|
|
228
|
-
expect(preload?.slice(1)).toEqual([expect.stringMatching(/arabic/), expect.stringMatching(/latin/)]);
|
|
229
|
-
expect(preload!.slice(1).every((file) => shipped.includes(file))).toBe(true);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("loads no font from a third party", () => {
|
|
233
|
-
const thirdParty = /fonts\.googleapis\.com|fonts\.gstatic\.com|use\.typekit\.net|fonts\.bunny\.net/;
|
|
234
|
-
expect(files.filter((file) => thirdParty.test(file.text)).map((file) => file.path)).toEqual([]);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it("writes no visible or spoken text in the markup: it comes from the copy", () => {
|
|
238
|
-
const literal = /\b(aria-label|alt|title|placeholder)="[A-Za-z][^"{]*"/g;
|
|
239
|
-
const offenders = code
|
|
240
|
-
.filter((file) => file.path.endsWith(".astro"))
|
|
241
|
-
.flatMap((file) => [...file.text.matchAll(literal)].map((match) => `${file.path}: ${match[0]}`));
|
|
242
|
-
expect(offenders).toEqual([]);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it("points every label at a field that exists in the same component", () => {
|
|
246
|
-
const broken = code
|
|
247
|
-
.filter((file) => file.path.endsWith(".astro"))
|
|
248
|
-
.flatMap((file) =>
|
|
249
|
-
[...file.text.matchAll(/<label\b[^>]*\bfor="([^"]+)"/g)]
|
|
250
|
-
.map((match) => match[1]!)
|
|
251
|
-
.filter((target) => !new RegExp(`\\bid="${target}"`).test(file.text))
|
|
252
|
-
.map((target) => `${file.path} → ${target}`),
|
|
253
|
-
);
|
|
254
|
-
expect(broken).toEqual([]);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
it("names nothing in the editor that no field shows: every editor label is used", () => {
|
|
259
|
-
const labels = files.find((file) => file.path === "theme/labels.ts")!.text;
|
|
260
|
-
const source = code.filter((file) => file.path !== "theme/labels.ts").map((file) => file.text).join("\n");
|
|
261
|
-
const unused = [...labels.matchAll(/export const (\w+) = \{([\s\S]*?)\n\};/g)]
|
|
262
|
-
.filter(([, group]) => !new RegExp(`Object\\.keys\\(${group}\\)`).test(source))
|
|
263
|
-
.flatMap(([, group, body]) => [...body!.matchAll(/^ {2}(\w+):/gm)].map(([, key]) => `${group}.${key}`))
|
|
264
|
-
.filter((name) => !new RegExp(`\\b${name.replace(".", "\\.")}\\b`).test(source));
|
|
265
|
-
expect(unused).toEqual([]);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
describe("the store's WhatsApp", () => {
|
|
271
|
-
it("is reached one way: every link comes from the SDK through the theme's one binding", () => {
|
|
272
|
-
const binding = "lib/whatsapp.ts";
|
|
273
|
-
const of = (test: (text: string) => boolean) => code.filter((file) => test(file.text)).map((file) => file.path).sort();
|
|
274
|
-
expect(of((text) => text.includes("storeWhatsApp(")).length).toBeGreaterThan(3);
|
|
275
|
-
expect(of((text) => text.includes("whatsAppContact("))).toEqual([binding]);
|
|
276
|
-
expect(of((text) => /wa\.me|api\.whatsapp\.com|\?text=/.test(text))).toEqual([]);
|
|
277
|
-
expect(of((text) => text.includes("config.whatsapp"))).toEqual([]);
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it("never writes a platform page's path by hand: contact, search and order tracking come from storefrontPath", () => {
|
|
281
|
-
expect(code.filter((file) => /["'`]\/(contact|search|track-order)["'`?]/.test(file.text)).map((file) => file.path)).toEqual([]);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
describe("where the theme runs", () => {
|
|
286
|
-
it("builds for Cloudflare Workers and for Vercel, so
|
|
287
|
-
const pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8")) as { scripts: Record<string, string>; dependencies: Record<string, string> };
|
|
288
|
-
expect(pkg.scripts.build).toBe("astro build");
|
|
289
|
-
expect(pkg.scripts["build:vercel"]).toBe("DEPLOY_TARGET=vercel astro build");
|
|
290
|
-
expect(Object.keys(pkg.dependencies)).toEqual(expect.arrayContaining(["@astrojs/cloudflare", "@astrojs/vercel"]));
|
|
291
|
-
const config = readFileSync(join(ROOT, "astro.config.mjs"), "utf8");
|
|
292
|
-
expect(config).toMatch(/cloudflare: async \(\) =>[\s\S]*@astrojs\/cloudflare"\)\)\.default/);
|
|
293
|
-
expect(config).toMatch(/vercel: async \(\) =>[\s\S]*@astrojs\/vercel"\)\)\.default/);
|
|
294
|
-
expect(config).toMatch(/process\.env\.DEPLOY_TARGET \|\| "cloudflare"/);
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
describe("colour and section style", () => {
|
|
299
|
-
const ALLOWED = new Set(["styles/tokens.css", "theme/palette.ts"]);
|
|
300
|
-
const COLOUR: [RegExp, string][] = [
|
|
301
|
-
[/(?<![\w&-])#[0-9a-fA-F]{3,8}(?![\w-])/, "a hex colour"],
|
|
302
|
-
[/%23[0-9a-fA-F]{3,8}/, "a hex colour in a data URI"],
|
|
303
|
-
[/\b(?:rgba?|hsla?|oklch|oklab|lab|lch)\(/, "a colour function"],
|
|
304
|
-
[/\b(?:fill|stroke|stop-color)(?:=|:)\s*["']?(?!none\b|currentColor|inherit|transparent)[a-zA-Z]/, "a named SVG paint"],
|
|
305
|
-
];
|
|
306
|
-
|
|
307
|
-
it("holds no colour outside the tokens and the palette: a colour is a token, or a value of palette.ts", () => {
|
|
308
|
-
expect(files.length).toBeGreaterThan(80);
|
|
309
|
-
const offenders = files
|
|
310
|
-
.filter((file) => !ALLOWED.has(file.path))
|
|
311
|
-
.flatMap((file) =>
|
|
312
|
-
file.text.split("\n").flatMap((line, index) =>
|
|
313
|
-
COLOUR.filter(([pattern]) => pattern.test(line)).map(([, what]) => `${file.path}:${index + 1} ${what}: ${line.trim().slice(0, 100)}`),
|
|
314
|
-
),
|
|
315
|
-
);
|
|
316
|
-
expect(offenders).toEqual([]);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
it("gives every section a colour scheme and a style, and draws it inside the shared frame", () => {
|
|
320
|
-
const definitions = files.filter((file) => file.path.startsWith("theme/sections/") && file.path.endsWith(".ts"));
|
|
321
|
-
const offenders: string[] = [];
|
|
322
|
-
let checked = 0;
|
|
323
|
-
for (const file of definitions) {
|
|
324
|
-
const components = new Map([...file.text.matchAll(/import (\w+)(?:,\s*\{[^}]*\})? from "(@\/components\/[^"]+\.astro)"/g)].map((match) => [match[1]!, match[2]!]));
|
|
325
|
-
for (const block of file.text.split("defineComponent({").slice(1)) {
|
|
326
|
-
if (!/placement: "section"/.test(block) || /"area:/.test(block)) continue;
|
|
327
|
-
checked++;
|
|
328
|
-
const type = /type: "([\w-]+)"/.exec(block)?.[1] ?? "?";
|
|
329
|
-
const path = components.get(/component: (\w+)/.exec(block)?.[1] ?? "");
|
|
330
|
-
const source = path ? code.find((candidate) => candidate.path === path.replace(/^@\//, ""))?.text ?? "" : "";
|
|
331
|
-
if (!path) offenders.push(`${type}: no component import`);
|
|
332
|
-
if (!/schemeField\(|key: "scheme"/.test(block)) offenders.push(`${type}: no colour scheme field`);
|
|
333
|
-
if (!/styleField\(|key: "style"/.test(block)) offenders.push(`${type}: no style field`);
|
|
334
|
-
if (!source.includes('"@/components/ui/Section.astro"')) offenders.push(`${type}: does not render through Section.astro`);
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
expect(checked).toBeGreaterThan(15);
|
|
338
|
-
expect(offenders).toEqual([]);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Source guards: rules every theme keeps, checked on the shipped source under
|
|
3
|
+
* `src/` (tests and build output left out). One walker, so every guard agrees
|
|
4
|
+
* on what "the theme" is; each first proves it found something to check.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from "vitest";
|
|
7
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { SCHEME_MARKER_CLASS } from "@abcart/theme";
|
|
10
|
+
import { STOREFRONT_API_PATHS } from "@abcart/storefront";
|
|
11
|
+
import { content } from "../../src/theme/content";
|
|
12
|
+
import { ROOT, browserModuleGraph, code, files, runtimeImports } from "./source";
|
|
13
|
+
|
|
14
|
+
describe("the theme's browser code", () => {
|
|
15
|
+
const graph = browserModuleGraph();
|
|
16
|
+
|
|
17
|
+
it("is found, so these guards check something", () => {
|
|
18
|
+
expect([...graph.keys()]).toEqual(expect.arrayContaining(["scripts/order-form.ts", "scripts/cart.ts", "scripts/product.ts", "lib/coupon-notice.ts"]));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("imports no schema and nothing from Zod: the server checked the data", () => {
|
|
22
|
+
const offenders = [...graph.values()].flatMap((file) =>
|
|
23
|
+
runtimeImports(file.text).flatMap(({ from, names }) => [
|
|
24
|
+
...(from === "zod" || from.startsWith("zod/") ? [`${file.path}: zod`] : []),
|
|
25
|
+
...(from.startsWith("@abcart/") || from.startsWith("@wocart/") ? names.filter((name) => /Schema\b/.test(name)).map((name) => `${file.path}: ${name}`) : []),
|
|
26
|
+
]),
|
|
27
|
+
);
|
|
28
|
+
expect(offenders).toEqual([]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("never reaches a server-only module, so the API key cannot ship", () => {
|
|
32
|
+
const serverOnly = /^(astro:env\/server|astro:actions|@(?:abcart|wocart)\/storefront\/(server|astro)|@\/lib\/(store|env)(\.ts)?)$/;
|
|
33
|
+
const offenders = [...graph.values()].flatMap((file) =>
|
|
34
|
+
runtimeImports(file.text).filter(({ from }) => serverOnly.test(from)).map(({ from }) => `${file.path} → ${from}`),
|
|
35
|
+
);
|
|
36
|
+
expect(offenders).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("takes from @abcart/theme only its browser entries: the lifecycle and the messages", () => {
|
|
40
|
+
const offenders = [...graph.values()].flatMap((file) =>
|
|
41
|
+
runtimeImports(file.text)
|
|
42
|
+
.filter(({ from }) => from.startsWith("@abcart/theme") && !["@abcart/theme/lifecycle", "@abcart/theme/messages"].includes(from))
|
|
43
|
+
.filter(({ from }) => !(from === "@abcart/theme/preview" && file.path.startsWith("components/surface/PreviewBridge")))
|
|
44
|
+
.map(({ from }) => `${file.path} → ${from}`),
|
|
45
|
+
);
|
|
46
|
+
expect(offenders).toEqual([]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("never ships the editor's bridge to a shopper's page", () => {
|
|
50
|
+
const shipsBridge = [...graph.values()].filter((file) => !file.path.startsWith("components/surface/PreviewBridge") && runtimeImports(file.text).some(({ from }) => from === "@abcart/theme/preview")).map((file) => file.path);
|
|
51
|
+
expect(shipsBridge).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("binds every behaviour through the SDK's lifecycle, so the editor's preview can swap a section or the page", () => {
|
|
55
|
+
// A script that finds its elements once at load would stay bound to markup the preview replaced.
|
|
56
|
+
const scripts = code.filter((file) => file.path.startsWith("scripts/") && !file.path.startsWith("scripts/checkout/") && !["scripts/events.ts", "scripts/public-config.ts", "scripts/cart.ts"].includes(file.path));
|
|
57
|
+
expect(scripts.length).toBeGreaterThanOrEqual(5);
|
|
58
|
+
const unbound = scripts.filter((file) => !runtimeImports(file.text).some(({ from, names }) => from === "@abcart/theme/lifecycle" && names.includes("bindEach"))).map((file) => file.path);
|
|
59
|
+
expect(unbound).toEqual([]);
|
|
60
|
+
// The swap events are the SDK's to name: a theme that listens for them itself has a second lifecycle.
|
|
61
|
+
const ownLifecycle = code.filter((file) => /["'](?:abcart:section-load|wocart:section-load|astro:page-load|astro:before-swap)["']/.test(file.text)).map((file) => file.path);
|
|
62
|
+
expect(ownLifecycle).toEqual([]);
|
|
63
|
+
const cart = code.find((file) => file.path === "scripts/cart.ts")!;
|
|
64
|
+
expect(cart.text).not.toMatch(/^const \w+ = document\.querySelector/m);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("binds the order form's parts from its one entry: no part binds itself or touches the page on load", () => {
|
|
68
|
+
const parts = code.filter((file) => file.path.startsWith("scripts/checkout/"));
|
|
69
|
+
expect(parts.map((file) => file.path.replace("scripts/checkout/", "")).sort()).toEqual(expect.arrayContaining(["coupon.ts", "delivery.ts", "otp.ts", "quote.ts", "submit.ts"]));
|
|
70
|
+
const entry = code.find((file) => file.path === "scripts/order-form.ts")!.text;
|
|
71
|
+
expect(parts.filter((file) => !entry.includes(`"./checkout/${file.path.replace("scripts/checkout/", "").replace(/\.ts$/, "")}"`)).map((file) => file.path)).toEqual([]);
|
|
72
|
+
expect(parts.filter((file) => runtimeImports(file.text).some(({ names }) => names.includes("bindEach") || names.includes("onEachPage"))).map((file) => file.path)).toEqual([]);
|
|
73
|
+
const onLoad = parts.flatMap((file) => file.text.split("\n").map((line, index) => ({ line, at: `${file.path}:${index + 1}` })).filter(({ line }) => /^(?![\s/*}]).*\b(document|window)\.(querySelector|addEventListener|location)/.test(line)).map(({ at }) => at));
|
|
74
|
+
expect(onLoad).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("gives every order form its checkout key, so a refresh or a retry places no second order", () => {
|
|
78
|
+
const orderForms = code.filter((file) => /<form\b[^>]*action=\{actions\.placeOrder\}/.test(file.text));
|
|
79
|
+
expect(orderForms.map((file) => file.path)).toEqual(["components/checkout/OrderForm.astro"]);
|
|
80
|
+
expect(orderForms[0]!.text).toMatch(/<form\b[^>]*\bdata-order-form\b/);
|
|
81
|
+
const orderForm = code.find((file) => file.path === "scripts/order-form.ts")!;
|
|
82
|
+
expect(orderForm.text).toMatch(/bindEach<HTMLFormElement>\("\[data-order-form\]", initForm\)/);
|
|
83
|
+
expect(orderForm.text).toMatch(/function initForm\(form: HTMLFormElement\) \{\n(?:\s*\/\/.*\n)*\s*const unbindCheckoutKey = bindCheckoutKey\(form\);/);
|
|
84
|
+
// Every way out of initForm hands back the cleanup that unbinds the key.
|
|
85
|
+
expect(orderForm.text).toMatch(/const cleanups: Cleanup\[\] = \[unbindCheckoutKey(?:, [^\]]+)?\];/);
|
|
86
|
+
const body = orderForm.text.slice(orderForm.text.indexOf("function initForm("));
|
|
87
|
+
const returns = [...body.matchAll(/\breturn\b[^;\n]*/g)].map((match) => match[0]).filter((statement) => !/^return window\.location/.test(statement));
|
|
88
|
+
expect(returns.length).toBeGreaterThanOrEqual(2);
|
|
89
|
+
expect(returns.every((statement) => statement === "return () => cleanups.forEach((cleanup) => cleanup())")).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("the SDK boundary", () => {
|
|
94
|
+
it("answers a missing product, category, collection, page or landing page through the SDK's notFound, never cached", () => {
|
|
95
|
+
const routes = ["pages/products/[handle].astro", "pages/category/[slug].astro", "pages/collections/[handle].astro", "pages/pages/[slug].astro", "pages/lp/[slug].astro"];
|
|
96
|
+
for (const route of routes) expect(code.find((file) => file.path === route)?.text, route).toMatch(/return notFound\(Astro\);/);
|
|
97
|
+
const handRolled = code.filter((file) => file.path.startsWith("pages/") && file.path !== "pages/404.astro" && /rewrite\(["']\/404["']\)|cache\.set\(false\)/.test(file.text)).map((file) => file.path);
|
|
98
|
+
expect(handRolled).toEqual([]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("mounts a route file at every API path the browser calls, and none it does not", () => {
|
|
102
|
+
// The SDK's `:wilayaId` is Astro's `[wilayaId]`: each path names exactly one route file.
|
|
103
|
+
const routeFiles = files.filter((file) => file.path.startsWith("pages/api/")).map((file) => `/${file.path.replace(/^pages\//, "").replace(/\.ts$/, "")}`);
|
|
104
|
+
const expected = Object.values(STOREFRONT_API_PATHS).map((path) => path.replace(/:(\w+)/g, "[$1]"));
|
|
105
|
+
expect(expected.filter((path) => !routeFiles.includes(path))).toEqual([]);
|
|
106
|
+
expect(routeFiles.filter((route) => !expected.includes(route))).toEqual([]);
|
|
107
|
+
const ownTables = code.filter((file) => /["'`]\/api\//.test(file.text) && !file.path.startsWith("pages/api/")).map((file) => file.path);
|
|
108
|
+
expect(ownTables).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("creates SDK clients in one place only", () => {
|
|
112
|
+
const creators = code.filter((file) => /\bcreateStoreClient\s*\(/.test(file.text)).map((file) => file.path);
|
|
113
|
+
expect(creators).toEqual(["lib/store.ts"]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("shows a store it cannot read through the SDK's unavailable store, built in one place", () => {
|
|
117
|
+
const fallbacks = code.filter((file) => /\bunavailableStoreConfig\s*\(/.test(file.text)).map((file) => file.path);
|
|
118
|
+
expect(fallbacks).toEqual(["middleware.ts"]);
|
|
119
|
+
expect(code.find((file) => file.path === "middleware.ts")!.text).toMatch(/fallback: unavailableStoreConfig\(/);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("imports the SDKs through their published entry points only", () => {
|
|
123
|
+
// What each installed package itself exports: a deep import of anything else is a private path.
|
|
124
|
+
const published = new Set(
|
|
125
|
+
["@abcart/storefront", "@abcart/theme"].flatMap((name) => {
|
|
126
|
+
const { exports } = JSON.parse(readFileSync(join(ROOT, "node_modules", name, "package.json"), "utf8")) as { exports: Record<string, unknown> };
|
|
127
|
+
return Object.keys(exports).filter((entry) => entry !== "./package.json").map((entry) => (entry === "." ? name : `${name}/${entry.slice(2)}`));
|
|
128
|
+
}),
|
|
129
|
+
);
|
|
130
|
+
expect(published).toContain("@abcart/theme/lifecycle");
|
|
131
|
+
const offenders = code.flatMap((file) =>
|
|
132
|
+
[...file.text.matchAll(/from\s+["'](@(?:abcart|wocart)\/[^"']+)["']|import\s+["'](@(?:abcart|wocart)\/[^"']+)["']/g)]
|
|
133
|
+
.map((match) => match[1] ?? match[2]!)
|
|
134
|
+
.filter((from) => !published.has(from))
|
|
135
|
+
.map((from) => `${file.path}: ${from}`),
|
|
136
|
+
);
|
|
137
|
+
expect(offenders).toEqual([]);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("builds every link to a platform page with storefrontPath, never by hand", () => {
|
|
141
|
+
const handWritten = [/`\/(products|category|pages|lp|collections)\/\$\{/, /["'`]\/(checkout|thank-you|track-order)["'`]/];
|
|
142
|
+
const offenders = code.flatMap((file) =>
|
|
143
|
+
file.text
|
|
144
|
+
.split("\n")
|
|
145
|
+
.map((line, index) => ({ line, at: `${file.path}:${index + 1}` }))
|
|
146
|
+
.filter(({ line }) => !/^\s*(\/\/|\/?\*)/.test(line) && handWritten.some((pattern) => pattern.test(line)))
|
|
147
|
+
.map(({ at, line }) => `${at} ${line.trim()}`),
|
|
148
|
+
);
|
|
149
|
+
expect(offenders).toEqual([]);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("the design system", () => {
|
|
154
|
+
const BRAND_VALUES: [RegExp, string][] = [
|
|
155
|
+
[/#[0-9a-f]{3,8}\b/i, "a hex color"],
|
|
156
|
+
[/\b(?:rgba?|hsla?|oklch|oklab|lab|lch)\(/, "a color function"],
|
|
157
|
+
[/(?<![-\w.])(?:white|black)(?![-\w])/, "a named color"],
|
|
158
|
+
[/font-family:(?!\s*var\()/, "a font family"],
|
|
159
|
+
[/border-radius:(?![^;]*var\()[^;]*\d+px/, "a radius"],
|
|
160
|
+
[/box-shadow:(?![^;]*var\()[^;]*\d+px/, "a shadow"],
|
|
161
|
+
[/font-weight:\s*\d/, "a font weight"],
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
it("keeps every brand value in tokens.css, so restyling the theme is one file", () => {
|
|
165
|
+
const sheets = files.filter((file) => file.path.endsWith(".css") && file.path !== "styles/tokens.css");
|
|
166
|
+
expect(sheets.length).toBeGreaterThan(3);
|
|
167
|
+
const offenders = sheets.flatMap((file) =>
|
|
168
|
+
file.text
|
|
169
|
+
.replace(/\/\*[\s\S]*?\*\//g, (comment) => comment.replace(/[^\n]/g, " "))
|
|
170
|
+
.replace(/url\("[^"]*"\)/g, "url()")
|
|
171
|
+
.split("\n")
|
|
172
|
+
.flatMap((line, index) => BRAND_VALUES.filter(([pattern]) => pattern.test(line)).map(([, what]) => `${file.path}:${index + 1} ${what}: ${line.trim()}`)),
|
|
173
|
+
);
|
|
174
|
+
expect(offenders).toEqual([]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("lays out with logical properties, so right to left needs no rule of its own", () => {
|
|
178
|
+
// A physical side is right only where the rule names one direction or the side the WhatsApp App was set to.
|
|
179
|
+
const physical = /(?:^|[;{\s])(?:left|right)\s*:|(?:margin|padding|border)-(?:left|right)\b|(?:text-align|float|background-position)\s*:\s*(?:left|right)\b/;
|
|
180
|
+
const oneSide = /\[dir="(?:rtl|ltr)"\]|\[data-wa-side=|\[data-position=/;
|
|
181
|
+
const sheets = files.filter((file) => file.path.endsWith(".css"));
|
|
182
|
+
const offenders = sheets.flatMap((file) =>
|
|
183
|
+
[...file.text.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]+)\{([^{}]*)\}/g)]
|
|
184
|
+
.filter((rule) => physical.test(rule[2]!) && !oneSide.test(rule[1]!))
|
|
185
|
+
.map((rule) => `${file.path}: ${rule[1]!.trim().replace(/\s+/g, " ")}`),
|
|
186
|
+
);
|
|
187
|
+
expect(sheets.length).toBeGreaterThan(3);
|
|
188
|
+
expect(offenders).toEqual([]);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("styles components from the theme's stylesheets, never from a scoped <style> block", () => {
|
|
192
|
+
const scoped = code.filter((file) => file.path.endsWith(".astro") && /<style\b(?![^>]*is:inline)/.test(file.text)).map((file) => file.path);
|
|
193
|
+
expect(scoped).toEqual([]);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("what a shopper reads and loads", () => {
|
|
198
|
+
it("derives its colours on the SDK's scheme marker, never on a marker of its own", () => {
|
|
199
|
+
// schemeClass() always emits the marker; tokens derived on any other selector miss the merchant's colours.
|
|
200
|
+
const derivers = files
|
|
201
|
+
.filter((file) => file.path.endsWith(".css"))
|
|
202
|
+
.flatMap((file) =>
|
|
203
|
+
[...file.text.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/([^{}]+)\{([^{}]*)\}/g)]
|
|
204
|
+
.filter((rule) => /--[\w-]+:\s*var\(--ab-color-/.test(rule[2]!))
|
|
205
|
+
.map((rule) => `${file.path}: ${rule[1]!.trim().replace(/\s+/g, " ")}`),
|
|
206
|
+
);
|
|
207
|
+
expect(derivers).toEqual([`styles/tokens.css: :root, .${SCHEME_MARKER_CLASS}`]);
|
|
208
|
+
expect(code.filter((file) => /\bschemeClass\(/.test(file.text)).length).toBeGreaterThanOrEqual(7);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("asks for no consent in a form: the store's legal pages are linked in the footer", () => {
|
|
212
|
+
const consent = /consent|توافق على|vous acceptez|you agree/i;
|
|
213
|
+
const copy = (["ar", "fr", "en"] as const).flatMap((locale) => Object.entries(content[locale]).filter(([key, text]) => consent.test(key) || consent.test(text)).map(([key]) => `${locale}: ${key}`));
|
|
214
|
+
expect([...copy, ...code.filter((file) => !file.path.startsWith("theme/content/") && consent.test(file.text)).map((file) => file.path)]).toEqual([]);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("self-hosts two font families, each file used, licensed and preloaded for its direction", () => {
|
|
218
|
+
const tokens = files.find((file) => file.path === "styles/tokens.css")!.text;
|
|
219
|
+
const faces = [...tokens.matchAll(/@font-face\s*\{[^}]*font-family:\s*"([^"]+)"[^}]*url\("\/fonts\/([^"]+)"\)[^}]*unicode-range:/g)].map((match) => ({ family: match[1]!, file: match[2]! }));
|
|
220
|
+
expect(new Set(faces.map((face) => face.family)).size).toBe(2);
|
|
221
|
+
const fontDir = join(ROOT, "public/fonts");
|
|
222
|
+
const shipped = readdirSync(fontDir).filter((name) => name.endsWith(".woff2"));
|
|
223
|
+
expect(shipped.sort()).toEqual(faces.map((face) => face.file).sort());
|
|
224
|
+
const license = readFileSync(join(fontDir, "OFL.txt"), "utf8");
|
|
225
|
+
expect(shipped.filter((name) => !license.includes(name))).toEqual([]);
|
|
226
|
+
const layout = files.find((file) => file.path === "layouts/StoreLayout.astro")!.text;
|
|
227
|
+
const preload = /\{isRTL \? \(\s*<link rel="preload" href="\/fonts\/([^"]+)"[^>]*\/>\s*\) : \(\s*<link rel="preload" href="\/fonts\/([^"]+)"/.exec(layout);
|
|
228
|
+
expect(preload?.slice(1)).toEqual([expect.stringMatching(/arabic/), expect.stringMatching(/latin/)]);
|
|
229
|
+
expect(preload!.slice(1).every((file) => shipped.includes(file))).toBe(true);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("loads no font from a third party", () => {
|
|
233
|
+
const thirdParty = /fonts\.googleapis\.com|fonts\.gstatic\.com|use\.typekit\.net|fonts\.bunny\.net/;
|
|
234
|
+
expect(files.filter((file) => thirdParty.test(file.text)).map((file) => file.path)).toEqual([]);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("writes no visible or spoken text in the markup: it comes from the copy", () => {
|
|
238
|
+
const literal = /\b(aria-label|alt|title|placeholder)="[A-Za-z][^"{]*"/g;
|
|
239
|
+
const offenders = code
|
|
240
|
+
.filter((file) => file.path.endsWith(".astro"))
|
|
241
|
+
.flatMap((file) => [...file.text.matchAll(literal)].map((match) => `${file.path}: ${match[0]}`));
|
|
242
|
+
expect(offenders).toEqual([]);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("points every label at a field that exists in the same component", () => {
|
|
246
|
+
const broken = code
|
|
247
|
+
.filter((file) => file.path.endsWith(".astro"))
|
|
248
|
+
.flatMap((file) =>
|
|
249
|
+
[...file.text.matchAll(/<label\b[^>]*\bfor="([^"]+)"/g)]
|
|
250
|
+
.map((match) => match[1]!)
|
|
251
|
+
.filter((target) => !new RegExp(`\\bid="${target}"`).test(file.text))
|
|
252
|
+
.map((target) => `${file.path} → ${target}`),
|
|
253
|
+
);
|
|
254
|
+
expect(broken).toEqual([]);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
it("names nothing in the editor that no field shows: every editor label is used", () => {
|
|
259
|
+
const labels = files.find((file) => file.path === "theme/labels.ts")!.text;
|
|
260
|
+
const source = code.filter((file) => file.path !== "theme/labels.ts").map((file) => file.text).join("\n");
|
|
261
|
+
const unused = [...labels.matchAll(/export const (\w+) = \{([\s\S]*?)\n\};/g)]
|
|
262
|
+
.filter(([, group]) => !new RegExp(`Object\\.keys\\(${group}\\)`).test(source))
|
|
263
|
+
.flatMap(([, group, body]) => [...body!.matchAll(/^ {2}(\w+):/gm)].map(([, key]) => `${group}.${key}`))
|
|
264
|
+
.filter((name) => !new RegExp(`\\b${name.replace(".", "\\.")}\\b`).test(source));
|
|
265
|
+
expect(unused).toEqual([]);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe("the store's WhatsApp", () => {
|
|
271
|
+
it("is reached one way: every link comes from the SDK through the theme's one binding", () => {
|
|
272
|
+
const binding = "lib/whatsapp.ts";
|
|
273
|
+
const of = (test: (text: string) => boolean) => code.filter((file) => test(file.text)).map((file) => file.path).sort();
|
|
274
|
+
expect(of((text) => text.includes("storeWhatsApp(")).length).toBeGreaterThan(3);
|
|
275
|
+
expect(of((text) => text.includes("whatsAppContact("))).toEqual([binding]);
|
|
276
|
+
expect(of((text) => /wa\.me|api\.whatsapp\.com|\?text=/.test(text))).toEqual([]);
|
|
277
|
+
expect(of((text) => text.includes("config.whatsapp"))).toEqual([]);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("never writes a platform page's path by hand: contact, search and order tracking come from storefrontPath", () => {
|
|
281
|
+
expect(code.filter((file) => /["'`]\/(contact|search|track-order)["'`?]/.test(file.text)).map((file) => file.path)).toEqual([]);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
describe("where the theme runs", () => {
|
|
286
|
+
it("builds for Cloudflare Workers and for Vercel, so AbCart Cloud can deploy it on the host a merchant picks", () => {
|
|
287
|
+
const pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8")) as { scripts: Record<string, string>; dependencies: Record<string, string> };
|
|
288
|
+
expect(pkg.scripts.build).toBe("astro build");
|
|
289
|
+
expect(pkg.scripts["build:vercel"]).toBe("DEPLOY_TARGET=vercel astro build");
|
|
290
|
+
expect(Object.keys(pkg.dependencies)).toEqual(expect.arrayContaining(["@astrojs/cloudflare", "@astrojs/vercel"]));
|
|
291
|
+
const config = readFileSync(join(ROOT, "astro.config.mjs"), "utf8");
|
|
292
|
+
expect(config).toMatch(/cloudflare: async \(\) =>[\s\S]*@astrojs\/cloudflare"\)\)\.default/);
|
|
293
|
+
expect(config).toMatch(/vercel: async \(\) =>[\s\S]*@astrojs\/vercel"\)\)\.default/);
|
|
294
|
+
expect(config).toMatch(/process\.env\.DEPLOY_TARGET \|\| "cloudflare"/);
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
describe("colour and section style", () => {
|
|
299
|
+
const ALLOWED = new Set(["styles/tokens.css", "theme/palette.ts"]);
|
|
300
|
+
const COLOUR: [RegExp, string][] = [
|
|
301
|
+
[/(?<![\w&-])#[0-9a-fA-F]{3,8}(?![\w-])/, "a hex colour"],
|
|
302
|
+
[/%23[0-9a-fA-F]{3,8}/, "a hex colour in a data URI"],
|
|
303
|
+
[/\b(?:rgba?|hsla?|oklch|oklab|lab|lch)\(/, "a colour function"],
|
|
304
|
+
[/\b(?:fill|stroke|stop-color)(?:=|:)\s*["']?(?!none\b|currentColor|inherit|transparent)[a-zA-Z]/, "a named SVG paint"],
|
|
305
|
+
];
|
|
306
|
+
|
|
307
|
+
it("holds no colour outside the tokens and the palette: a colour is a token, or a value of palette.ts", () => {
|
|
308
|
+
expect(files.length).toBeGreaterThan(80);
|
|
309
|
+
const offenders = files
|
|
310
|
+
.filter((file) => !ALLOWED.has(file.path))
|
|
311
|
+
.flatMap((file) =>
|
|
312
|
+
file.text.split("\n").flatMap((line, index) =>
|
|
313
|
+
COLOUR.filter(([pattern]) => pattern.test(line)).map(([, what]) => `${file.path}:${index + 1} ${what}: ${line.trim().slice(0, 100)}`),
|
|
314
|
+
),
|
|
315
|
+
);
|
|
316
|
+
expect(offenders).toEqual([]);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("gives every section a colour scheme and a style, and draws it inside the shared frame", () => {
|
|
320
|
+
const definitions = files.filter((file) => file.path.startsWith("theme/sections/") && file.path.endsWith(".ts"));
|
|
321
|
+
const offenders: string[] = [];
|
|
322
|
+
let checked = 0;
|
|
323
|
+
for (const file of definitions) {
|
|
324
|
+
const components = new Map([...file.text.matchAll(/import (\w+)(?:,\s*\{[^}]*\})? from "(@\/components\/[^"]+\.astro)"/g)].map((match) => [match[1]!, match[2]!]));
|
|
325
|
+
for (const block of file.text.split("defineComponent({").slice(1)) {
|
|
326
|
+
if (!/placement: "section"/.test(block) || /"area:/.test(block)) continue;
|
|
327
|
+
checked++;
|
|
328
|
+
const type = /type: "([\w-]+)"/.exec(block)?.[1] ?? "?";
|
|
329
|
+
const path = components.get(/component: (\w+)/.exec(block)?.[1] ?? "");
|
|
330
|
+
const source = path ? code.find((candidate) => candidate.path === path.replace(/^@\//, ""))?.text ?? "" : "";
|
|
331
|
+
if (!path) offenders.push(`${type}: no component import`);
|
|
332
|
+
if (!/schemeField\(|key: "scheme"/.test(block)) offenders.push(`${type}: no colour scheme field`);
|
|
333
|
+
if (!/styleField\(|key: "style"/.test(block)) offenders.push(`${type}: no style field`);
|
|
334
|
+
if (!source.includes('"@/components/ui/Section.astro"')) offenders.push(`${type}: does not render through Section.astro`);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
expect(checked).toBeGreaterThan(15);
|
|
338
|
+
expect(offenders).toEqual([]);
|
|
339
|
+
});
|
|
340
|
+
});
|