1import { vol } from 'memfs'; 2 3import { loadTsConfigPathsAsync } from '../loadTsConfigPaths'; 4 5jest.mock('../evaluateTsConfig', () => ({ 6 evaluateTsConfig: jest.fn((ts, filepath) => { 7 return (require('@expo/json-file') as typeof import('@expo/json-file')).default.read(filepath, { 8 json5: true, 9 }); 10 }), 11 importTypeScriptFromProjectOptionally: jest.fn(() => ({})), 12})); 13 14describe(loadTsConfigPathsAsync, () => { 15 beforeEach(() => { 16 vol.reset(); 17 }); 18 it(`returns null if tsconfig doesn't exist`, async () => { 19 vol.fromJSON({}, '/'); 20 expect(await loadTsConfigPathsAsync('/')).toBeNull(); 21 }); 22 it(`returns just baseUrl`, async () => { 23 vol.fromJSON( 24 { 25 'jsconfig.json': '{}', 26 }, 27 '/' 28 ); 29 expect(await loadTsConfigPathsAsync('/')).toEqual({ baseUrl: '/', paths: undefined }); 30 }); 31 it(`returns jsconfig paths`, async () => { 32 vol.fromJSON( 33 { 34 'jsconfig.json': JSON.stringify({ 35 compilerOptions: { 36 baseUrl: 'src', 37 paths: { 38 '@foo/*': ['foo/*'], 39 }, 40 }, 41 }), 42 }, 43 '/' 44 ); 45 expect(await loadTsConfigPathsAsync('/')).toEqual({ 46 baseUrl: '/src', 47 paths: { '@foo/*': ['foo/*'] }, 48 }); 49 }); 50 it(`returns tsconfig before jsconfig`, async () => { 51 vol.fromJSON( 52 { 53 'tsconfig.json': JSON.stringify({ 54 compilerOptions: { 55 baseUrl: 'src', 56 paths: { 57 '@foo/*': ['foo/*'], 58 }, 59 }, 60 }), 61 'jsconfig.json': JSON.stringify({}), 62 }, 63 '/' 64 ); 65 expect(await loadTsConfigPathsAsync('/')).toEqual({ 66 baseUrl: '/src', 67 paths: { '@foo/*': ['foo/*'] }, 68 }); 69 }); 70}); 71