@@ -1021,13 +1021,18 @@ const a: string = "hello";`),
10211021 } ) ;
10221022 } ) ;
10231023
1024- describe ( "unittests:: tsbuild:: watchMode:: persistentResolutions" , ( ) => {
1025- verifyTscWatch ( {
1026- scenario : "persistResolutions" ,
1027- subScenario : "saves resolution and uses it for new program" ,
1028- sys : ( ) => createWatchedSystem ( [
1024+ describe ( "unittests:: tsbuild:: watchMode:: persistResolutions" , ( ) => {
1025+ function getSys ( outFile ?: string ) {
1026+ return createWatchedSystem ( [
10291027 {
10301028 path : `${ projectRoot } /src/main.ts` ,
1029+ content : Utils . dedent `
1030+ import { something } from "./filePresent";
1031+ import { something as something1 } from "./filePresent";
1032+ import { something2 } from "./fileNotFound";` ,
1033+ } ,
1034+ {
1035+ path : `${ projectRoot } /src/anotherFileReusingResolution.ts` ,
10311036 content : Utils . dedent `
10321037 import { something } from "./filePresent";
10331038 import { something2 } from "./fileNotFound";` ,
@@ -1044,12 +1049,42 @@ const a: string = "hello";`),
10441049 composite : true ,
10451050 persistResolutions : true ,
10461051 traceResolution : true ,
1052+ outFile
10471053 } ,
10481054 include : [ "src/**/*.ts" ]
10491055 } ) ,
10501056 } ,
10511057 libFile
1052- ] , { currentDirectory : projectRoot } ) ,
1058+ ] , { currentDirectory : projectRoot } ) ;
1059+ }
1060+
1061+ function getSysWithSavedResolutions ( outFile ?: string ) {
1062+ const sys = getSys ( outFile ) ;
1063+ const exit = sys . exit ;
1064+ sys . exit = noop ;
1065+ fakes . withTemporaryPatchingForBuildinfoReadWrite ( sys , sys => executeCommandLine ( sys , noop , [ "--b" , "." ] ) ) ;
1066+ sys . exit = exit ;
1067+ sys . clearOutput ( ) ;
1068+ return sys ;
1069+ }
1070+
1071+ function getSysWithClearedResolutions ( outFile ?: string ) {
1072+ const sys = getSys ( outFile ) ;
1073+ const exit = sys . exit ;
1074+ sys . exit = noop ;
1075+ fakes . withTemporaryPatchingForBuildinfoReadWrite ( sys , sys => {
1076+ executeCommandLine ( sys , noop , [ "--b" , "." ] ) ;
1077+ executeCommandLine ( sys , noop , [ "--b" , "." , "--cleanPersistedProgram" ] ) ;
1078+ } ) ;
1079+ sys . exit = exit ;
1080+ sys . clearOutput ( ) ;
1081+ return sys ;
1082+ }
1083+
1084+ verifyTscWatch ( {
1085+ scenario : "persistResolutions" ,
1086+ subScenario : "saves resolution and uses it for new program" ,
1087+ sys : getSys ,
10531088 commandLineArgs : [ "--b" , "." , "-w" , "--extendedDiagnostics" ] ,
10541089 changes : [
10551090 {
@@ -1078,39 +1113,7 @@ const a: string = "hello";`),
10781113 verifyTscWatch ( {
10791114 scenario : "persistResolutions" ,
10801115 subScenario : "can build after resolutions have been saved in tsbuildinfo file" ,
1081- sys : ( ) => {
1082- const sys = createWatchedSystem ( [
1083- {
1084- path : `${ projectRoot } /src/main.ts` ,
1085- content : Utils . dedent `
1086- import { something } from "./filePresent";
1087- import { something2 } from "./fileNotFound";` ,
1088- } ,
1089- {
1090- path : `${ projectRoot } /src/filePresent.ts` ,
1091- content : `export function something() { return 10; }` ,
1092- } ,
1093- {
1094- path : `${ projectRoot } /tsconfig.json` ,
1095- content : JSON . stringify ( {
1096- compilerOptions : {
1097- module : "amd" ,
1098- composite : true ,
1099- persistResolutions : true ,
1100- traceResolution : true ,
1101- } ,
1102- include : [ "src/**/*.ts" ]
1103- } ) ,
1104- } ,
1105- libFile
1106- ] , { currentDirectory : projectRoot } ) ;
1107- const exit = sys . exit ;
1108- sys . exit = noop ;
1109- fakes . withTemporaryPatchingForBuildinfoReadWrite ( sys , sys => executeCommandLine ( sys , noop , [ "--b" , "." ] ) ) ;
1110- sys . exit = exit ;
1111- sys . clearOutput ( ) ;
1112- return sys ;
1113- } ,
1116+ sys : getSysWithSavedResolutions ,
11141117 commandLineArgs : [ "--b" , "." , "-w" , "--extendedDiagnostics" ] ,
11151118 changes : [
11161119 {
@@ -1139,42 +1142,7 @@ const a: string = "hello";`),
11391142 verifyTscWatch ( {
11401143 scenario : "persistResolutions" ,
11411144 subScenario : "can build after resolutions are cleaned" ,
1142- sys : ( ) => {
1143- const sys = createWatchedSystem ( [
1144- {
1145- path : `${ projectRoot } /src/main.ts` ,
1146- content : Utils . dedent `
1147- import { something } from "./filePresent";
1148- import { something2 } from "./fileNotFound";` ,
1149- } ,
1150- {
1151- path : `${ projectRoot } /src/filePresent.ts` ,
1152- content : `export function something() { return 10; }` ,
1153- } ,
1154- {
1155- path : `${ projectRoot } /tsconfig.json` ,
1156- content : JSON . stringify ( {
1157- compilerOptions : {
1158- module : "amd" ,
1159- composite : true ,
1160- persistResolutions : true ,
1161- traceResolution : true ,
1162- } ,
1163- include : [ "src/**/*.ts" ]
1164- } ) ,
1165- } ,
1166- libFile
1167- ] , { currentDirectory : projectRoot } ) ;
1168- const exit = sys . exit ;
1169- sys . exit = noop ;
1170- fakes . withTemporaryPatchingForBuildinfoReadWrite ( sys , sys => {
1171- executeCommandLine ( sys , noop , [ "--b" , "." ] ) ;
1172- executeCommandLine ( sys , noop , [ "--b" , "." , "--cleanPersistedProgram" ] ) ;
1173- } ) ;
1174- sys . exit = exit ;
1175- sys . clearOutput ( ) ;
1176- return sys ;
1177- } ,
1145+ sys : getSysWithClearedResolutions ,
11781146 commandLineArgs : [ "--b" , "." , "-w" , "--extendedDiagnostics" ] ,
11791147 changes : [
11801148 {
@@ -1204,32 +1172,7 @@ const a: string = "hello";`),
12041172 verifyTscWatch ( {
12051173 scenario : "persistResolutions" ,
12061174 subScenario : "saves resolution and uses it for new program with outFile" ,
1207- sys : ( ) => createWatchedSystem ( [
1208- {
1209- path : `${ projectRoot } /src/main.ts` ,
1210- content : Utils . dedent `
1211- import { something } from "./filePresent";
1212- import { something2 } from "./fileNotFound";` ,
1213- } ,
1214- {
1215- path : `${ projectRoot } /src/filePresent.ts` ,
1216- content : `export function something() { return 10; }` ,
1217- } ,
1218- {
1219- path : `${ projectRoot } /tsconfig.json` ,
1220- content : JSON . stringify ( {
1221- compilerOptions : {
1222- module : "amd" ,
1223- composite : true ,
1224- persistResolutions : true ,
1225- traceResolution : true ,
1226- outFile : "outFile.js"
1227- } ,
1228- include : [ "src/**/*.ts" ]
1229- } ) ,
1230- } ,
1231- libFile
1232- ] , { currentDirectory : projectRoot } ) ,
1175+ sys : ( ) => getSys ( "outFile.js" ) ,
12331176 commandLineArgs : [ "--b" , "." , "-w" , "--extendedDiagnostics" ] ,
12341177 changes : [
12351178 {
@@ -1258,40 +1201,7 @@ const a: string = "hello";`),
12581201 verifyTscWatch ( {
12591202 scenario : "persistResolutions" ,
12601203 subScenario : "can build after resolutions have been saved in tsbuildinfo file with outFile" ,
1261- sys : ( ) => {
1262- const sys = createWatchedSystem ( [
1263- {
1264- path : `${ projectRoot } /src/main.ts` ,
1265- content : Utils . dedent `
1266- import { something } from "./filePresent";
1267- import { something2 } from "./fileNotFound";` ,
1268- } ,
1269- {
1270- path : `${ projectRoot } /src/filePresent.ts` ,
1271- content : `export function something() { return 10; }` ,
1272- } ,
1273- {
1274- path : `${ projectRoot } /tsconfig.json` ,
1275- content : JSON . stringify ( {
1276- compilerOptions : {
1277- module : "amd" ,
1278- composite : true ,
1279- persistResolutions : true ,
1280- traceResolution : true ,
1281- outFile : "outFile.js"
1282- } ,
1283- include : [ "src/**/*.ts" ]
1284- } ) ,
1285- } ,
1286- libFile
1287- ] , { currentDirectory : projectRoot } ) ;
1288- const exit = sys . exit ;
1289- sys . exit = noop ;
1290- fakes . withTemporaryPatchingForBuildinfoReadWrite ( sys , sys => executeCommandLine ( sys , noop , [ "--b" , "." ] ) ) ;
1291- sys . exit = exit ;
1292- sys . clearOutput ( ) ;
1293- return sys ;
1294- } ,
1204+ sys : ( ) => getSysWithSavedResolutions ( "outFile.js" ) ,
12951205 commandLineArgs : [ "--b" , "." , "-w" , "--extendedDiagnostics" ] ,
12961206 changes : [
12971207 {
@@ -1320,43 +1230,7 @@ const a: string = "hello";`),
13201230 verifyTscWatch ( {
13211231 scenario : "persistResolutions" ,
13221232 subScenario : "can build after resolutions are cleaned with outFile" ,
1323- sys : ( ) => {
1324- const sys = createWatchedSystem ( [
1325- {
1326- path : `${ projectRoot } /src/main.ts` ,
1327- content : Utils . dedent `
1328- import { something } from "./filePresent";
1329- import { something2 } from "./fileNotFound";` ,
1330- } ,
1331- {
1332- path : `${ projectRoot } /src/filePresent.ts` ,
1333- content : `export function something() { return 10; }` ,
1334- } ,
1335- {
1336- path : `${ projectRoot } /tsconfig.json` ,
1337- content : JSON . stringify ( {
1338- compilerOptions : {
1339- module : "amd" ,
1340- composite : true ,
1341- persistResolutions : true ,
1342- traceResolution : true ,
1343- outFile : "outFile.js"
1344- } ,
1345- include : [ "src/**/*.ts" ]
1346- } ) ,
1347- } ,
1348- libFile
1349- ] , { currentDirectory : projectRoot } ) ;
1350- const exit = sys . exit ;
1351- sys . exit = noop ;
1352- fakes . withTemporaryPatchingForBuildinfoReadWrite ( sys , sys => {
1353- executeCommandLine ( sys , noop , [ "--b" , "." ] ) ;
1354- executeCommandLine ( sys , noop , [ "--b" , "." , "--cleanPersistedProgram" ] ) ;
1355- } ) ;
1356- sys . exit = exit ;
1357- sys . clearOutput ( ) ;
1358- return sys ;
1359- } ,
1233+ sys : ( ) => getSysWithClearedResolutions ( "outFile.js" ) ,
13601234 commandLineArgs : [ "--b" , "." , "-w" , "--extendedDiagnostics" ] ,
13611235 changes : [
13621236 {
0 commit comments