@decocms/blocks 8.0.0 → 8.1.0-next.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/bin/deco.js +13 -0
- package/package.json +39 -3
- package/src/cms/applySectionConventions.ts +26 -2
- package/src/cms/blockSource.ts +37 -0
- package/src/cms/client.ts +5 -0
- package/src/cms/deferredTrigger.ts +58 -0
- package/src/cms/draftSource.ts +171 -57
- package/src/cms/index.ts +32 -3
- package/src/cms/loader.ts +318 -59
- package/src/cms/registry.ts +22 -0
- package/src/cms/renderJson.ts +179 -0
- package/src/cms/resolve.ts +396 -95
- package/src/cms/schema.ts +9 -5
- package/src/cms/sectionLoaders.ts +106 -56
- package/src/hooks/Image.tsx +70 -6
- package/src/hooks/LiveControls.tsx +30 -8
- package/src/hooks/Stats.tsx +134 -0
- package/src/hooks/index.ts +5 -0
- package/src/hooks/useLoadMore.ts +100 -0
- package/src/index.ts +37 -0
- package/src/middleware/observability.ts +173 -16
- package/src/preview/DraftPreviewBadge.tsx +306 -0
- package/src/preview/decoMark.ts +11 -0
- package/src/preview/index.ts +8 -0
- package/src/protocol/assets.ts +124 -0
- package/src/protocol/canonical.ts +7 -0
- package/src/protocol/ciphertext.ts +6 -0
- package/src/protocol/client.ts +170 -0
- package/src/protocol/conformance/cases/assets.ts +81 -0
- package/src/protocol/conformance/cases/guards.ts +314 -0
- package/src/protocol/conformance/cases/reads.ts +168 -0
- package/src/protocol/conformance/cases/types.ts +9 -0
- package/src/protocol/conformance/cases/wire.ts +138 -0
- package/src/protocol/conformance/cases/writes.ts +345 -0
- package/src/protocol/conformance/contentHashFixtures.ts +79 -0
- package/src/protocol/conformance/context.ts +222 -0
- package/src/protocol/conformance/index.ts +140 -0
- package/src/protocol/errors.ts +142 -0
- package/src/protocol/index.ts +39 -0
- package/src/protocol/keys.ts +279 -0
- package/src/protocol/params.ts +67 -0
- package/src/protocol/secrets.ts +231 -0
- package/src/protocol/server/assets.ts +119 -0
- package/src/protocol/server/auth.ts +49 -0
- package/src/protocol/server/bodyCache.ts +84 -0
- package/src/protocol/server/content.ts +175 -0
- package/src/protocol/server/core.ts +112 -0
- package/src/protocol/server/handler.ts +102 -0
- package/src/protocol/server/http.ts +139 -0
- package/src/protocol/server/index.ts +11 -0
- package/src/protocol/server/methods/apply.ts +341 -0
- package/src/protocol/server/methods/read.ts +156 -0
- package/src/protocol/server/rpc.ts +136 -0
- package/src/protocol/storage/fs/hash.ts +21 -0
- package/src/protocol/storage/fs/index.ts +338 -0
- package/src/protocol/storage/fs/lock.ts +68 -0
- package/src/protocol/storage/fs/transaction.ts +183 -0
- package/src/protocol/storage/fs/unsupported.ts +15 -0
- package/src/protocol/storage/memory.ts +238 -0
- package/src/protocol/storage.ts +182 -0
- package/src/protocol/types.ts +172 -0
- package/src/sdk/abTesting.ts +60 -3
- package/src/sdk/analytics.ts +72 -2
- package/src/sdk/cacheHeaders.ts +210 -10
- package/src/sdk/cacheStorage.ts +287 -0
- package/src/sdk/cachedLoader.ts +143 -90
- package/src/sdk/crypto.ts +16 -2
- package/src/sdk/deepOmit.ts +52 -0
- package/src/sdk/encoding.ts +2 -5
- package/src/sdk/experiments.ts +314 -0
- package/src/sdk/fetchCache.ts +269 -0
- package/src/sdk/fetchTimeout.ts +58 -0
- package/src/sdk/flags.ts +38 -8
- package/src/sdk/index.ts +7 -0
- package/src/sdk/instrumentedFetch.ts +25 -2
- package/src/sdk/nonce.ts +46 -0
- package/src/sdk/normalizeUrls.ts +2 -2
- package/src/sdk/observability.ts +8 -1
- package/src/sdk/otel.ts +131 -25
- package/src/sdk/otelHttpLog.ts +4 -4
- package/src/sdk/otelHttpMeter.ts +39 -13
- package/src/sdk/otelHttpTracer.ts +4 -4
- package/src/sdk/redirects.ts +113 -5
- package/src/sdk/responseCache.ts +82 -0
- package/src/sdk/urlUtils.ts +49 -0
- package/src/sdk/useSuggestions.ts +1 -1
- package/src/v8/analytics.ts +50 -0
- package/src/v8/background.ts +107 -0
- package/src/v8/builtins/data.ts +23 -0
- package/src/v8/builtins/index.ts +26 -0
- package/src/v8/builtins/lazy.ts +23 -0
- package/src/v8/builtins/legacy.ts +65 -0
- package/src/v8/builtins/matchers.ts +31 -0
- package/src/v8/builtins/multivariate.ts +25 -0
- package/src/v8/builtins/secret.ts +82 -0
- package/src/v8/canonical.ts +117 -0
- package/src/v8/ciphertext.ts +158 -0
- package/src/v8/cli/builtins.ts +20 -0
- package/src/v8/cli/check/index.ts +774 -0
- package/src/v8/cli/check/messages.ts +168 -0
- package/src/v8/cli/content.ts +287 -0
- package/src/v8/cli/index.ts +17 -0
- package/src/v8/cli/log.ts +18 -0
- package/src/v8/cli/main.ts +12 -0
- package/src/v8/cli/root.ts +66 -0
- package/src/v8/cli/run.ts +236 -0
- package/src/v8/cli/schema/builtinSchemas.ts +236 -0
- package/src/v8/cli/schema/generate.ts +507 -0
- package/src/v8/cli/schema/index.ts +63 -0
- package/src/v8/cli/schema/tsProgram.ts +497 -0
- package/src/v8/cli/schema/typeToSchema.ts +689 -0
- package/src/v8/cli/serve/server.ts +303 -0
- package/src/v8/cli/watch.ts +86 -0
- package/src/v8/client.ts +147 -0
- package/src/v8/cms.ts +237 -0
- package/src/v8/content.ts +195 -0
- package/src/v8/draft.ts +136 -0
- package/src/v8/errors.ts +59 -0
- package/src/v8/fetch.ts +152 -0
- package/src/v8/identity.ts +65 -0
- package/src/v8/index.ts +39 -0
- package/src/v8/json.ts +74 -0
- package/src/v8/matchRoute.ts +204 -0
- package/src/v8/remoteLoader.ts +282 -0
- package/src/v8/resolver.ts +278 -0
- package/src/v8/secrets.ts +17 -0
- package/src/v8/telemetry.ts +533 -0
- package/src/v8/types.ts +240 -0
- package/src/cms/blockSource.test.ts +0 -76
- package/src/cms/client.browserBundle.test.ts +0 -44
- package/src/cms/draftSource.test.ts +0 -343
- package/src/cms/layoutCacheRace.test.ts +0 -181
- package/src/cms/loadDecofileDirectory.test.ts +0 -109
- package/src/cms/loader.test.ts +0 -200
- package/src/cms/registry.test.ts +0 -110
- package/src/cms/resolve.test.ts +0 -980
- package/src/cms/schema.test.ts +0 -356
- package/src/cms/sectionLoaderContext.test.ts +0 -111
- package/src/cms/sectionLoaders.test.ts +0 -533
- package/src/cms/sectionMixins.test.ts +0 -167
- package/src/cms/stickyFlags.test.ts +0 -117
- package/src/flags/flags.test.ts +0 -148
- package/src/hooks/Image.test.ts +0 -100
- package/src/hooks/RenderSection.test.tsx +0 -81
- package/src/matchers/builtins.test.ts +0 -318
- package/src/matchers/override.test.ts +0 -205
- package/src/middleware/hydrationContext.test.ts +0 -61
- package/src/middleware/observability.test.ts +0 -242
- package/src/middleware/validateSection.test.ts +0 -147
- package/src/sdk/abTesting.test.ts +0 -326
- package/src/sdk/cacheHeaders.test.ts +0 -115
- package/src/sdk/cachedLoader.test.ts +0 -122
- package/src/sdk/cachedLoaderModule.test.ts +0 -209
- package/src/sdk/cn.test.ts +0 -34
- package/src/sdk/composite.test.ts +0 -121
- package/src/sdk/cookie.test.ts +0 -108
- package/src/sdk/encoding.test.ts +0 -71
- package/src/sdk/env.test.ts +0 -33
- package/src/sdk/flags.test.ts +0 -91
- package/src/sdk/http.test.ts +0 -71
- package/src/sdk/inflightTimeout.test.ts +0 -35
- package/src/sdk/instrumentedFetch.test.ts +0 -559
- package/src/sdk/invoke.test.ts +0 -115
- package/src/sdk/logger.test.ts +0 -432
- package/src/sdk/otel.test.ts +0 -526
- package/src/sdk/otelAdapters.test.ts +0 -89
- package/src/sdk/otelHttpLog.test.ts +0 -457
- package/src/sdk/otelHttpMeter.test.ts +0 -292
- package/src/sdk/otelHttpTracer.test.ts +0 -474
- package/src/sdk/requestContextStorage.browser.test.ts +0 -29
- package/src/sdk/urlRedaction.test.ts +0 -73
- package/src/sdk/useDevice.test.ts +0 -130
- package/src/sdk/useScript.test.ts +0 -128
- package/src/sdk/useSuggestions.test.ts +0 -230
- package/tsconfig.json +0 -7
package/src/cms/loader.test.ts
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import { findPageByPath, matchPath, setBlocks } from "./loader";
|
|
3
|
-
|
|
4
|
-
// Mirrors the behavior of the original deco-cx/deco Fresh framework
|
|
5
|
-
// (runtime/features/render.tsx), which uses native `URLPattern` directly
|
|
6
|
-
// and returns `result.pathname.groups`. Splats become numbered groups
|
|
7
|
-
// ("0", "1", …) — there is no `_splat` rename.
|
|
8
|
-
|
|
9
|
-
describe("matchPath", () => {
|
|
10
|
-
describe("literal segments", () => {
|
|
11
|
-
it("matches the root path", () => {
|
|
12
|
-
expect(matchPath("/", "/")).toEqual({});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("matches exact literal paths", () => {
|
|
16
|
-
expect(matchPath("/foo/bar", "/foo/bar")).toEqual({});
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("returns null when literals differ", () => {
|
|
20
|
-
expect(matchPath("/foo/bar", "/foo/baz")).toBeNull();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("returns null when literal-only pattern does not span the whole URL", () => {
|
|
24
|
-
expect(matchPath("/foo", "/foo/bar")).toBeNull();
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe("named params (:slug)", () => {
|
|
29
|
-
it("captures a single param", () => {
|
|
30
|
-
expect(matchPath("/foo/:slug", "/foo/sabonete")).toEqual({ slug: "sabonete" });
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("captures a param sandwiched between literals (VTEX PDP)", () => {
|
|
34
|
-
expect(matchPath("/produto/:slug/p", "/produto/sabonete/p")).toEqual({
|
|
35
|
-
slug: "sabonete",
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("returns null when the URL is shorter than the pattern", () => {
|
|
40
|
-
expect(matchPath("/foo/:slug", "/foo")).toBeNull();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe("trailing splat (*)", () => {
|
|
45
|
-
it("captures the rest as group '0'", () => {
|
|
46
|
-
expect(matchPath("/*", "/foo/bar")).toEqual({ "0": "foo/bar" });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("matches root with empty splat", () => {
|
|
50
|
-
expect(matchPath("/*", "/")).toEqual({ "0": "" });
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("captures the remainder under a prefix", () => {
|
|
54
|
-
expect(matchPath("/foo/*", "/foo/bar/baz")).toEqual({ "0": "bar/baz" });
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Intentional bug fix: the previous custom matchPath accidentally matched
|
|
58
|
-
// `/foo` against `/foo/*` due to its naive split("/") logic, which also
|
|
59
|
-
// mis-handled trailing slashes. Native URLPattern (and the Fresh original)
|
|
60
|
-
// require at least one segment after `/foo/`.
|
|
61
|
-
it("does NOT match the bare prefix without a trailing segment", () => {
|
|
62
|
-
expect(matchPath("/foo/*", "/foo")).toBeNull();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("URLPattern optional groups ({...}?)", () => {
|
|
67
|
-
// Patterns emitted by the deco-cx admin / present in production CMS data.
|
|
68
|
-
// These are the cases that issue #213 documents as broken.
|
|
69
|
-
|
|
70
|
-
it("matches with the optional group present", () => {
|
|
71
|
-
expect(matchPath("/{granado/}?*", "/granado/perfumaria")).toEqual({
|
|
72
|
-
"0": "perfumaria",
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("matches with the optional group absent", () => {
|
|
77
|
-
expect(matchPath("/{granado/}?*", "/perfumaria")).toEqual({ "0": "perfumaria" });
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("matches root when optional prefix and splat collapse to empty", () => {
|
|
81
|
-
expect(matchPath("/{granado/}?*", "/")).toEqual({ "0": "" });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("matches with an optional prefix before a literal segment", () => {
|
|
85
|
-
expect(matchPath("/{granado/}?campanhas/*", "/granado/campanhas/destaques-2023")).toEqual({
|
|
86
|
-
"0": "destaques-2023",
|
|
87
|
-
});
|
|
88
|
-
expect(matchPath("/{granado/}?campanhas/*", "/campanhas/destaques-2023")).toEqual({
|
|
89
|
-
"0": "destaques-2023",
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("matches an optional suffix group present and absent", () => {
|
|
94
|
-
expect(matchPath("/black-friday{/70-off}?", "/black-friday")).toEqual({});
|
|
95
|
-
expect(matchPath("/black-friday{/70-off}?", "/black-friday/70-off")).toEqual({});
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("error tolerance", () => {
|
|
100
|
-
it("returns null for malformed patterns instead of throwing", () => {
|
|
101
|
-
expect(() => matchPath("/[invalid", "/anything")).not.toThrow();
|
|
102
|
-
expect(matchPath("/[invalid", "/anything")).toBeNull();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Node <= 22 has no URLPattern global. The malformed-pattern try/catch
|
|
106
|
-
// above must NOT absorb that ReferenceError — a missing API has to fail
|
|
107
|
-
// loudly at first match, not degrade into every CMS page silently
|
|
108
|
-
// returning null (which renders as sitewide 404s).
|
|
109
|
-
it("throws a descriptive error when the runtime lacks URLPattern", () => {
|
|
110
|
-
const g = globalThis as { URLPattern?: unknown };
|
|
111
|
-
const saved = g.URLPattern;
|
|
112
|
-
// biome-ignore lint/performance/noDelete: restoring exact global state
|
|
113
|
-
delete g.URLPattern;
|
|
114
|
-
try {
|
|
115
|
-
expect(() => matchPath("/foo/:slug", "/foo/bar")).toThrow(/URLPattern.*Node\.js >= 24/s);
|
|
116
|
-
} finally {
|
|
117
|
-
if (saved !== undefined) g.URLPattern = saved;
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
describe("findPageByPath specificity", () => {
|
|
124
|
-
beforeEach(() => {
|
|
125
|
-
setBlocks({
|
|
126
|
-
"pages-bf": {
|
|
127
|
-
name: "Black Friday",
|
|
128
|
-
path: "/black-friday",
|
|
129
|
-
sections: [],
|
|
130
|
-
},
|
|
131
|
-
"pages-bf-splat": {
|
|
132
|
-
name: "Black Friday with optional suffix",
|
|
133
|
-
path: "/black-friday{/70-off}?",
|
|
134
|
-
sections: [],
|
|
135
|
-
},
|
|
136
|
-
"pages-pdp-plp": {
|
|
137
|
-
name: "PDP & PLP",
|
|
138
|
-
path: "/{granado/}?*",
|
|
139
|
-
sections: [],
|
|
140
|
-
},
|
|
141
|
-
"pages-product": {
|
|
142
|
-
name: "Product",
|
|
143
|
-
path: "/produto/:slug/p",
|
|
144
|
-
sections: [],
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
afterEach(() => {
|
|
150
|
-
setBlocks({});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("prefers an exact literal over an optional-group splat", () => {
|
|
154
|
-
const match = findPageByPath("/black-friday");
|
|
155
|
-
expect(match?.blockKey).toBe("pages-bf");
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("prefers the home page over an optional-group splat catch-all", () => {
|
|
159
|
-
// Regression: /{granado/}?* matches "/" and was out-ranking the home
|
|
160
|
-
// because the `{granado` segment counted as a param. The home block
|
|
161
|
-
// is a literal-only `/` path and must always win.
|
|
162
|
-
setBlocks({
|
|
163
|
-
"pages-home": {
|
|
164
|
-
name: "Home",
|
|
165
|
-
path: "/",
|
|
166
|
-
sections: [],
|
|
167
|
-
},
|
|
168
|
-
"pages-pdp-plp": {
|
|
169
|
-
name: "PDP & PLP",
|
|
170
|
-
path: "/{granado/}?*",
|
|
171
|
-
sections: [],
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
const match = findPageByPath("/");
|
|
175
|
-
expect(match?.blockKey).toBe("pages-home");
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it("falls back to the splat page for unknown URLs", () => {
|
|
179
|
-
const match = findPageByPath("/perfumaria");
|
|
180
|
-
expect(match?.blockKey).toBe("pages-pdp-plp");
|
|
181
|
-
expect(match?.params).toEqual({ "0": "perfumaria" });
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it("matches the param-bearing route ahead of the splat catch-all", () => {
|
|
185
|
-
const match = findPageByPath("/produto/sabonete/p");
|
|
186
|
-
expect(match?.blockKey).toBe("pages-product");
|
|
187
|
-
expect(match?.params).toEqual({ slug: "sabonete" });
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
it("returns null when no page matches", () => {
|
|
191
|
-
setBlocks({
|
|
192
|
-
"pages-only-bf": {
|
|
193
|
-
name: "Black Friday",
|
|
194
|
-
path: "/black-friday",
|
|
195
|
-
sections: [],
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
expect(findPageByPath("/nope")).toBeNull();
|
|
199
|
-
});
|
|
200
|
-
});
|
package/src/cms/registry.test.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
getResolvedComponent,
|
|
4
|
-
getSection,
|
|
5
|
-
getSectionOptions,
|
|
6
|
-
getSyncComponent,
|
|
7
|
-
registerSection,
|
|
8
|
-
registerSectionsSync,
|
|
9
|
-
} from "./registry";
|
|
10
|
-
|
|
11
|
-
// Reset globalThis.__deco between tests to avoid cross-test pollution
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
const G = globalThis as any;
|
|
14
|
-
G.__deco.sectionRegistry = {};
|
|
15
|
-
G.__deco.sectionOptions = {};
|
|
16
|
-
G.__deco.resolvedComponents = {};
|
|
17
|
-
G.__deco.syncComponents = {};
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("registerSection + getSection", () => {
|
|
21
|
-
it("registers and retrieves a section loader", () => {
|
|
22
|
-
const loader = async () => ({ default: () => null });
|
|
23
|
-
registerSection("site/sections/Hero.tsx", loader);
|
|
24
|
-
|
|
25
|
-
const retrieved = getSection("site/sections/Hero.tsx");
|
|
26
|
-
expect(retrieved).toBe(loader);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("returns undefined for unregistered section", () => {
|
|
30
|
-
expect(getSection("nonexistent")).toBeUndefined();
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("registerSection with options", () => {
|
|
35
|
-
it("stores loadingFallback in section options", () => {
|
|
36
|
-
const fallback = () => null;
|
|
37
|
-
registerSection("site/sections/Shelf.tsx", async () => ({ default: () => null }), {
|
|
38
|
-
loadingFallback: fallback,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const opts = getSectionOptions("site/sections/Shelf.tsx");
|
|
42
|
-
expect(opts?.loadingFallback).toBe(fallback);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("stores clientOnly flag in section options", () => {
|
|
46
|
-
registerSection("site/sections/Analytics.tsx", async () => ({ default: () => null }), {
|
|
47
|
-
clientOnly: true,
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const opts = getSectionOptions("site/sections/Analytics.tsx");
|
|
51
|
-
expect(opts?.clientOnly).toBe(true);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("clientOnly defaults to undefined when not set", () => {
|
|
55
|
-
registerSection("site/sections/Normal.tsx", async () => ({ default: () => null }), {
|
|
56
|
-
loadingFallback: () => null,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
const opts = getSectionOptions("site/sections/Normal.tsx");
|
|
60
|
-
expect(opts?.clientOnly).toBeUndefined();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("clientOnly false is preserved", () => {
|
|
64
|
-
registerSection("site/sections/Explicit.tsx", async () => ({ default: () => null }), {
|
|
65
|
-
clientOnly: false,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const opts = getSectionOptions("site/sections/Explicit.tsx");
|
|
69
|
-
expect(opts?.clientOnly).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("returns undefined options for section without options", () => {
|
|
73
|
-
registerSection("site/sections/Plain.tsx", async () => ({ default: () => null }));
|
|
74
|
-
expect(getSectionOptions("site/sections/Plain.tsx")).toBeUndefined();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
describe("registerSectionsSync", () => {
|
|
79
|
-
it("registers component as sync and resolved", () => {
|
|
80
|
-
const MyComponent = () => null;
|
|
81
|
-
registerSectionsSync({ "site/sections/Header.tsx": MyComponent });
|
|
82
|
-
|
|
83
|
-
expect(getSyncComponent("site/sections/Header.tsx")).toBe(MyComponent);
|
|
84
|
-
expect(getResolvedComponent("site/sections/Header.tsx")).toBe(MyComponent);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("accepts module objects with LoadingFallback", () => {
|
|
88
|
-
const MyComponent = () => null;
|
|
89
|
-
const MyFallback = () => null;
|
|
90
|
-
|
|
91
|
-
registerSectionsSync({
|
|
92
|
-
"site/sections/Footer.tsx": {
|
|
93
|
-
default: MyComponent,
|
|
94
|
-
LoadingFallback: MyFallback,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
expect(getSyncComponent("site/sections/Footer.tsx")).toBe(MyComponent);
|
|
99
|
-
const opts = getSectionOptions("site/sections/Footer.tsx");
|
|
100
|
-
expect(opts?.loadingFallback).toBe(MyFallback);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("skips entries without callable default export", () => {
|
|
104
|
-
registerSectionsSync({
|
|
105
|
-
"site/sections/Bad.tsx": { default: "not a function" } as any,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
expect(getSyncComponent("site/sections/Bad.tsx")).toBeUndefined();
|
|
109
|
-
});
|
|
110
|
-
});
|