@@ -1375,78 +1375,70 @@ function foo() {
13751375 } ) ;
13761376
13771377 describe ( "when references are monorepo like with symlinks" , ( ) => {
1378- function verifySession ( alreadyBuilt : boolean , extraOptions : CompilerOptions ) {
1379- const bPackageJson : File = {
1380- path : `${ projectRoot } /packages/B/package.json` ,
1381- content : JSON . stringify ( {
1382- main : "lib/index.js" ,
1383- types : "lib/index.d.ts"
1384- } )
1385- } ;
1378+ interface Packages {
1379+ bPackageJson : File ;
1380+ aTest : File ;
1381+ bFoo : File ;
1382+ bBar : File ;
1383+ }
1384+ function verifySymlinkScenario ( packages : ( ) => Packages ) {
1385+ describe ( "when solution is not built" , ( ) => {
1386+ it ( "with preserveSymlinks turned off" , ( ) => {
1387+ verifySession ( packages ( ) , /*alreadyBuilt*/ false , { } ) ;
1388+ } ) ;
1389+
1390+ it ( "with preserveSymlinks turned on" , ( ) => {
1391+ verifySession ( packages ( ) , /*alreadyBuilt*/ false , { preserveSymlinks : true } ) ;
1392+ } ) ;
1393+ } ) ;
1394+
1395+ describe ( "when solution is already built" , ( ) => {
1396+ it ( "with preserveSymlinks turned off" , ( ) => {
1397+ verifySession ( packages ( ) , /*alreadyBuilt*/ true , { } ) ;
1398+ } ) ;
1399+
1400+ it ( "with preserveSymlinks turned on" , ( ) => {
1401+ verifySession ( packages ( ) , /*alreadyBuilt*/ true , { preserveSymlinks : true } ) ;
1402+ } ) ;
1403+ } ) ;
1404+ }
1405+
1406+ function verifySession ( { bPackageJson, aTest, bFoo, bBar } : Packages , alreadyBuilt : boolean , extraOptions : CompilerOptions ) {
13861407 const aConfig = config ( "A" , extraOptions , [ "../B" ] ) ;
13871408 const bConfig = config ( "B" , extraOptions ) ;
1388- const aIndex = index ( "A" , `import { foo } from 'b';
1389- import { bar } from 'b/lib/bar';
1390- foo();
1391- bar();` ) ;
1392- const bIndex = index ( "B" , `export function foo() { }` ) ;
1393- const bBar : File = {
1394- path : `${ projectRoot } /packages/B/src/bar.ts` ,
1395- content : `export function bar() { }`
1396- } ;
13971409 const bSymlink : SymLink = {
13981410 path : `${ projectRoot } /node_modules/b` ,
13991411 symLink : `${ projectRoot } /packages/B`
14001412 } ;
1401-
1402- const files = [ libFile , bPackageJson , aConfig , bConfig , aIndex , bIndex , bBar , bSymlink ] ;
1413+ const files = [ libFile , bPackageJson , aConfig , bConfig , aTest , bFoo , bBar , bSymlink ] ;
14031414 const host = alreadyBuilt ?
14041415 createHost ( files , [ aConfig . path ] ) :
14051416 createServerHost ( files ) ;
14061417
14071418 // Create symlink in node module
14081419 const session = createSession ( host , { canUseEvents : true } ) ;
1409- openFilesForSession ( [ aIndex ] , session ) ;
1420+ openFilesForSession ( [ aTest ] , session ) ;
14101421 const service = session . getProjectService ( ) ;
14111422 const project = service . configuredProjects . get ( aConfig . path . toLowerCase ( ) ) ! ;
14121423 assert . deepEqual ( project . getAllProjectErrors ( ) , [ ] ) ;
14131424 checkProjectActualFiles (
14141425 project ,
1415- [ aConfig . path , aIndex . path , bIndex . path , bBar . path , libFile . path ]
1426+ [ aConfig . path , aTest . path , bFoo . path , bBar . path , libFile . path ]
14161427 ) ;
14171428 verifyGetErrRequest ( {
14181429 host,
14191430 session,
14201431 expected : [
1421- { file : aIndex , syntax : [ ] , semantic : [ ] , suggestion : [ ] }
1432+ { file : aTest , syntax : [ ] , semantic : [ ] , suggestion : [ ] }
14221433 ]
14231434 } ) ;
14241435 }
14251436
1426- function verifySymlinkScenario ( alreadyBuilt : boolean ) {
1427- it ( "with preserveSymlinks turned off" , ( ) => {
1428- verifySession ( alreadyBuilt , { } ) ;
1429- } ) ;
1430-
1431- it ( "with preserveSymlinks turned on" , ( ) => {
1432- verifySession ( alreadyBuilt , { preserveSymlinks : true } ) ;
1433- } ) ;
1434- }
1435-
1436- describe ( "when solution is not built" , ( ) => {
1437- verifySymlinkScenario ( /*alreadyBuilt*/ false ) ;
1438- } ) ;
1439-
1440- describe ( "when solution is already built" , ( ) => {
1441- verifySymlinkScenario ( /*alreadyBuilt*/ true ) ;
1442- } ) ;
1443-
14441437 function config ( packageName : string , extraOptions : CompilerOptions , references ?: string [ ] ) : File {
14451438 return {
14461439 path : `${ projectRoot } /packages/${ packageName } /tsconfig.json` ,
14471440 content : JSON . stringify ( {
14481441 compilerOptions : {
1449- baseUrl : "." ,
14501442 outDir : "lib" ,
14511443 rootDir : "src" ,
14521444 composite : true ,
@@ -1458,12 +1450,45 @@ bar();`);
14581450 } ;
14591451 }
14601452
1461- function index ( packageName : string , content : string ) : File {
1453+ function file ( packageName : string , fileName : string , content : string ) : File {
14621454 return {
1463- path : `${ projectRoot } /packages/${ packageName } /src/index.ts ` ,
1455+ path : `${ projectRoot } /packages/${ packageName } /src/${ fileName } ` ,
14641456 content
14651457 } ;
14661458 }
1459+
1460+ describe ( "when packageJson has types field and has index.ts" , ( ) => {
1461+ verifySymlinkScenario ( ( ) => ( {
1462+ bPackageJson : {
1463+ path : `${ projectRoot } /packages/B/package.json` ,
1464+ content : JSON . stringify ( {
1465+ main : "lib/index.js" ,
1466+ types : "lib/index.d.ts"
1467+ } )
1468+ } ,
1469+ aTest : file ( "A" , "index.ts" , `import { foo } from 'b';
1470+ import { bar } from 'b/lib/bar';
1471+ foo();
1472+ bar();` ) ,
1473+ bFoo : file ( "B" , "index.ts" , `export function foo() { }` ) ,
1474+ bBar : file ( "B" , "bar.ts" , `export function bar() { }` )
1475+ } ) ) ;
1476+ } ) ;
1477+
1478+ describe ( "when referencing file from subFolder" , ( ) => {
1479+ verifySymlinkScenario ( ( ) => ( {
1480+ bPackageJson : {
1481+ path : `${ projectRoot } /packages/B/package.json` ,
1482+ content : "{}"
1483+ } ,
1484+ aTest : file ( "A" , "test.ts" , `import { foo } from 'b/lib/foo';
1485+ import { bar } from 'b/lib/bar/foo';
1486+ foo();
1487+ bar();` ) ,
1488+ bFoo : file ( "B" , "foo.ts" , `export function foo() { }` ) ,
1489+ bBar : file ( "B" , "bar/foo.ts" , `export function bar() { }` )
1490+ } ) ) ;
1491+ } ) ;
14671492 } ) ;
14681493 } ) ;
14691494}
0 commit comments