expo-router 1.4.2 → 1.4.3

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.
Files changed (28) hide show
  1. package/build/loadStaticParamsAsync.d.ts.map +1 -1
  2. package/build/static/renderStaticContent.d.ts.map +1 -1
  3. package/build/static/useServerState.d.ts.map +1 -1
  4. package/build/views/Screen.d.ts.map +1 -1
  5. package/build/views/Unmatched.d.ts.map +1 -1
  6. package/package.json +5 -4
  7. package/src/loadStaticParamsAsync.ts +51 -24
  8. package/src/static/renderStaticContent.tsx +5 -1
  9. package/src/static/useServerState.ts +4 -1
  10. package/src/views/Screen.tsx +4 -1
  11. package/src/views/Unmatched.tsx +17 -3
  12. package/src/__tests__/LocationProvider.test.node.ts +0 -55
  13. package/src/__tests__/Route.test.node.ts +0 -70
  14. package/src/__tests__/getReactNavigationConfig.test.node.ts +0 -138
  15. package/src/__tests__/getRoutes.test.node.ts +0 -486
  16. package/src/__tests__/loadStaticParamsAsync.test.node.ts +0 -413
  17. package/src/__tests__/matchers.test.node.ts +0 -59
  18. package/src/__tests__/useNavigation.test.node.ts +0 -24
  19. package/src/__tests__/useScreens.test.node.tsx +0 -66
  20. package/src/fork/__tests__/__snapshots__/extractPathFromURL.test.ios.ts.snap +0 -97
  21. package/src/fork/__tests__/extractPathFromURL.test.ios.ts +0 -76
  22. package/src/fork/__tests__/getPathFromState-upstream.test.node.ts +0 -1981
  23. package/src/fork/__tests__/getStateFromPath-upstream.test.node.ts +0 -2570
  24. package/src/fork/__tests__/getStateFromPath.test.node.ts +0 -131
  25. package/src/link/__tests__/href.test.node.ts +0 -57
  26. package/src/link/__tests__/stateOperations.test.node.ts +0 -373
  27. package/src/link/__tests__/useLinkToPath.test.node.ts +0 -53
  28. package/src/utils/__tests__/mockState.test.node.ts +0 -119
