|
| 1 | +import path from 'node:path'; |
| 2 | + |
| 3 | +import { resolveRuntimeConfigPath } from '../../client-core/client'; |
| 4 | + |
| 5 | +describe('resolveRuntimeConfigPath', () => { |
| 6 | + it('preserves path mapping and module specifiers', () => { |
| 7 | + const outputPath = path.join(process.cwd(), 'src/client'); |
| 8 | + |
| 9 | + expect( |
| 10 | + resolveRuntimeConfigPath({ |
| 11 | + outputPath, |
| 12 | + runtimeConfigPath: '~/foo.ts', |
| 13 | + }), |
| 14 | + ).toBe('~/foo.ts'); |
| 15 | + |
| 16 | + expect( |
| 17 | + resolveRuntimeConfigPath({ |
| 18 | + outputPath, |
| 19 | + runtimeConfigPath: '@/foo.ts', |
| 20 | + }), |
| 21 | + ).toBe('@/foo.ts'); |
| 22 | + |
| 23 | + expect( |
| 24 | + resolveRuntimeConfigPath({ |
| 25 | + outputPath, |
| 26 | + runtimeConfigPath: '@scope/runtime-config', |
| 27 | + }), |
| 28 | + ).toBe('@scope/runtime-config'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('resolves relative filesystem paths from cwd to output-relative import', () => { |
| 32 | + const outputPath = path.join(process.cwd(), 'src/client'); |
| 33 | + |
| 34 | + expect( |
| 35 | + resolveRuntimeConfigPath({ |
| 36 | + outputPath, |
| 37 | + runtimeConfigPath: './src/hey-api.ts', |
| 38 | + }), |
| 39 | + ).toBe('../hey-api.ts'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('resolves absolute filesystem paths to output-relative import', () => { |
| 43 | + const cwd = process.cwd(); |
| 44 | + const outputPath = path.join(cwd, 'src/client'); |
| 45 | + |
| 46 | + expect( |
| 47 | + resolveRuntimeConfigPath({ |
| 48 | + outputPath, |
| 49 | + runtimeConfigPath: path.join(cwd, 'src/runtime/hey-api.ts'), |
| 50 | + }), |
| 51 | + ).toBe('../runtime/hey-api.ts'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('adds ./ prefix for same-directory files', () => { |
| 55 | + const cwd = process.cwd(); |
| 56 | + const outputPath = path.join(cwd, 'src/client'); |
| 57 | + |
| 58 | + expect( |
| 59 | + resolveRuntimeConfigPath({ |
| 60 | + outputPath, |
| 61 | + runtimeConfigPath: path.join(cwd, 'src/client/hey-api.ts'), |
| 62 | + }), |
| 63 | + ).toBe('./hey-api.ts'); |
| 64 | + }); |
| 65 | +}); |
0 commit comments