Connect.utils.test.ts224 lines · main
| 1 | import { describe, expect, test } from 'vitest' |
| 2 | |
| 3 | import { resolveFrameworkLibraryKey } from './Connect.utils' |
| 4 | |
| 5 | describe('Connect.utils:resolveFrameworkLibraryKey', () => { |
| 6 | test('should return null if no framework provided', () => { |
| 7 | const result = resolveFrameworkLibraryKey({ |
| 8 | framework: undefined, |
| 9 | frameworkVariant: undefined, |
| 10 | library: undefined, |
| 11 | }) |
| 12 | expect(result).toBeNull() |
| 13 | }) |
| 14 | |
| 15 | test('should return null for empty framework string', () => { |
| 16 | const result = resolveFrameworkLibraryKey({ |
| 17 | framework: '', |
| 18 | frameworkVariant: undefined, |
| 19 | library: undefined, |
| 20 | }) |
| 21 | expect(result).toBeNull() |
| 22 | }) |
| 23 | |
| 24 | test('should return explicit library if provided', () => { |
| 25 | const result = resolveFrameworkLibraryKey({ |
| 26 | framework: 'nextjs', |
| 27 | frameworkVariant: 'app', |
| 28 | library: 'custom-library', |
| 29 | }) |
| 30 | expect(result).toBe('custom-library') |
| 31 | }) |
| 32 | |
| 33 | test('should resolve library for Next.js App Router', () => { |
| 34 | const result = resolveFrameworkLibraryKey({ |
| 35 | framework: 'nextjs', |
| 36 | frameworkVariant: 'app', |
| 37 | library: undefined, |
| 38 | }) |
| 39 | // Next.js App Router has brivenjs as its library |
| 40 | expect(result).toBe('brivenjs') |
| 41 | }) |
| 42 | |
| 43 | test('should resolve library for Next.js Pages Router', () => { |
| 44 | const result = resolveFrameworkLibraryKey({ |
| 45 | framework: 'nextjs', |
| 46 | frameworkVariant: 'pages', |
| 47 | library: undefined, |
| 48 | }) |
| 49 | expect(result).toBe('brivenjs') |
| 50 | }) |
| 51 | |
| 52 | test('should resolve library for React with Vite variant', () => { |
| 53 | const result = resolveFrameworkLibraryKey({ |
| 54 | framework: 'react', |
| 55 | frameworkVariant: 'vite', |
| 56 | library: undefined, |
| 57 | }) |
| 58 | expect(result).toBe('brivenjs') |
| 59 | }) |
| 60 | |
| 61 | test('should resolve library for React with Create React App variant', () => { |
| 62 | const result = resolveFrameworkLibraryKey({ |
| 63 | framework: 'react', |
| 64 | frameworkVariant: 'create-react-app', |
| 65 | library: undefined, |
| 66 | }) |
| 67 | expect(result).toBe('brivenjs') |
| 68 | }) |
| 69 | |
| 70 | test('should resolve library for framework without variants (Remix)', () => { |
| 71 | const result = resolveFrameworkLibraryKey({ |
| 72 | framework: 'remix', |
| 73 | frameworkVariant: undefined, |
| 74 | library: undefined, |
| 75 | }) |
| 76 | // Remix has single child which is brivenjs |
| 77 | expect(result).toBe('brivenjs') |
| 78 | }) |
| 79 | |
| 80 | test('should resolve library for Flutter', () => { |
| 81 | const result = resolveFrameworkLibraryKey({ |
| 82 | framework: 'flutter', |
| 83 | frameworkVariant: undefined, |
| 84 | library: undefined, |
| 85 | }) |
| 86 | expect(result).toBe('brivenflutter') |
| 87 | }) |
| 88 | |
| 89 | test('should resolve library for Swift', () => { |
| 90 | const result = resolveFrameworkLibraryKey({ |
| 91 | framework: 'swift', |
| 92 | frameworkVariant: undefined, |
| 93 | library: undefined, |
| 94 | }) |
| 95 | expect(result).toBe('brivenswift') |
| 96 | }) |
| 97 | |
| 98 | test('should resolve library for Android Kotlin', () => { |
| 99 | const result = resolveFrameworkLibraryKey({ |
| 100 | framework: 'androidkotlin', |
| 101 | frameworkVariant: undefined, |
| 102 | library: undefined, |
| 103 | }) |
| 104 | expect(result).toBe('brivenkt') |
| 105 | }) |
| 106 | |
| 107 | test('should resolve library for Flask (Python)', () => { |
| 108 | const result = resolveFrameworkLibraryKey({ |
| 109 | framework: 'flask', |
| 110 | frameworkVariant: undefined, |
| 111 | library: undefined, |
| 112 | }) |
| 113 | expect(result).toBe('brivenpy') |
| 114 | }) |
| 115 | |
| 116 | test('should fallback to first variant library when variant not specified for multi-variant framework', () => { |
| 117 | const result = resolveFrameworkLibraryKey({ |
| 118 | framework: 'nextjs', |
| 119 | frameworkVariant: undefined, |
| 120 | library: undefined, |
| 121 | }) |
| 122 | // Should get library from first variant (app router) |
| 123 | expect(result).toBe('brivenjs') |
| 124 | }) |
| 125 | |
| 126 | test('should return null for unknown framework', () => { |
| 127 | const result = resolveFrameworkLibraryKey({ |
| 128 | framework: 'unknown-framework', |
| 129 | frameworkVariant: undefined, |
| 130 | library: undefined, |
| 131 | }) |
| 132 | expect(result).toBeNull() |
| 133 | }) |
| 134 | |
| 135 | test('should handle SvelteKit framework', () => { |
| 136 | const result = resolveFrameworkLibraryKey({ |
| 137 | framework: 'sveltekit', |
| 138 | frameworkVariant: undefined, |
| 139 | library: undefined, |
| 140 | }) |
| 141 | expect(result).toBe('brivenjs') |
| 142 | }) |
| 143 | |
| 144 | test('should handle Nuxt framework', () => { |
| 145 | const result = resolveFrameworkLibraryKey({ |
| 146 | framework: 'nuxt', |
| 147 | frameworkVariant: undefined, |
| 148 | library: undefined, |
| 149 | }) |
| 150 | expect(result).toBe('brivenjs') |
| 151 | }) |
| 152 | |
| 153 | test('should handle Vue.js framework', () => { |
| 154 | const result = resolveFrameworkLibraryKey({ |
| 155 | framework: 'vuejs', |
| 156 | frameworkVariant: undefined, |
| 157 | library: undefined, |
| 158 | }) |
| 159 | expect(result).toBe('brivenjs') |
| 160 | }) |
| 161 | |
| 162 | test('should handle Solid.js framework', () => { |
| 163 | const result = resolveFrameworkLibraryKey({ |
| 164 | framework: 'solidjs', |
| 165 | frameworkVariant: undefined, |
| 166 | library: undefined, |
| 167 | }) |
| 168 | expect(result).toBe('brivenjs') |
| 169 | }) |
| 170 | |
| 171 | test('should handle Astro framework', () => { |
| 172 | const result = resolveFrameworkLibraryKey({ |
| 173 | framework: 'astro', |
| 174 | frameworkVariant: undefined, |
| 175 | library: undefined, |
| 176 | }) |
| 177 | expect(result).toBe('brivenjs') |
| 178 | }) |
| 179 | |
| 180 | test('should handle Expo React Native', () => { |
| 181 | const result = resolveFrameworkLibraryKey({ |
| 182 | framework: 'exporeactnative', |
| 183 | frameworkVariant: undefined, |
| 184 | library: undefined, |
| 185 | }) |
| 186 | expect(result).toBe('brivenjs') |
| 187 | }) |
| 188 | |
| 189 | test('should handle Ionic React', () => { |
| 190 | const result = resolveFrameworkLibraryKey({ |
| 191 | framework: 'ionicreact', |
| 192 | frameworkVariant: undefined, |
| 193 | library: undefined, |
| 194 | }) |
| 195 | expect(result).toBe('brivenjs') |
| 196 | }) |
| 197 | |
| 198 | test('should handle Ionic Angular', () => { |
| 199 | const result = resolveFrameworkLibraryKey({ |
| 200 | framework: 'ionicangular', |
| 201 | frameworkVariant: undefined, |
| 202 | library: undefined, |
| 203 | }) |
| 204 | expect(result).toBe('brivenjs') |
| 205 | }) |
| 206 | |
| 207 | test('should handle Refine framework', () => { |
| 208 | const result = resolveFrameworkLibraryKey({ |
| 209 | framework: 'refine', |
| 210 | frameworkVariant: undefined, |
| 211 | library: undefined, |
| 212 | }) |
| 213 | expect(result).toBe('brivenjs') |
| 214 | }) |
| 215 | |
| 216 | test('should handle TanStack Start framework', () => { |
| 217 | const result = resolveFrameworkLibraryKey({ |
| 218 | framework: 'tanstack', |
| 219 | frameworkVariant: undefined, |
| 220 | library: undefined, |
| 221 | }) |
| 222 | expect(result).toBe('brivenjs') |
| 223 | }) |
| 224 | }) |