@@ -1,486 +0,0 @@
1
- import { RouteNode } from "../Route";
2
- import {
3
- assertDuplicateRoutes,
4
- FileNode,
5
- getExactRoutes,
6
- getRecursiveTree,
7
- getRoutes,
8
- getUserDefinedDeepDynamicRoute,
9
- } from "../getRoutes";
10
- import { RequireContext } from "../types";
11
-
12
- function createMockContextModule(
13
- map: Record<string, Record<string, any>> = {}
14
- ) {
15
- const contextModule = jest.fn((key) => map[key]);
16
-
17
- Object.defineProperty(contextModule, "keys", {
18
- value: () => Object.keys(map),
19
- });
20
-
21
- return contextModule as unknown as RequireContext;
22
- }
23
-
24
- function dropFunctions({ loadRoute, ...node }: RouteNode) {
25
- return {
26
- ...node,
27
- children: node.children.map(dropFunctions),
28
- };
29
- }
30
-
31
- const ROUTE_404 = {
32
- children: [],
33
- contextKey: "./[...404].tsx",
34
- dynamic: [{ deep: true, name: "404" }],
35
- generated: true,
36
- internal: true,
37
- route: "[...404]",
38
- };
39
-
40
- const ROUTE_DIRECTORY = {
41
- children: [],
42
- contextKey: "./_sitemap.tsx",
43
- dynamic: null,
44
- generated: true,
45
- internal: true,
46
- route: "_sitemap",
47
- };
48
-
49
- const asFileNode = (route: Partial<FileNode>): FileNode => ({
50
- loadRoute(): any {
51
- return {
52
- default() {
53
- return null;
54
- },
55
- };
56
- },
57
- normalizedName: "INVALID_TEST_VALUE",
58
- contextKey: "INVALID_TEST_VALUE",
59
- ...route,
60
- });
61
-
62
- const asRouteNode = (route: Partial<RouteNode>) => ({
63
- loadRoute(): any {
64
- return {
65
- default() {
66
- return null;
67
- },
68
- };
69
- },
70
- children: [],
71
- dynamic: null,
72
- route: "INVALID_TEST_VALUE",
73
- contextKey: "INVALID_TEST_VALUE",
74
- ...route,
75
- });
76
-
77
- describe(assertDuplicateRoutes, () => {
78
- const originalEnv = process.env.NODE_ENV;
79
-
80
- afterEach(() => {
81
- process.env.NODE_ENV = originalEnv;
82
- });
83
- it(`throws if there are duplicate routes`, () => {
84
- expect(() =>
85
- assertDuplicateRoutes(["a.js", "a.tsx", "b.js"])
86
- ).toThrowErrorMatchingInlineSnapshot(
87
- `"Multiple files match the route name "a"."`
88
- );
89
- });
90
-
91
- it(`doesn't throw if there are no duplicate routes`, () => {
92
- expect(() =>
93
- assertDuplicateRoutes(["a", "b", "/c/d/e.js", "f/g.tsx"])
94
- ).not.toThrow();
95
- });
96
-
97
- it(`doesn't throw if running in production`, () => {
98
- process.env.NODE_ENV = "production";
99
- expect(() => assertDuplicateRoutes(["a", "a.js"])).not.toThrow();
100
- });
101
- });
102
-
103
- describe(getRecursiveTree, () => {
104
- function getTreeForKeys(keys: string[]) {
105
- const routes = keys.map((normalizedName) =>
106
- asFileNode({
107
- normalizedName,
108
- })
109
- );
110
- return getRecursiveTree(routes).children;
111
- }
112
-
113
- it(`should assert using deprecated layout route format`, () => {
114
- expect(() => getTreeForKeys(["(app)", "(app)/index"])).toThrowError(
115
- /Using deprecated Layout Route format/
116
- );
117
- });
118
-
119
- it(`should return a layout route`, () => {
120
- expect(getTreeForKeys(["(app)/_layout", "(app)/index"])).toEqual([
121
- {
122
- children: [
123
- {
124
- children: [],
125
- name: "index",
126
- node: expect.objectContaining({
127
- normalizedName: "(app)/index",
128
- }),
129
- parents: ["", "(app)"],
130
- },
131
- ],
132
- name: "(app)",
133
- node: expect.objectContaining({
134
- normalizedName: "(app)/_layout",
135
- }),
136
- parents: [""],
137
- },
138
- ]);
139
- });
140
-
141
- it(`should return a layout route using alternative format`, () => {
142
- expect(getTreeForKeys(["(app)/_layout", "(app)/index"])).toEqual([
143
- {
144
- children: [
145
- {
146
- children: [],
147
- name: "index",
148
- node: expect.objectContaining({
149
- normalizedName: "(app)/index",
150
- }),
151
- parents: ["", "(app)"],
152
- },
153
- ],
154
- name: "(app)",
155
- node: expect.objectContaining({
156
- normalizedName: "(app)/_layout",
157
- }),
158
- parents: [""],
159
- },
160
- ]);
161
- });
162
- });
163
-
164
- describe(getUserDefinedDeepDynamicRoute, () => {
165
- it(`should return a basic deep dynamic route`, () => {
166
- const routes = asRouteNode({
167
- children: [
168
- asRouteNode({
169
- route: "[...404]",
170
- }),
171
- ],
172
- });
173
- expect(getUserDefinedDeepDynamicRoute(routes)).toEqual(routes.children[0]);
174
- });
175
- it(`does not return a nested deep dynamic route `, () => {
176
- const deep = asRouteNode({
177
- route: "[...404]",
178
- });
179
- const routes = asRouteNode({
180
- children: [
181
- asRouteNode({
182
- route: "home",
183
- children: [deep],
184
- }),
185
- ],
186
- });
187
- expect(getUserDefinedDeepDynamicRoute(routes)).toEqual(null);
188
- });
189
- it(`should return a top-level deep dynamic route when nested in a group`, () => {
190
- const deep = asRouteNode({
191
- route: "[...404]",
192
- });
193
- const routes = asRouteNode({
194
- children: [
195
- asRouteNode({
196
- route: "(group)",
197
- children: [
198
- asRouteNode({
199
- route: "(another)",
200
- children: [deep],
201
- }),
202
- ],
203
- }),
204
- ],
205
- });
206
- expect(getUserDefinedDeepDynamicRoute(routes)).toEqual(deep);
207
- });
208
- it(`does not return a dynamic route`, () => {
209
- expect(
210
- getUserDefinedDeepDynamicRoute(
211
- asRouteNode({
212
- children: [
213
- // [404].js
214
- asRouteNode({
215
- route: "[404]",
216
- }),
217
- ],
218
- })
219
- )
220
- ).toEqual(null);
221
-
222
- expect(
223
- getUserDefinedDeepDynamicRoute(
224
- asRouteNode({
225
- children: [
226
- // home/
227
- asRouteNode({
228
- route: "home",
229
- children: [
230
- // [404].js
231
- asRouteNode({
232
- route: "[404]",
233
- }),
234
- ],
235
- }),
236
- ],
237
- })
238
- )
239
- ).toEqual(null);
240
- });
241
- });
242
-
243
- describe(getExactRoutes, () => {
244
- // NOTE(EvanBacon): This tests when all you have is a root layout.
245
- it(`automatically blocks +html file`, () => {
246
- expect(
247
- dropFunctions(
248
- getExactRoutes(
249
- createMockContextModule({
250
- "./+html.js": { default() {} },
251
- "./other/+html.js": { default() {} },
252
- "./_layout.tsx": { default() {} },
253
- })
254
- )!
255
- )
256
- ).toEqual({
257
- children: [
258
- {
259
- children: [],
260
- contextKey: "./other/+html.js",
261
- dynamic: null,
262
- route: "other/+html",
263
- },
264
- ],
265
- contextKey: "./_layout.tsx",
266
- dynamic: null,
267
- route: "",
268
- });
269
- });
270
- });
271
-
272
- describe(getRoutes, () => {
273
- // NOTE(EvanBacon): This tests when all you have is a root layout.
274
- it(`should allow a custom root _layout route`, () => {
275
- expect(
276
- dropFunctions(
277
- getRoutes(
278
- createMockContextModule({
279
- "./_layout.tsx": { default() {} },
280
- })
281
- )!
282
- )
283
- ).toEqual({
284
- children: [
285
- {
286
- children: [],
287
- contextKey: "./[...404].tsx",
288
- dynamic: [{ deep: true, name: "404" }],
289
- generated: true,
290
- internal: true,
291
- route: "[...404]",
292
- },
293
- ],
294
- contextKey: "./_layout.tsx",
295
- dynamic: null,
296
- route: "",
297
- });
298
- });
299
-
300
- it(`should support a single nested route without layouts`, () => {
301
- expect(
302
- dropFunctions(
303
- getRoutes(
304
- createMockContextModule({
305
- "./some/nested/value.tsx": { default() {} },
306
- })
307
- )!
308
- )
309
- ).toEqual({
310
- children: [
311
- {
312
- children: [],
313
- contextKey: "./some/nested/value.tsx",
314
- dynamic: null,
315
- route: "some/nested/value",
316
- },
317
- ROUTE_DIRECTORY,
318
- ROUTE_404,
319
- ],
320
- contextKey: "./_layout.tsx",
321
- dynamic: null,
322
- generated: true,
323
- route: "",
324
- });
325
- });
326
-
327
- it(`get dynamic routes`, () => {
328
- expect(
329
- dropFunctions(
330
- getRoutes(
331
- createMockContextModule({
332
- "./[dynamic].tsx": { default() {} },
333
- "./[...deep].tsx": { default() {} },
334
- })
335
- )!
336
- )
337
- ).toEqual(
338
- expect.objectContaining({
339
- generated: true,
340
- children: [
341
- {
342
- children: [],
343
- contextKey: "./[dynamic].tsx",
344
- dynamic: [
345
- {
346
- deep: false,
347
- name: "dynamic",
348
- },
349
- ],
350
-
351
- route: "[dynamic]",
352
- },
353
- {
354
- children: [],
355
- contextKey: "./[...deep].tsx",
356
- dynamic: [
357
- {
358
- deep: true,
359
- name: "deep",
360
- },
361
- ],
362
-
363
- route: "[...deep]",
364
- },
365
- ROUTE_DIRECTORY,
366
- // No 404 route because we have a dynamic route
367
- ],
368
- })
369
- );
370
- });
371
-
372
- it(`should convert a complex context module routes`, () => {
373
- expect(
374
- dropFunctions(
375
- getRoutes(
376
- createMockContextModule({
377
- "./(stack)/_layout.tsx": { default() {} },
378
- "./(stack)/home.tsx": { default() {} },
379
- "./(stack)/settings.tsx": { default() {} },
380
- "./(stack)/user/(default)/_layout.tsx": { default() {} },
381
- "./(stack)/user/(default)/posts.tsx": { default() {} },
382
- "./(stack)/user/profile.tsx": { default() {} },
383
- "./(stack)/user/[profile].tsx": { default() {} },
384
- "./(stack)/user/settings/_layout.tsx": { default() {} },
385
- "./(stack)/user/settings/info.tsx": { default() {} },
386
- "./(stack)/user/settings/[...other].tsx": { default() {} },
387
- "./another.tsx": { default() {} },
388
- "./some/nested/value.tsx": { default() {} },
389
- })
390
- )!
391
- )
392
- ).toEqual({
393
- children: [
394
- {
395
- children: [
396
- {
397
- children: [],
398
- contextKey: "./(stack)/home.tsx",
399
- dynamic: null,
400
- route: "home",
401
- },
402
- {
403
- children: [],
404
- contextKey: "./(stack)/settings.tsx",
405
- dynamic: null,
406
- route: "settings",
407
- },
408
- {
409
- children: [
410
- {
411
- children: [],
412
- contextKey: "./(stack)/user/(default)/posts.tsx",
413
- dynamic: null,
414
- route: "posts",
415
- },
416
- ],
417
- contextKey: "./(stack)/user/(default)/_layout.tsx",
418
- dynamic: null,
419
- route: "user/(default)",
420
- },
421
- {
422
- children: [],
423
- contextKey: "./(stack)/user/profile.tsx",
424
- dynamic: null,
425
- route: "user/profile",
426
- },
427
- {
428
- children: [],
429
- contextKey: "./(stack)/user/[profile].tsx",
430
- dynamic: [
431
- {
432
- deep: false,
433
- name: "profile",
434
- },
435
- ],
436
- route: "user/[profile]",
437
- },
438
- {
439
- children: [
440
- {
441
- children: [],
442
- contextKey: "./(stack)/user/settings/info.tsx",
443
- dynamic: null,
444
- route: "info",
445
- },
446
- {
447
- children: [],
448
- contextKey: "./(stack)/user/settings/[...other].tsx",
449
- dynamic: [{ deep: true, name: "other" }],
450
- route: "[...other]",
451
- },
452
- ],
453
- contextKey: "./(stack)/user/settings/_layout.tsx",
454
- dynamic: null,
455
- route: "user/settings",
456
- },
457
- ],
458
- contextKey: "./(stack)/_layout.tsx",
459
- dynamic: null,
460
- route: "(stack)",
461
- },
462
- {
463
- children: [],
464
- contextKey: "./another.tsx",
465
- dynamic: null,
466
- route: "another",
467
- },
468
- {
469
- children: [],
470
- contextKey: "./some/nested/value.tsx",
471
- dynamic: null,
472
- route: "some/nested/value",
473
- },
474
- ROUTE_DIRECTORY,
475
- ROUTE_404,
476
- ],
477
- contextKey: "./_layout.tsx",
478
- dynamic: null,
479
- generated: true,
480
- route: "",
481
- });
482
- });
483
- it(`should convert an empty context module to routes`, () => {
484
- expect(getRoutes(createMockContextModule({}))).toEqual(null);
485
- });
486
- });