|
| 1 | +import { AppSegmentConfigSchema } from './app-segment-config' |
| 2 | + |
| 3 | +describe('AppConfigSchema', () => { |
| 4 | + it('should only support zero, a positive number or false for revalidate', () => { |
| 5 | + const valid = [0, 1, 100, false] |
| 6 | + |
| 7 | + for (const value of valid) { |
| 8 | + expect( |
| 9 | + AppSegmentConfigSchema.safeParse({ revalidate: value }).success |
| 10 | + ).toBe(true) |
| 11 | + } |
| 12 | + |
| 13 | + const invalid = [-1, -100, true] |
| 14 | + |
| 15 | + for (const value of invalid) { |
| 16 | + expect( |
| 17 | + AppSegmentConfigSchema.safeParse({ revalidate: value }).success |
| 18 | + ).toBe(false) |
| 19 | + } |
| 20 | + }) |
| 21 | + |
| 22 | + it('should support an empty config', () => { |
| 23 | + expect(AppSegmentConfigSchema.safeParse({}).success).toBe(true) |
| 24 | + }) |
| 25 | + |
| 26 | + it('should support a boolean for dynamicParams', () => { |
| 27 | + expect( |
| 28 | + AppSegmentConfigSchema.safeParse({ dynamicParams: true }).success |
| 29 | + ).toBe(true) |
| 30 | + expect( |
| 31 | + AppSegmentConfigSchema.safeParse({ dynamicParams: false }).success |
| 32 | + ).toBe(true) |
| 33 | + expect( |
| 34 | + AppSegmentConfigSchema.safeParse({ dynamicParams: 'foo' }).success |
| 35 | + ).toBe(false) |
| 36 | + }) |
| 37 | + |
| 38 | + it('should support "auto" | "force-dynamic" | "error" | "force-static" for dynamic', () => { |
| 39 | + expect(AppSegmentConfigSchema.safeParse({ dynamic: 'auto' }).success).toBe( |
| 40 | + true |
| 41 | + ) |
| 42 | + expect( |
| 43 | + AppSegmentConfigSchema.safeParse({ dynamic: 'force-dynamic' }).success |
| 44 | + ).toBe(true) |
| 45 | + expect(AppSegmentConfigSchema.safeParse({ dynamic: 'error' }).success).toBe( |
| 46 | + true |
| 47 | + ) |
| 48 | + expect( |
| 49 | + AppSegmentConfigSchema.safeParse({ dynamic: 'force-static' }).success |
| 50 | + ).toBe(true) |
| 51 | + }) |
| 52 | + |
| 53 | + it('should support "edge" | "nodejs" for runtime', () => { |
| 54 | + expect(AppSegmentConfigSchema.safeParse({ runtime: 'edge' }).success).toBe( |
| 55 | + true |
| 56 | + ) |
| 57 | + expect( |
| 58 | + AppSegmentConfigSchema.safeParse({ runtime: 'nodejs' }).success |
| 59 | + ).toBe(true) |
| 60 | + expect(AppSegmentConfigSchema.safeParse({ runtime: 'foo' }).success).toBe( |
| 61 | + false |
| 62 | + ) |
| 63 | + }) |
| 64 | + |
| 65 | + it('should support a positive number or zero for maxDuration', () => { |
| 66 | + expect(AppSegmentConfigSchema.safeParse({ maxDuration: 0 }).success).toBe( |
| 67 | + true |
| 68 | + ) |
| 69 | + expect(AppSegmentConfigSchema.safeParse({ maxDuration: 100 }).success).toBe( |
| 70 | + true |
| 71 | + ) |
| 72 | + expect(AppSegmentConfigSchema.safeParse({ maxDuration: -1 }).success).toBe( |
| 73 | + false |
| 74 | + ) |
| 75 | + }) |
| 76 | + |
| 77 | + it('should support "force-cache" | "only-cache" for fetchCache', () => { |
| 78 | + expect( |
| 79 | + AppSegmentConfigSchema.safeParse({ fetchCache: 'force-cache' }).success |
| 80 | + ).toBe(true) |
| 81 | + expect( |
| 82 | + AppSegmentConfigSchema.safeParse({ fetchCache: 'only-cache' }).success |
| 83 | + ).toBe(true) |
| 84 | + expect( |
| 85 | + AppSegmentConfigSchema.safeParse({ fetchCache: 'foo' }).success |
| 86 | + ).toBe(false) |
| 87 | + }) |
| 88 | + |
| 89 | + it('should support a string or an array of strings for preferredRegion', () => { |
| 90 | + expect( |
| 91 | + AppSegmentConfigSchema.safeParse({ preferredRegion: 'foo' }).success |
| 92 | + ).toBe(true) |
| 93 | + expect( |
| 94 | + AppSegmentConfigSchema.safeParse({ preferredRegion: ['foo', 'bar'] }) |
| 95 | + .success |
| 96 | + ).toBe(true) |
| 97 | + }) |
| 98 | + |
| 99 | + it('should support a boolean for experimental_ppr', () => { |
| 100 | + expect( |
| 101 | + AppSegmentConfigSchema.safeParse({ experimental_ppr: true }).success |
| 102 | + ).toBe(true) |
| 103 | + expect( |
| 104 | + AppSegmentConfigSchema.safeParse({ experimental_ppr: false }).success |
| 105 | + ).toBe(true) |
| 106 | + expect( |
| 107 | + AppSegmentConfigSchema.safeParse({ experimental_ppr: 'foo' }).success |
| 108 | + ).toBe(false) |
| 109 | + }) |
| 110 | +}) |
0 commit comments