diff --git a/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts b/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts index e6048f6c7a6c6..77e2de13023c8 100644 --- a/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts +++ b/src/testRunner/unittests/tsserver/cachingFileSystemInformation.ts @@ -76,7 +76,7 @@ namespace ts.projectSystem { }; const host = createServerHost([root, imported]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.setCompilerOptionsForInferredProjects({ module: ModuleKind.AMD, noLib: true }); projectService.openClientFile(root.path); const project = projectService.inferredProjects[0]; @@ -134,7 +134,7 @@ namespace ts.projectSystem { }; const host = createServerHost([root]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.setCompilerOptionsForInferredProjects({ module: ModuleKind.AMD, noLib: true }); const logCacheAndClear = createLoggerTrackingHostCalls(host); projectService.openClientFile(root.path); @@ -146,7 +146,7 @@ namespace ts.projectSystem { logCacheAndClear(projectService.logger); host.writeFile(imported.path, imported.content); - host.runQueuedTimeoutCallbacks(); + projectService.runQueuedTimeoutCallbacks(); logSemanticDiagnostics(projectService, project, root); logCacheAndClear(projectService.logger); baselineTsserverLogs("cachingFileSystemInformation", "loads missing files from disk", projectService); @@ -195,7 +195,7 @@ namespace ts.projectSystem { }; const projectFiles = [clientFile, anotherModuleFile, moduleFile, tsconfigFile]; const host = createServerHost(projectFiles); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([clientFile], session); const logCacheAndClear = createLoggerTrackingHostCalls(host); @@ -273,14 +273,14 @@ namespace ts.projectSystem { }; const projectFiles = [file1, file2, es2016LibFile, tsconfigFile]; const host = createServerHost(projectFiles, { useCaseSensitiveFileNames }); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(file1.path); const logCacheAndClear = createLoggerTrackingHostCalls(host); // Create file cookie.ts host.writeFile(file3.path, file3.content); - host.runQueuedTimeoutCallbacks(); + projectService.runQueuedTimeoutCallbacks(); logCacheAndClear(projectService.logger); projectService.openClientFile(file3.path); @@ -383,7 +383,7 @@ namespace ts.projectSystem { ` }); const host = createServerHost([app, libFile, tsconfigJson, packageJson]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.setHostConfiguration({ preferences: { includePackageJsonAutoImports: "off" } }); projectService.openClientFile(app.path); @@ -479,15 +479,15 @@ namespace ts.projectSystem { if (npmInstallComplete || timeoutDuringPartialInstallation) { if (timeoutQueueLengthWhenRunningTimeouts) { // Expected project update - host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions - host.runQueuedTimeoutCallbacks(); // Actual update + projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts + 1); // Scheduled invalidation of resolutions + projectService.runQueuedTimeoutCallbacks(); // Actual update } else { - host.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts); + projectService.checkTimeoutQueueLengthAndRun(timeoutQueueLengthWhenRunningTimeouts); } } else { - host.checkTimeoutQueueLength(3); + projectService.checkTimeoutQueueLength(3); } } } diff --git a/src/testRunner/unittests/tsserver/configFileSearch.ts b/src/testRunner/unittests/tsserver/configFileSearch.ts index 39ba56ced2127..02829a326f997 100644 --- a/src/testRunner/unittests/tsserver/configFileSearch.ts +++ b/src/testRunner/unittests/tsserver/configFileSearch.ts @@ -38,12 +38,12 @@ namespace ts.projectSystem { content: "{}" }; const host = createServerHost([f1, libFile, configFile, configFile2]); - const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); service.openClientFile(f1.path, /*fileContent*/ undefined, /*scriptKind*/ undefined, projectDir); // Delete config file - should create inferred project and not configured project host.deleteFile(configFile.path); - host.runQueuedTimeoutCallbacks(); + service.runQueuedTimeoutCallbacks(); checkNumberOfProjects(service, { inferredProjects: 1 }); baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again", service); }); @@ -67,13 +67,13 @@ namespace ts.projectSystem { const service = createProjectService(host, { useSingleInferredProject: true, useInferredProjectPerProjectRoot: true, - logger: createLoggerWithInMemoryLogs(), + logger: createLoggerWithInMemoryLogs(host), }); service.openClientFile(f1.path, /*fileContent*/ undefined, /*scriptKind*/ undefined, projectDir); // Delete config file - should create inferred project with project root path set host.deleteFile(configFile.path); - host.runQueuedTimeoutCallbacks(); + service.runQueuedTimeoutCallbacks(); baselineTsserverLogs("configFileSearch", "should use projectRootPath when searching for inferred project again 2", service); }); @@ -89,7 +89,7 @@ namespace ts.projectSystem { }; function openClientFile(files: File[]) { const host = createServerHost(files); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(file.path, /*fileContent*/ undefined, /*scriptKind*/ undefined, "/a/b/projects/proj"); return { host, projectService }; } @@ -98,10 +98,10 @@ namespace ts.projectSystem { const { host, projectService } = openClientFile([file, libFile, tsconfig]); host.deleteFile(tsconfig.path); - host.runQueuedTimeoutCallbacks(); + projectService.runQueuedTimeoutCallbacks(); host.writeFile(tsconfig.path, tsconfig.content); - host.runQueuedTimeoutCallbacks(); + projectService.runQueuedTimeoutCallbacks(); baselineTsserverLogs("configFileSearch", "tsconfig for the file exists", projectService); }); @@ -110,10 +110,10 @@ namespace ts.projectSystem { const { host, projectService } = openClientFile([file, libFile]); host.writeFile(tsconfig.path, tsconfig.content); - host.runQueuedTimeoutCallbacks(); + projectService.runQueuedTimeoutCallbacks(); host.deleteFile(tsconfig.path); - host.runQueuedTimeoutCallbacks(); + projectService.runQueuedTimeoutCallbacks(); baselineTsserverLogs("configFileSearch", "tsconfig for the file does not exist", projectService); }); @@ -124,7 +124,7 @@ namespace ts.projectSystem { it(scenario, () => { const path = `/root/teams/VSCode68/Shared Documents/General/jt-ts-test-workspace/x.js`; const host = createServerHost([libFile, { path, content: "const x = 10" }], { useCaseSensitiveFileNames: true }); - const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); service.openClientFile(path, /*fileContent*/ undefined, /*scriptKind*/ undefined, projectRootPath); baselineTsserverLogs("configFileSearch", scenario, service); }); diff --git a/src/testRunner/unittests/tsserver/configuredProjects.ts b/src/testRunner/unittests/tsserver/configuredProjects.ts index d8246838c0756..7e0446fd58626 100644 --- a/src/testRunner/unittests/tsserver/configuredProjects.ts +++ b/src/testRunner/unittests/tsserver/configuredProjects.ts @@ -25,7 +25,7 @@ namespace ts.projectSystem { }; const host = createServerHost([configFile, libFile, file1, file2, file3]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); const { configFileName, configFileErrors } = projectService.openClientFile(file1.path); assert(configFileName, "should find config file"); @@ -57,7 +57,7 @@ namespace ts.projectSystem { }; const host = createServerHost([configFile, libFile, file1, file2, file3]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); const { configFileName, configFileErrors } = projectService.openClientFile(file1.path); assert(configFileName, "should find config file"); @@ -84,17 +84,17 @@ namespace ts.projectSystem { const host = createServerHost([libFile, commonFile1, commonFile2]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(commonFile1.path); projectService.openClientFile(commonFile2.path); // Add a tsconfig file host.writeFile(configFile.path, configFile.content); - host.checkTimeoutQueueLengthAndRun(2); // load configured project from disk + ensureProjectsForOpenFiles + projectService.checkTimeoutQueueLengthAndRun(2); // load configured project from disk + ensureProjectsForOpenFiles // remove the tsconfig file host.deleteFile(configFile.path); - host.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects + projectService.checkTimeoutQueueLengthAndRun(1); // Refresh inferred projects baselineTsserverLogs("configuredProjects", "add and then remove a config file in a folder with loose files", projectService); }); @@ -105,12 +105,12 @@ namespace ts.projectSystem { content: `{}` }; const host = createServerHost([commonFile1, libFile, configFile]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(commonFile1.path); // add a new ts file host.writeFile(commonFile2.path, commonFile2.content); - host.checkTimeoutQueueLengthAndRun(2); + projectService.checkTimeoutQueueLengthAndRun(2); baselineTsserverLogs("configuredProjects", "add new files to a configured project without file list", projectService); }); @@ -537,7 +537,7 @@ namespace ts.projectSystem { const files = [file1, file2, file3, file4]; const host = createServerHost(files.concat(configFile)); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(file1.path); projectService.openClientFile(file2.path); @@ -548,7 +548,7 @@ namespace ts.projectSystem { assert.isTrue(configProject1.hasOpenRef()); // file1 and file3 host.writeFile(configFile.path, "{}"); - host.runQueuedTimeoutCallbacks(); + projectService.runQueuedTimeoutCallbacks(); assert.isTrue(configProject1.hasOpenRef()); // file1, file2, file3 assert.isTrue(projectService.inferredProjects[0].isOrphan()); @@ -577,6 +577,7 @@ namespace ts.projectSystem { content: "let zz = 1;" }; host.writeFile(file5.path, file5.content); + projectService.baselineHost("File5 written"); projectService.openClientFile(file5.path); baselineTsserverLogs("configuredProjects", "Open ref of configured project when open file gets added to the project as part of configured file update", projectService); @@ -793,7 +794,7 @@ declare var console: { };` }; const host = createServerHost([barConfig, barIndex, fooConfig, fooIndex, barSymLink, lib2017, libDom]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([fooIndex, barIndex], session); verifyGetErrRequest({ session, host, files: [barIndex, fooIndex] }); baselineTsserverLogs("configuredProjects", "when multiple projects are open detects correct default project", session); @@ -851,7 +852,7 @@ declare var console: { ]); const session = createSession(host, { canUseEvents: true, - logger: createLoggerWithInMemoryLogs(), + logger: createLoggerWithInMemoryLogs(host), }); session.executeCommandSeq({ command: protocol.CommandTypes.Open, @@ -1017,7 +1018,7 @@ foo();` }; const host = createServerHost([alphaExtendedConfig, aConfig, aFile, bravoExtendedConfig, bConfig, bFile, ...(additionalFiles || emptyArray)]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); return { host, projectService, aFile, bFile, aConfig, bConfig, alphaExtendedConfig, bravoExtendedConfig }; } @@ -1032,7 +1033,7 @@ foo();` strict: true } })); - host.checkTimeoutQueueLengthAndRun(3); + projectService.checkTimeoutQueueLengthAndRun(3); host.writeFile(bravoExtendedConfig.path, JSON.stringify({ extends: "./alpha.tsconfig.json", @@ -1040,15 +1041,15 @@ foo();` strict: false } })); - host.checkTimeoutQueueLengthAndRun(2); + projectService.checkTimeoutQueueLengthAndRun(2); host.writeFile(bConfig.path, JSON.stringify({ extends: "../extended/alpha.tsconfig.json", })); - host.checkTimeoutQueueLengthAndRun(2); + projectService.checkTimeoutQueueLengthAndRun(2); host.writeFile(alphaExtendedConfig.path, "{}"); - host.checkTimeoutQueueLengthAndRun(3); + projectService.checkTimeoutQueueLengthAndRun(3); baselineTsserverLogs("configuredProjects", "should watch the extended configs of multiple projects", projectService); }); @@ -1178,12 +1179,12 @@ foo();` }; const files = [file1, file2a, configFile, libFile]; const host = createServerHost(files); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(file1.path); host.writeFile(file2.path, file2.content); - host.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions - host.runQueuedTimeoutCallbacks(); // Actual update + projectService.runQueuedTimeoutCallbacks(); // Scheduled invalidation of resolutions + projectService.runQueuedTimeoutCallbacks(); // Actual update // On next file open the files file2a should be closed and not watched any more projectService.openClientFile(file2.path); @@ -1217,7 +1218,7 @@ foo();` nonLibFiles.forEach(f => f.path = root + f.path); const files = nonLibFiles.concat(libFile); const host = createServerHost(files); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(file1.path); baselineTsserverLogs("configuredProjects", "failed lookup locations uses parent most node_modules directory", projectService); }); diff --git a/src/testRunner/unittests/tsserver/events/projectLanguageServiceState.ts b/src/testRunner/unittests/tsserver/events/projectLanguageServiceState.ts index 08d66db76a16c..ab54f63075221 100644 --- a/src/testRunner/unittests/tsserver/events/projectLanguageServiceState.ts +++ b/src/testRunner/unittests/tsserver/events/projectLanguageServiceState.ts @@ -68,11 +68,11 @@ namespace ts.projectSystem { content: "{}" }; const host = createServerHost([f1, f2, f3, libFile, config]); - const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const service = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); service.openClientFile(f1.path); const project = service.configuredProjects.get(config.path)!; - service.logger.logs.push(`languageServiceEnabled: ${project.languageServiceEnabled}`); - service.logger.logs.push(`lastFileExceededProgramSize: ${project.lastFileExceededProgramSize}`); + service.logger.info(`languageServiceEnabled: ${project.languageServiceEnabled}`); + service.logger.info(`lastFileExceededProgramSize: ${project.lastFileExceededProgramSize}`); baselineTsserverLogs("projectLanguageServiceStateEvent", "large file size is determined correctly", service); }); }); diff --git a/src/testRunner/unittests/tsserver/events/projectUpdatedInBackground.ts b/src/testRunner/unittests/tsserver/events/projectUpdatedInBackground.ts index 248fd25e95ca3..61991ef4a89fa 100644 --- a/src/testRunner/unittests/tsserver/events/projectUpdatedInBackground.ts +++ b/src/testRunner/unittests/tsserver/events/projectUpdatedInBackground.ts @@ -437,12 +437,12 @@ namespace ts.projectSystem { const openFiles = [file1.path]; const host = createServerHost([file1, file3, libFile, configFile]); - const { session, verifyInitialOpen, verifyProjectsUpdatedInBackgroundEventHandler } = createSession(host, createLoggerWithInMemoryLogs()); + const { session, verifyInitialOpen, verifyProjectsUpdatedInBackgroundEventHandler } = createSession(host, createLoggerWithInMemoryLogs(host)); verifyInitialOpen(file1); file3.content += "export class d {}"; host.writeFile(file3.path, file3.content); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); // Since this is first event verifyProjectsUpdatedInBackgroundEventHandler([{ @@ -453,8 +453,8 @@ namespace ts.projectSystem { }]); host.writeFile(file2.path, file2.content); - host.runQueuedTimeoutCallbacks(); // For invalidation - host.runQueuedTimeoutCallbacks(); // For actual update + session.runQueuedTimeoutCallbacks(); // For invalidation + session.runQueuedTimeoutCallbacks(); // For actual update verifyProjectsUpdatedInBackgroundEventHandler(useSlashRootAsSomeNotRootFolderInUserDirectory ? [{ eventName: server.ProjectsUpdatedInBackgroundEvent, diff --git a/src/testRunner/unittests/tsserver/forceConsistentCasingInFileNames.ts b/src/testRunner/unittests/tsserver/forceConsistentCasingInFileNames.ts index 674556e8cf135..2e834a43ad402 100644 --- a/src/testRunner/unittests/tsserver/forceConsistentCasingInFileNames.ts +++ b/src/testRunner/unittests/tsserver/forceConsistentCasingInFileNames.ts @@ -59,7 +59,7 @@ namespace ts.projectSystem { }; const host = createServerHost([loggerFile, anotherFile, tsconfig, libFile, tsconfig]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([{ file: loggerFile, projectRootPath: tscWatch.projectRoot }], session); verifyGetErrRequest({ session, host, files: [loggerFile] }); @@ -108,7 +108,7 @@ namespace ts.projectSystem { }; const host = createServerHost([loggerFile, anotherFile, tsconfig, libFile, tsconfig]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([{ file: anotherFile, projectRootPath: tscWatch.projectRoot }], session); verifyGetErrRequest({ session, host, files: [anotherFile] }); diff --git a/src/testRunner/unittests/tsserver/helpers.ts b/src/testRunner/unittests/tsserver/helpers.ts index f87355f7491f9..6a8504aeef4ac 100644 --- a/src/testRunner/unittests/tsserver/helpers.ts +++ b/src/testRunner/unittests/tsserver/helpers.ts @@ -53,6 +53,7 @@ namespace ts.projectSystem { export interface Logger extends server.Logger { logs: string[]; + host?: TestServerHost; } export function nullLogger(): Logger { @@ -77,20 +78,52 @@ namespace ts.projectSystem { }; } - export function createLoggerWritingToConsole(): Logger { - return { + function handleLoggerGroup(logger: Logger, host: TestServerHost | undefined): Logger { + let inGroup = false; + let firstInGroup = false; + let seq = 0; + logger.startGroup = () => { + inGroup = true; + firstInGroup = true; + }; + logger.endGroup = () => inGroup = false; + logger.host = host; + const originalInfo = logger.info; + logger.info = s => msg(s, server.Msg.Info, s => originalInfo.call(logger, s)); + return logger; + + function msg(s: string, type = server.Msg.Err, write: (s: string) => void) { + s = `[${nowString()}] ${s}`; + if (!inGroup || firstInGroup) s = padStringRight(type + " " + seq.toString(), " ") + s; + write(s); + if (!inGroup) seq++; + } + + function padStringRight(str: string, padding: string) { + return (str + padding).slice(0, padding.length); + } + + function nowString() { + // E.g. "12:34:56.789" + const d = logger.host!.now(); + return `${padLeft(d.getUTCHours().toString(), 2, "0")}:${padLeft(d.getUTCMinutes().toString(), 2, "0")}:${padLeft(d.getUTCSeconds().toString(), 2, "0")}.${padLeft(d.getUTCMilliseconds().toString(), 3, "0")}`; + } + } + + export function createLoggerWritingToConsole(host: TestServerHost): Logger { + return handleLoggerGroup({ ...nullLogger(), hasLevel: returnTrue, loggingEnabled: returnTrue, perftrc: s => console.log(s), info: s => console.log(s), msg: (s, type) => console.log(`${type}:: ${s}`), - }; + }, host); } - export function createLoggerWithInMemoryLogs(): Logger { + export function createLoggerWithInMemoryLogs(host: TestServerHost): Logger { const logger = createHasErrorMessageLogger(); - return { + return handleLoggerGroup({ ...logger, hasLevel: returnTrue, loggingEnabled: returnTrue, @@ -109,9 +142,9 @@ namespace ts.projectSystem { .replace(/getExportInfoMap: done in \d+(?:\.\d+)?/g, `getExportInfoMap: done in *`) .replace(/collectAutoImports: \d+(?:\.\d+)?/g, `collectAutoImports: *`) .replace(/dependencies in \d+(?:\.\d+)?/g, `dependencies in *`) - .replace(/\"exportMapKey\"\:\"[_$a-zA-Z][_$_$a-zA-Z0-9]*\|\d+\|/g, match => match.replace(/\|\d+\|/, `|*|`)) + .replace(/\"exportMapKey\"\:\s*\"[_$a-zA-Z][_$_$a-zA-Z0-9]*\|\d+\|/g, match => match.replace(/\|\d+\|/, `|*|`)) ) - }; + }, host); } export function baselineTsserverLogs(scenario: string, subScenario: string, sessionOrService: { logger: Logger; }) { @@ -316,12 +349,14 @@ namespace ts.projectSystem { export class TestSession extends server.Session { private seq = 0; public events: protocol.Event[] = []; - public testhost: TestServerHost = this.host as TestServerHost; + public testhost: TestFSWithWatch.TestServerHostTrackingWrittenFiles; public logger: Logger; + private hostDiff: ReturnType | undefined; constructor(opts: TestSessionOptions) { super(opts); this.logger = opts.logger; + this.testhost = TestFSWithWatch.changeToHostTrackingWrittenFiles(this.host as TestServerHost); } getProjectService() { @@ -337,11 +372,7 @@ namespace ts.projectSystem { } public executeCommand(request: protocol.Request) { - const verboseLogging = this.logger.hasLevel(server.LogLevel.verbose); - if (verboseLogging) this.logger.info(`request:${JSON.stringify(request)}`); - const result = super.executeCommand(request); - if (verboseLogging) this.logger.info(`response:${JSON.stringify(result)}`); - return result; + return this.baseline("response", super.executeCommand(this.baseline("request", request))); } public executeCommandSeq(request: Partial) { @@ -360,6 +391,46 @@ namespace ts.projectSystem { clear(this.events); this.testhost.clearOutput(); } + + private baseline(type: "request" | "response", requestOrResult: T): T { + if (!this.logger.hasLevel(server.LogLevel.verbose)) return requestOrResult; + if (type === "request") this.logger.info(`request:${server.indent(JSON.stringify(requestOrResult, undefined, 2))}`); + this.baselineHost(type === "request" ? "Before request" : "After request"); + if (type === "response") this.logger.info(`response:${server.indent(JSON.stringify(requestOrResult, undefined, 2))}`); + return requestOrResult; + } + + baselineHost(title: string) { + if (!this.logger.hasLevel(server.LogLevel.verbose)) return; + this.logger.logs.push(title); + this.testhost.diff(this.logger.logs, this.hostDiff); + this.testhost.serializeWatches(this.logger.logs); + this.hostDiff = this.testhost.snap(); + this.testhost.writtenFiles.clear(); + } + + checkTimeoutQueueLengthAndRun(expected: number) { + this.baselineHost(`Before checking timeout queue length (${expected}) and running`); + this.testhost.checkTimeoutQueueLengthAndRun(expected); + this.baselineHost(`After checking timeout queue length (${expected}) and running`); + } + + checkTimeoutQueueLength(expected: number) { + this.baselineHost(`Checking timeout queue length: ${expected}`); + this.testhost.checkTimeoutQueueLength(expected); + } + + runQueuedTimeoutCallbacks(timeoutId?: number) { + this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`); + this.testhost.runQueuedTimeoutCallbacks(timeoutId); + this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`); + } + + runQueuedImmediateCallbacks(checkCount?: number) { + this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`); + this.testhost.runQueuedImmediateCallbacks(checkCount); + this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`); + } } export function createSession(host: server.ServerHost, opts: Partial = {}) { @@ -426,7 +497,9 @@ namespace ts.projectSystem { } export class TestProjectService extends server.ProjectService { - constructor(host: server.ServerHost, public logger: Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean, + public testhost: TestFSWithWatch.TestServerHostTrackingWrittenFiles; + private hostDiff: ReturnType | undefined; + constructor(host: TestServerHost, public logger: Logger, cancellationToken: HostCancellationToken, useSingleInferredProject: boolean, typingsInstaller: server.ITypingsInstaller, opts: Partial = {}) { super({ host, @@ -439,14 +512,48 @@ namespace ts.projectSystem { typesMapLocation: customTypesMap.path, ...opts }); + this.testhost = TestFSWithWatch.changeToHostTrackingWrittenFiles(this.host as TestServerHost); + this.baselineHost("Creating project service"); } checkNumberOfProjects(count: { inferredProjects?: number, configuredProjects?: number, externalProjects?: number }) { checkNumberOfProjects(this, count); } + + baselineHost(title: string) { + if (!this.logger.hasLevel(server.LogLevel.verbose)) return; + this.logger.logs.push(title); + this.testhost.diff(this.logger.logs, this.hostDiff); + this.testhost.serializeWatches(this.logger.logs); + this.hostDiff = this.testhost.snap(); + this.testhost.writtenFiles.clear(); + } + + checkTimeoutQueueLengthAndRun(expected: number) { + this.baselineHost(`Before checking timeout queue length (${expected}) and running`); + this.testhost.checkTimeoutQueueLengthAndRun(expected); + this.baselineHost(`After checking timeout queue length (${expected}) and running`); + } + + checkTimeoutQueueLength(expected: number) { + this.baselineHost(`Checking timeout queue length: ${expected}`); + this.testhost.checkTimeoutQueueLength(expected); + } + + runQueuedTimeoutCallbacks(timeoutId?: number) { + this.baselineHost(`Before running timeout callback${timeoutId === undefined ? "s" : timeoutId}`); + this.testhost.runQueuedTimeoutCallbacks(timeoutId); + this.baselineHost(`After running timeout callback${timeoutId === undefined ? "s" : timeoutId}`); + } + + runQueuedImmediateCallbacks(checkCount?: number) { + this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`); + this.testhost.runQueuedImmediateCallbacks(checkCount); + this.baselineHost(`Before running immediate callbacks${checkCount === undefined ? "" : ` and checking length (${checkCount})`}`); + } } - export function createProjectService(host: server.ServerHost, options?: Partial) { + export function createProjectService(host: TestServerHost, options?: Partial) { const cancellationToken = options?.cancellationToken || server.nullCancellationToken; const logger = options?.logger || createHasErrorMessageLogger(); const useSingleInferredProject = options?.useSingleInferredProject !== undefined ? options.useSingleInferredProject : false; @@ -747,14 +854,14 @@ namespace ts.projectSystem { Debug.assert(session.logger.logs.length); for (let i = 0; i < files.length; i++) { if (existingTimeouts !== undefined) { - host.checkTimeoutQueueLength(existingTimeouts + 1); - host.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1); + session.checkTimeoutQueueLength(existingTimeouts + 1); + session.runQueuedTimeoutCallbacks(host.getNextTimeoutId() - 1); } else { - host.checkTimeoutQueueLengthAndRun(1); + session.checkTimeoutQueueLengthAndRun(1); } - if (!skip?.[i]?.semantic) host.runQueuedImmediateCallbacks(1); - if (!skip?.[i]?.suggestion) host.runQueuedImmediateCallbacks(1); + if (!skip?.[i]?.semantic) session.runQueuedImmediateCallbacks(1); + if (!skip?.[i]?.suggestion) session.runQueuedImmediateCallbacks(1); } } @@ -765,7 +872,7 @@ namespace ts.projectSystem { function verifyErrorsUsingGeterr({scenario, subScenario, allFiles, openFiles, getErrRequest }: VerifyGetErrScenario) { it("verifies the errors in open file", () => { const host = createServerHost([...allFiles(), libFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession(openFiles(), session); verifyGetErrRequest({ session, host, files: getErrRequest() }); @@ -776,7 +883,7 @@ namespace ts.projectSystem { function verifyErrorsUsingGeterrForProject({ scenario, subScenario, allFiles, openFiles, getErrForProjectRequest }: VerifyGetErrScenario) { it("verifies the errors in projects", () => { const host = createServerHost([...allFiles(), libFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession(openFiles(), session); for (const expected of getErrForProjectRequest()) { @@ -793,7 +900,7 @@ namespace ts.projectSystem { function verifyErrorsUsingSyncMethods({ scenario, subScenario, allFiles, openFiles, syncDiagnostics }: VerifyGetErrScenario) { it("verifies the errors using sync commands", () => { const host = createServerHost([...allFiles(), libFile]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession(openFiles(), session); for (const { file, project } of syncDiagnostics()) { const reqArgs = { file: filePath(file), projectFileName: project && filePath(project) }; diff --git a/src/testRunner/unittests/tsserver/inferredProjects.ts b/src/testRunner/unittests/tsserver/inferredProjects.ts index d4390e111add0..ce1747ee4fa5c 100644 --- a/src/testRunner/unittests/tsserver/inferredProjects.ts +++ b/src/testRunner/unittests/tsserver/inferredProjects.ts @@ -14,7 +14,7 @@ namespace ts.projectSystem { content: `export let x: number` }; const host = createServerHost([appFile, moduleFile, libFile]); - const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs() }); + const projectService = createProjectService(host, { logger: createLoggerWithInMemoryLogs(host) }); projectService.openClientFile(appFile.path); baselineTsserverLogs("inferredProjects", "create inferred project", projectService); }); diff --git a/src/testRunner/unittests/tsserver/moduleResolution.ts b/src/testRunner/unittests/tsserver/moduleResolution.ts index ec3535c5d73ab..c83ea4db1238c 100644 --- a/src/testRunner/unittests/tsserver/moduleResolution.ts +++ b/src/testRunner/unittests/tsserver/moduleResolution.ts @@ -32,7 +32,7 @@ namespace ts.projectSystem { ` }; const host = createServerHost([configFile, fileA, fileB, packageFile, { ...libFile, path: "/a/lib/lib.es2016.full.d.ts" }]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([fileA], session); return { host, session, packageFile, @@ -46,34 +46,34 @@ namespace ts.projectSystem { host.writeFile(packageFile.path, JSON.stringify({ name: "app", version: "1.0.0", type: "module", })); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Modify package json file to remove type module"); host.writeFile(packageFile.path, packageFile.content); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Delete package.json"); host.deleteFile(packageFile.path); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Modify package json file to add type module"); host.writeFile(packageFile.path, JSON.stringify({ name: "app", version: "1.0.0", type: "module", })); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Delete package.json"); host.deleteFile(packageFile.path); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); baselineTsserverLogs("moduleResolution", "package json file is edited", session); @@ -86,32 +86,32 @@ namespace ts.projectSystem { session.logger.info("Modify package json file to remove type module"); host.writeFile(packageFile.path, JSON.stringify({ name: "app", version: "1.0.0" })); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Modify package json file to add type module"); host.writeFile(packageFile.path, packageFile.content); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Delete package.json"); host.deleteFile(packageFile.path); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Modify package json file to without type module"); host.writeFile(packageFile.path, JSON.stringify({ name: "app", version: "1.0.0" })); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); session.logger.info("Delete package.json"); host.deleteFile(packageFile.path); - host.runQueuedTimeoutCallbacks(); // Failed lookup updates - host.runQueuedTimeoutCallbacks(); // Actual update + session.runQueuedTimeoutCallbacks(); // Failed lookup updates + session.runQueuedTimeoutCallbacks(); // Actual update verifyErr(); baselineTsserverLogs("moduleResolution", "package json file is edited when package json with type module exists", session); diff --git a/src/testRunner/unittests/tsserver/moduleSpecifierCache.ts b/src/testRunner/unittests/tsserver/moduleSpecifierCache.ts index a89d9d56fdd43..8a9ff13178578 100644 --- a/src/testRunner/unittests/tsserver/moduleSpecifierCache.ts +++ b/src/testRunner/unittests/tsserver/moduleSpecifierCache.ts @@ -59,11 +59,11 @@ namespace ts.projectSystem { }); it("invalidates module specifiers when changes happen in contained node_modules directories", () => { - const { host, session, moduleSpecifierCache, triggerCompletions } = setup(createLoggerWithInMemoryLogs()); + const { host, session, moduleSpecifierCache, triggerCompletions } = setup(host => createLoggerWithInMemoryLogs(host)); // Completion at an import statement will calculate and cache module specifiers triggerCompletions({ file: cTs.path, line: 1, offset: cTs.content.length + 1 }); host.writeFile("/node_modules/.staging/mobx-12345678/package.json", "{}"); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); assert.equal(moduleSpecifierCache.count(), 0); baselineTsserverLogs("moduleSpecifierCache", "invalidates module specifiers when changes happen in contained node_modules directories", session); }); @@ -123,9 +123,9 @@ namespace ts.projectSystem { }); }); - function setup(logger?: Logger) { + function setup(createLogger?: (host: TestServerHost) => Logger) { const host = createServerHost([aTs, bTs, cTs, bSymlink, ambientDeclaration, tsconfig, packageJson, mobxPackageJson, mobxDts]); - const session = createSession(host, logger && { logger }); + const session = createSession(host, createLogger && { logger: createLogger(host) }); openFilesForSession([aTs, bTs, cTs], session); const projectService = session.getProjectService(); const project = configuredProjectAt(projectService, 0); diff --git a/src/testRunner/unittests/tsserver/navTo.ts b/src/testRunner/unittests/tsserver/navTo.ts index eeebca75263fd..e484afaeab9c5 100644 --- a/src/testRunner/unittests/tsserver/navTo.ts +++ b/src/testRunner/unittests/tsserver/navTo.ts @@ -61,7 +61,7 @@ namespace ts.projectSystem { export const ghijkl = a.abcdef;` }; const host = createServerHost([configFile1, file1, configFile2, file2]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file1, file2], session); const request = makeSessionRequest(CommandNames.Navto, { searchValue: "abcdef", file: file1.path }); @@ -107,7 +107,7 @@ export const ghijkl = a.abcdef;` export const ghijkl = a.abcdef;` }; const host = createServerHost([configFile1, file1, configFile2, file2, solutionConfig]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file1], session); const request = makeSessionRequest(CommandNames.Navto, { searchValue: "abcdef" }); diff --git a/src/testRunner/unittests/tsserver/openFile.ts b/src/testRunner/unittests/tsserver/openFile.ts index 362c6ae16f005..de791a3e495a5 100644 --- a/src/testRunner/unittests/tsserver/openFile.ts +++ b/src/testRunner/unittests/tsserver/openFile.ts @@ -147,7 +147,7 @@ foo(); bar();` }; const host = createServerHost([file, libFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file], session); verifyGetErrRequest({ session, host, files: [file] }); diff --git a/src/testRunner/unittests/tsserver/partialSemanticServer.ts b/src/testRunner/unittests/tsserver/partialSemanticServer.ts index 621c4db5c5374..2a7a4157c6ff1 100644 --- a/src/testRunner/unittests/tsserver/partialSemanticServer.ts +++ b/src/testRunner/unittests/tsserver/partialSemanticServer.ts @@ -29,7 +29,7 @@ import { something } from "something"; const session = createSession(host, { serverMode: LanguageServiceMode.PartialSemantic, useSingleInferredProject: true, - logger: createLoggerWithInMemoryLogs(), + logger: createLoggerWithInMemoryLogs(host), }); return { host, session, file1, file2, file3, something, configFile }; } @@ -98,7 +98,7 @@ import { something } from "something"; const session = createSession(host, { serverMode: LanguageServiceMode.PartialSemantic, useSingleInferredProject: true, - logger: createLoggerWithInMemoryLogs() + logger: createLoggerWithInMemoryLogs(host) }); const service = session.getProjectService(); @@ -163,7 +163,7 @@ function fooB() { }` const session = createSession(host, { serverMode: LanguageServiceMode.PartialSemantic, useSingleInferredProject: true, - logger: createLoggerWithInMemoryLogs(), + logger: createLoggerWithInMemoryLogs(host), }); openFilesForSession([file1], session); baselineTsserverLogs("partialSemanticServer", "should not include referenced files from unopened files", session); diff --git a/src/testRunner/unittests/tsserver/projectErrors.ts b/src/testRunner/unittests/tsserver/projectErrors.ts index f721a27cf316f..2ddcf00cd4b26 100644 --- a/src/testRunner/unittests/tsserver/projectErrors.ts +++ b/src/testRunner/unittests/tsserver/projectErrors.ts @@ -232,7 +232,7 @@ namespace ts.projectSystem { content: "class c { }" }; const host = createServerHost([libFile, fileInRoot, fileInProjectRoot]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(), useInferredProjectPerProjectRoot: true }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host), useInferredProjectPerProjectRoot: true }); const untitledFile = "untitled:Untitled-1"; const refPathNotFound1 = "../../../../../../typings/@epic/Core.d.ts"; @@ -280,7 +280,7 @@ namespace ts.projectSystem { content: JSON.stringify({ compilerOptions: { module: "none", targer: "es5" }, exclude: ["node_modules"] }) }; const host = createServerHost([app, foo, configFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); session.executeCommandSeq({ command: server.CommandNames.Open, @@ -289,8 +289,8 @@ namespace ts.projectSystem { verifyGetErrRequest({ session, host, files: [app] }); host.renameFolder(`${projectDir}/foo`, `${projectDir}/foo2`); - host.runQueuedTimeoutCallbacks(); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyGetErrRequest({ session, host, files: [app] }); baselineTsserverLogs("projectErrors", `folder rename updates project structure and reports no errors`, session); }); @@ -301,7 +301,7 @@ namespace ts.projectSystem { content: "let x: number = false;" }; const host = createServerHost([file, libFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); session.executeCommandSeq({ command: server.CommandNames.Geterr, arguments: { @@ -310,7 +310,7 @@ namespace ts.projectSystem { } }); - host.checkTimeoutQueueLengthAndRun(1); + session.checkTimeoutQueueLengthAndRun(1); baselineTsserverLogs("projectErrors", "getting errors before opening file", session); }); @@ -329,7 +329,7 @@ namespace ts.projectSystem { }; const files = [libFile, app, serverUtilities, backendTest]; const host = createServerHost(files); - const session = createSession(host, { useInferredProjectPerProjectRoot: true, canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { useInferredProjectPerProjectRoot: true, canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([{ file: app, projectRootPath: tscWatch.projectRoot }], session); openFilesForSession([{ file: backendTest, projectRootPath: tscWatch.projectRoot }], session); verifyGetErrRequest({ session, host, files: [backendTest.path, app.path] }); @@ -367,7 +367,7 @@ declare module '@custom/plugin' { }; const files = [libFile, aFile, config, plugin, pluginProposed]; const host = createServerHost(files); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([aFile], session); checkErrors(); @@ -430,7 +430,7 @@ declare module '@custom/plugin' { }` }; const host = createServerHost([file, libFile, configFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file], session); baselineTsserverLogs("projectErrors", "configFileDiagnostic events are generated when the config file has errors", session); }); @@ -447,7 +447,7 @@ declare module '@custom/plugin' { }` }; const host = createServerHost([file, libFile, configFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file], session); baselineTsserverLogs("projectErrors", "configFileDiagnostic events are generated when the config file doesnt have errors", session); }); @@ -465,7 +465,7 @@ declare module '@custom/plugin' { }; const host = createServerHost([file, libFile, configFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file], session); configFile.content = `{ @@ -474,13 +474,13 @@ declare module '@custom/plugin' { } }`; host.writeFile(configFile.path, configFile.content); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); configFile.content = `{ "compilerOptions": {} }`; host.writeFile(configFile.path, configFile.content); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); baselineTsserverLogs("projectErrors", "configFileDiagnostic events are generated when the config file changes", session); }); @@ -508,7 +508,7 @@ declare module '@custom/plugin' { }` }; const host = createServerHost([file, libFile, configFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file2], session); openFilesForSession([file], session); // We generate only if project is created when opening file from the project @@ -531,7 +531,7 @@ declare module '@custom/plugin' { }` }; const host = createServerHost([file, libFile, configFile]); - const session = createSession(host, { canUseEvents: true, suppressDiagnosticEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, suppressDiagnosticEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file], session); baselineTsserverLogs("projectErrors", "configFileDiagnostic events are not generated when the config file has errors but suppressDiagnosticEvents is true", session); }); @@ -557,7 +557,7 @@ declare module '@custom/plugin' { }; const host = createServerHost([file, file2, file3, libFile, configFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file2], session); openFilesForSession([file], session); // We generate only if project is created when opening file from the project @@ -580,7 +580,7 @@ declare module '@custom/plugin' { }; const host = createServerHost([file, libFile, configFile]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file], session); baselineTsserverLogs("projectErrors", "configFileDiagnostic events contains the project reference errors", session); }); @@ -788,7 +788,7 @@ console.log(blabla);` }; const host = createServerHost([test, blabla, libFile, tsconfig]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([test], session); return { host, session, test, blabla, tsconfig }; } @@ -827,7 +827,7 @@ console.log(blabla);` }; const projectFiles = [main, libFile, config]; const host = createServerHost(projectFiles); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([{ file: main, projectRootPath: tscWatch.projectRoot }], session); verifyGetErrRequest({ session, host, files: [main] }); @@ -868,13 +868,13 @@ console.log(blabla);` function verifyWhileNpmInstall(timeouts: number) { filesAndFoldersToAdd.forEach(f => host.ensureFileOrFolder(f)); if (npmInstallComplete || timeoutDuringPartialInstallation) { - host.checkTimeoutQueueLengthAndRun(timeouts); // Invalidation of failed lookups + session.checkTimeoutQueueLengthAndRun(timeouts); // Invalidation of failed lookups if (timeouts) { - host.checkTimeoutQueueLengthAndRun(timeouts - 1); // Actual update + session.checkTimeoutQueueLengthAndRun(timeouts - 1); // Actual update } } else { - host.checkTimeoutQueueLength(timeouts ? 3 : 2); + session.checkTimeoutQueueLength(timeouts ? 3 : 2); } verifyGetErrRequest({ session, host, files: [main], existingTimeouts: !npmInstallComplete && !timeoutDuringPartialInstallation ? timeouts ? 3 : 2 : undefined }); } diff --git a/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts b/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts index 8ea94a596c8a8..671813de33fc6 100644 --- a/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts +++ b/src/testRunner/unittests/tsserver/projectReferenceCompileOnSave.ts @@ -35,157 +35,60 @@ fn2(); const localChange = "function fn3() { }"; const change = `export ${localChange}`; - const changeJs = `function fn3() { } -exports.fn3 = fn3;`; - const changeDts = "export declare function fn3(): void;"; - - function expectedAffectedFiles(config: File, fileNames: readonly File[]): protocol.CompileOnSaveAffectedFileListSingleProject { - return { - projectFileName: config.path, - fileNames: fileNames.map(f => f.path), - projectUsesOutFile: false - }; - } - - function expectedUsageEmitFiles(appendJsText?: string): readonly File[] { - const appendJs = appendJsText ? `${appendJsText} -` : ""; - return [{ - path: `${usageLocation}/usage.js`, - content: `"use strict"; -exports.__esModule = true;${appendJsText === changeJs ? "\nexports.fn3 = void 0;" : ""} -var fns_1 = require("../decls/fns"); -(0, fns_1.fn1)(); -(0, fns_1.fn2)(); -${appendJs}` - }]; - } - - function expectedEmitOutput(expectedFiles: readonly File[]): EmitOutput { - return { - outputFiles: expectedFiles.map(({ path, content }) => ({ - name: path, - text: content, - writeByteOrderMark: false - })), - emitSkipped: false, - diagnostics: emptyArray - }; - } - - function noEmitOutput(): EmitOutput { - return { - emitSkipped: true, - outputFiles: [], - diagnostics: emptyArray - }; - } - - function expectedDependencyEmitFiles(appendJsText?: string, appendDtsText?: string): readonly File[] { - const appendJs = appendJsText ? `${appendJsText} -` : ""; - const appendDts = appendDtsText ? `${appendDtsText} -` : ""; - return [ - { - path: `${dependecyLocation}/fns.js`, - content: `"use strict"; -exports.__esModule = true; -${appendJsText === changeJs ? "exports.fn3 = " : ""}exports.fn2 = exports.fn1 = void 0; -function fn1() { } -exports.fn1 = fn1; -function fn2() { } -exports.fn2 = fn2; -${appendJs}` - }, - { - path: `${tscWatch.projectRoot}/decls/fns.d.ts`, - content: `export declare function fn1(): void; -export declare function fn2(): void; -${appendDts}` - } - ]; - } describe("when dependency project is not open", () => { describe("Of usageTs", () => { it("with initial file open, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage", session); }); it("with initial file open, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage with project", session); }); it("with local change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -193,42 +96,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${localChange}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage and local change to dependency", session); }); it("with local change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -236,42 +126,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${localChange}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage with project and local change to dependency", session); }); it("with local change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -290,42 +167,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(localChange); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage and local change to usage", session); }); it("with local change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -344,42 +208,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(localChange); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage with project and local change to usage", session); }); it("with change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -387,42 +238,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${change}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage and change to depenedency", session); }); it("with change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -430,42 +268,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${change}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage with project and change to depenedency", session); }); it("with change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -484,42 +309,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(changeJs); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage and change to usage", session); }); it("with change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -538,107 +350,80 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(changeJs); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on usage with project and change to usage", session); }); }); describe("Of dependencyTs in usage project", () => { it("with initial file open, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency", session); }); it("with initial file open, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency with project", session); }); it("with local change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -646,37 +431,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${localChange}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency and local change to dependency", session); }); it("with local change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -684,37 +461,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${localChange}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency with project and local change to dependency", session); }); it("with local change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -733,37 +502,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency and local change to usage", session); }); it("with local change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -782,37 +543,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency with project and local change to usage", session); }); it("with change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -820,37 +573,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${change}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency and change to dependency", session); }); it("with change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -858,37 +603,29 @@ ${appendDts}` arguments: { file: dependencyTs.path } }); host.writeFile(dependencyTs.path, `${dependencyTs.content}${change}`); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency with project and change to dependency", session); }); it("with change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -907,37 +644,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency and change to usage", session); }); it("with change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs], session); session.executeCommandSeq({ @@ -956,31 +685,25 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "when dependency project is not open and save on dependency with project and change to usage", session); }); }); }); @@ -988,82 +711,56 @@ ${appendDts}` describe("when the depedency file is open", () => { describe("Of usageTs", () => { it("with initial file open, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage", session); }); it("with initial file open, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage with project", session); }); it("with local change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1082,42 +779,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage and local change to dependency", session); }); it("with local change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1136,42 +820,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage and local change to dependency with file", session); }); it("with local change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1190,42 +861,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(localChange); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage and local change to usage", session); }); it("with local change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1244,42 +902,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(localChange); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage and local change to usage with project", session); }); it("with change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1298,42 +943,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage and change to dependency", session); }); it("with change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1352,42 +984,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage with project and change to dependency", session); }); it("with change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1406,42 +1025,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(changeJs); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage and change to usage", session); }); it("with change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1460,76 +1066,55 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedUsageEmitFiles(changeJs); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } - + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: usageTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on usage with project and change to usage", session); }); }); describe("Of dependencyTs in usage project", () => { it("with initial file open, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with usage project", session); }); it("with local change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1548,37 +1133,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with usage project and local change to dependency", session); }); it("with local change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1597,37 +1174,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with usage project and local change to usage", session); }); it("with change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1646,37 +1215,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with usage project and change to dependency", session); }); it("with change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1695,113 +1256,80 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response; - assert.isFalse(actualEmit, "Emit files"); - assert.equal(host.writtenFiles.size, 0); + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: usageConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, noEmitOutput(), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with usage project and change to usage", session); }); }); describe("Of dependencyTs", () => { it("with initial file open, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]), - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency", session); }); it("with initial file open, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with project", session); }); it("with local change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1820,43 +1348,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray), - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(localChange); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency and local change to dependency", session); }); it("with local change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1875,42 +1389,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(localChange); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with project and local change to dependency", session); }); it("with local change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1929,43 +1430,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray), - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency and local change to usage", session); }); it("with local change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -1984,42 +1471,29 @@ ${appendDts}` insertString: localChange } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with project and local change to usage", session); }); it("with change to dependency, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -2038,43 +1512,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, [usageTs]), - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(changeJs, changeDts); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency and change to dependency", session); }); it("with change to dependency, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -2093,42 +1553,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(changeJs, changeDts); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with project and change to dependency", session); }); it("with change to usage, without specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -2147,43 +1594,29 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(usageConfig, emptyArray), - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency and change to usage", session); }); it("with change to usage, with specifying project file", () => { - const host = TestFSWithWatch.changeToHostTrackingWrittenFiles( - createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]) - ); - const session = createSession(host); + const host = createServerHost([dependencyTs, dependencyConfig, usageTs, usageConfig, libFile]); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([usageTs, dependencyTs], session); session.executeCommandSeq({ @@ -2202,36 +1635,25 @@ ${appendDts}` insertString: change } }); - host.writtenFiles.clear(); // Verify CompileOnSaveAffectedFileList - const actualAffectedFiles = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveAffectedFileList, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as protocol.CompileOnSaveAffectedFileListSingleProject[]; - assert.deepEqual(actualAffectedFiles, [ - expectedAffectedFiles(dependencyConfig, [dependencyTs]) - ], "Affected files"); + }); // Verify CompileOnSaveEmit - const actualEmit = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.CompileOnSaveEmitFile, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response; - assert.isTrue(actualEmit, "Emit files"); - const expectedFiles = expectedDependencyEmitFiles(); - assert.equal(host.writtenFiles.size, expectedFiles.length); - for (const file of expectedFiles) { - assert.equal(host.readFile(file.path), file.content, `Expected to write ${file.path}`); - assert.isTrue(host.writtenFiles.has(file.path as Path), `${file.path} is newly written`); - } + }); // Verify EmitOutput - const actualEmitOutput = session.executeCommandSeq({ + session.executeCommandSeq({ command: protocol.CommandTypes.EmitOutput, arguments: { file: dependencyTs.path, projectFileName: dependencyConfig.path } - }).response as EmitOutput; - assert.deepEqual(actualEmitOutput, expectedEmitOutput(expectedFiles), "Emit output"); + }); + baselineTsserverLogs("projectReferenceCompileOnSave", "save on dependency with project and change to usage", session); }); }); }); @@ -2297,10 +1719,8 @@ ${appendDts}` // ts build should succeed tscWatch.ensureErrorFreeBuild(host, [siblingConfig.path]); - const sourceJs = changeExtension(siblingSource.path, ".js"); - const expectedSiblingJs = host.readFile(sourceJs); - const session = createSession(host); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([siblingSource], session); session.executeCommandSeq({ @@ -2310,7 +1730,7 @@ ${appendDts}` projectFileName: siblingConfig.path } }); - assert.equal(host.readFile(sourceJs), expectedSiblingJs); + baselineTsserverLogs("projectReferenceCompileOnSave", "compile on save emits same output as project build with external project", session); }); }); } \ No newline at end of file diff --git a/src/testRunner/unittests/tsserver/projectReferences.ts b/src/testRunner/unittests/tsserver/projectReferences.ts index d5f2cf6339c74..dfed05abe3c22 100644 --- a/src/testRunner/unittests/tsserver/projectReferences.ts +++ b/src/testRunner/unittests/tsserver/projectReferences.ts @@ -26,7 +26,7 @@ namespace ts.projectSystem { const host = createHostWithSolutionBuild(files, [containerConfig.path]); // Open external project for the folder - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); const service = session.getProjectService(); service.openExternalProjects([{ projectFileName: TestFSWithWatch.getTsBuildProjectFilePath(project, project), @@ -57,7 +57,7 @@ namespace ts.projectSystem { it("can successfully find references with --out options", () => { const host = createHostWithSolutionBuild(files, [containerConfig.path]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([containerCompositeExec[1]], session); const myConstStart = protocolLocationFromSubstring(containerCompositeExec[1].content, "myConst"); session.executeCommandSeq({ @@ -74,7 +74,7 @@ namespace ts.projectSystem { content: "let x = 10" }; const host = createHostWithSolutionBuild(files.concat([tempFile]), [containerConfig.path]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([containerCompositeExec[1]], session); const service = session.getProjectService(); @@ -164,7 +164,7 @@ function foo() { [commonConfig, keyboardTs, keyboardTestTs, srcConfig, terminalTs, libFile], [srcConfig.path] ); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([keyboardTs, terminalTs], session); const searchStr = "evaluateKeyboardEvent"; @@ -341,7 +341,7 @@ function foo() { createServerHost(files); // Create symlink in node module - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([aTest], session); verifyGetErrRequest({ session, host, files: [aTest] }); session.executeCommandSeq({ @@ -492,7 +492,7 @@ testCompositeFunction('why hello there', 42);` symLink: `${tscWatch.projectRoot}/packages/emit-composite` }; const host = createServerHost([libFile, compositeConfig, compositePackageJson, compositeIndex, compositeTestModule, consumerConfig, consumerIndex, symlink], { useCaseSensitiveFileNames: true }); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([consumerIndex], session); verifyGetErrRequest({ host, session, files: [consumerIndex] }); baselineTsserverLogs("projectReferences", `when the referenced projects have allowJs and emitDeclarationOnly`, session); @@ -562,7 +562,7 @@ testCompositeFunction('why hello there', 42);` const files = [libFile, solution, compilerConfig, typesFile, programFile, servicesConfig, servicesFile, libFile]; const host = createServerHost(files); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([programFile], session); // Find all references for getSourceFile @@ -682,7 +682,7 @@ testCompositeFunction('why hello there', 42);` const files = [libFile, solutionConfig, aConfig, aFile, bConfig, bFile, cConfig, cFile, dConfig, dFile, libFile]; const host = createServerHost(files); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([bFile], session); // The first search will trigger project loads @@ -756,7 +756,7 @@ ${usage}` content: definition }; const host = createServerHost([libFile, solution, libFile, apiConfig, apiFile, appConfig, appFile, sharedConfig, sharedFile]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([apiFile], session); // Find all references @@ -874,7 +874,7 @@ export const foo = local;`, const files = [libFile, solution, compilerConfig, typesFile, programFile, servicesConfig, servicesFile, libFile]; const host = createServerHost(files); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([programFile], session); // Find all references @@ -969,7 +969,7 @@ export function bar() {}` mainDts, mainDtsMap, helperDts, helperDtsMap, tsconfigIndirect3, fileResolvingToMainDts, ...additionalFiles]); - const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { canUseEvents: true, logger: createLoggerWithInMemoryLogs(host) }); const service = session.getProjectService(); service.openClientFile(main.path); return { session, service, host }; @@ -979,10 +979,10 @@ export function bar() {}` const { session, service, host } = setup(input); const info = service.getScriptInfoForPath(main.path as Path)!; - session.logger.logs.push(""); - session.logger.logs.push(`getDefaultProject for ${main.path}: ${info.getDefaultProject().projectName}`); - session.logger.logs.push(`findDefaultConfiguredProject for ${main.path}: ${service.findDefaultConfiguredProject(info)!.projectName}`); - session.logger.logs.push(""); + session.logger.startGroup(); + session.logger.info(`getDefaultProject for ${main.path}: ${info.getDefaultProject().projectName}`); + session.logger.info(`findDefaultConfiguredProject for ${main.path}: ${service.findDefaultConfiguredProject(info)!.projectName}`); + session.logger.endGroup(); // Verify errors verifyGetErrRequest({ session, host, files: [main] }); @@ -1046,10 +1046,10 @@ export function bar() {}` const { session, service } = setup(input); const info = service.getScriptInfoForPath(main.path as Path)!; - session.logger.logs.push(""); - session.logger.logs.push(`getDefaultProject for ${main.path}: ${info.getDefaultProject().projectName}`); - session.logger.logs.push(`findDefaultConfiguredProject for ${main.path}: ${service.findDefaultConfiguredProject(info)?.projectName}`); - session.logger.logs.push(""); + session.logger.startGroup(); + session.logger.info(`getDefaultProject for ${main.path}: ${info.getDefaultProject().projectName}`); + session.logger.info(`findDefaultConfiguredProject for ${main.path}: ${service.findDefaultConfiguredProject(info)?.projectName}`); + session.logger.endGroup(); // Verify collection of script infos service.openClientFile(dummyFilePath); @@ -1246,7 +1246,7 @@ bar;` content: `class class2 {}` }; const host = createServerHost([config1, class1, class1Dts, config2, class2, libFile]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([class2], session); return { host, session, class1 }; } @@ -1257,16 +1257,16 @@ bar;` // Add new class to referenced project const class3 = `${tscWatch.projectRoot}/projects/project1/class3.ts`; host.writeFile(class3, `class class3 {}`); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); // Add excluded file to referenced project host.ensureFileOrFolder({ path: `${tscWatch.projectRoot}/projects/project1/temp/file.d.ts`, content: `declare class file {}` }); - host.checkTimeoutQueueLengthAndRun(0); + session.checkTimeoutQueueLengthAndRun(0); // Add output from new class to referenced project const class3Dts = `${tscWatch.projectRoot}/projects/project1/class3.d.ts`; host.writeFile(class3Dts, `declare class class3 {}`); - host.checkTimeoutQueueLengthAndRun(0); + session.checkTimeoutQueueLengthAndRun(0); baselineTsserverLogs("projectReferences", `new file is added to the referenced project when referenced project is not open`, session); }); @@ -1277,14 +1277,14 @@ bar;` // Add new class to referenced project const class3 = `${tscWatch.projectRoot}/projects/project1/class3.ts`; host.writeFile(class3, `class class3 {}`); - host.checkTimeoutQueueLengthAndRun(3); + session.checkTimeoutQueueLengthAndRun(3); // Add excluded file to referenced project host.ensureFileOrFolder({ path: `${tscWatch.projectRoot}/projects/project1/temp/file.d.ts`, content: `declare class file {}` }); - host.checkTimeoutQueueLengthAndRun(0); + session.checkTimeoutQueueLengthAndRun(0); // Add output from new class to referenced project const class3Dts = `${tscWatch.projectRoot}/projects/project1/class3.d.ts`; host.writeFile(class3Dts, `declare class class3 {}`); - host.checkTimeoutQueueLengthAndRun(0); + session.checkTimeoutQueueLengthAndRun(0); baselineTsserverLogs("projectReferences", `new file is added to the referenced project when referenced project is open`, session); }); @@ -1294,20 +1294,20 @@ bar;` // Add new class to referenced project const class3 = `${tscWatch.projectRoot}/projects/project1/class3.ts`; host.writeFile(class3, `class class3 {}`); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); // Add output of new class to referenced project const class3Dts = `${tscWatch.projectRoot}/projects/project1/class3.d.ts`; host.writeFile(class3Dts, `declare class class3 {}`); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); // Add excluded file to referenced project host.ensureFileOrFolder({ path: `${tscWatch.projectRoot}/projects/project1/temp/file.d.ts`, content: `declare class file {}` }); - host.checkTimeoutQueueLengthAndRun(0); + session.checkTimeoutQueueLengthAndRun(0); // Delete output from new class to referenced project host.deleteFile(class3Dts); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); // Write back output of new class to referenced project host.writeFile(class3Dts, `declare class class3 {}`); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); baselineTsserverLogs("projectReferences", `new file is added to the referenced project when referenced project is not open with disableSourceOfProjectReferenceRedirect`, session); }); @@ -1318,20 +1318,20 @@ bar;` // Add new class to referenced project const class3 = `${tscWatch.projectRoot}/projects/project1/class3.ts`; host.writeFile(class3, `class class3 {}`); - host.checkTimeoutQueueLengthAndRun(3); + session.checkTimeoutQueueLengthAndRun(3); // Add output of new class to referenced project const class3Dts = `${tscWatch.projectRoot}/projects/project1/class3.d.ts`; host.writeFile(class3Dts, `declare class class3 {}`); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); // Add excluded file to referenced project host.ensureFileOrFolder({ path: `${tscWatch.projectRoot}/projects/project1/temp/file.d.ts`, content: `declare class file {}` }); - host.checkTimeoutQueueLengthAndRun(0); + session.checkTimeoutQueueLengthAndRun(0); // Delete output from new class to referenced project host.deleteFile(class3Dts); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); // Write back output of new class to referenced project host.writeFile(class3Dts, `declare class class3 {}`); - host.checkTimeoutQueueLengthAndRun(2); + session.checkTimeoutQueueLengthAndRun(2); baselineTsserverLogs("projectReferences", `new file is added to the referenced project when referenced project is open with disableSourceOfProjectReferenceRedirect`, session); }); }); @@ -1401,7 +1401,7 @@ bar;` tscWatch.solutionBuildWithBaseline(host, [solnConfig.path]); host.clearOutput(); } - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([appIndex], session); session.executeCommandSeq({ command: protocol.CommandTypes.GetCodeFixes, @@ -1464,7 +1464,7 @@ bar;` refToCoreRef3File, refToCoreRef3Config, indirectNoCoreRefFile, indirectNoCoreRefConfig, noCoreRef2File, noCoreRef2Config ], { useCaseSensitiveFileNames: true }); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([mainFile, coreFile], session); // Find all refs in coreFile @@ -1549,7 +1549,7 @@ const b: B = new B();` }; const host = createServerHost([configA, indexA, configB, indexB, helperB, dtsB, ...(dtsMapPresent ? [dtsMapB] : [])]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([indexA, ...(projectAlreadyLoaded ? [helperB] : [])], session); session.executeCommandSeq({ diff --git a/src/testRunner/unittests/tsserver/projectReferencesSourcemap.ts b/src/testRunner/unittests/tsserver/projectReferencesSourcemap.ts index b0f2c2a15b85a..3773d1fa8c314 100644 --- a/src/testRunner/unittests/tsserver/projectReferencesSourcemap.ts +++ b/src/testRunner/unittests/tsserver/projectReferencesSourcemap.ts @@ -216,14 +216,14 @@ fn5(); compilerOptions: { composite: true, declarationMap: true } })); onHostCreate?.(host); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); return { host, session }; } function createSessionWithProjectReferences(onHostCreate?: OnHostCreate) { const host = createHostWithSolutionBuild(files, [mainConfig.path]); onHostCreate?.(host); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); return { host, session }; } @@ -239,7 +239,7 @@ fn5(); references: [{ path: "../dependency" }] })); onHostCreate?.(host); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); return { host, session }; } @@ -311,11 +311,11 @@ fn5(); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToMainTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -355,7 +355,7 @@ fn5(); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -395,7 +395,7 @@ fn5(); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -554,11 +554,11 @@ fn5(); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToMainTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -598,7 +598,7 @@ fn5(); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -638,7 +638,7 @@ fn5(); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -778,7 +778,7 @@ fn5(); // Make change, without rebuild of solution host.writeFile(dependencyTs.path, `function fooBar() { } ${dependencyTs.content}`); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -815,7 +815,7 @@ ${dependencyTs.content}`); it("when projects are not built", () => { const host = createServerHost(files); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([mainTs, randomFile], session); verifyAllFnAction( session, @@ -855,11 +855,11 @@ ${dependencyTs.content}`); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToMainTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -899,7 +899,7 @@ ${dependencyTs.content}`); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -939,7 +939,7 @@ ${dependencyTs.content}`); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1107,11 +1107,11 @@ ${dependencyTs.content}`); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToDependencyTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1151,7 +1151,7 @@ ${dependencyTs.content}`); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1191,7 +1191,7 @@ ${dependencyTs.content}`); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1350,11 +1350,11 @@ ${dependencyTs.content}`); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToDependencyTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1394,7 +1394,7 @@ ${dependencyTs.content}`); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1434,7 +1434,7 @@ ${dependencyTs.content}`); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1568,7 +1568,7 @@ ${dependencyTs.content}`); }); it(`when defining project source changes, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change // Make change, without rebuild of solution @@ -1578,7 +1578,7 @@ ${dependencyTs.content}`); file: dependencyTs.path, line: 1, offset: 1, endLine: 1, endOffset: 1, insertString: `function fooBar() { } `} }); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1619,7 +1619,7 @@ ${dependencyTs.content}`); it("when projects are not built", () => { const host = createServerHost(files); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([dependencyTs, randomFile], session); verifyAllFnAction( session, @@ -1659,11 +1659,11 @@ ${dependencyTs.content}`); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToDependencyTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1703,7 +1703,7 @@ ${dependencyTs.content}`); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1743,7 +1743,7 @@ ${dependencyTs.content}`); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1921,12 +1921,12 @@ ${dependencyTs.content}`); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToMainTs(session); makeChangeToDependencyTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -1983,7 +1983,7 @@ ${dependencyTs.content}`); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2039,7 +2039,7 @@ ${dependencyTs.content}`); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2274,12 +2274,12 @@ ${dependencyTs.content}`); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToMainTs(session); makeChangeToDependencyTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2336,7 +2336,7 @@ ${dependencyTs.content}`); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2392,7 +2392,7 @@ ${dependencyTs.content}`); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2592,7 +2592,7 @@ ${dependencyTs.content}`); }); it(`when defining project source changes, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change // Make change, without rebuild of solution @@ -2602,7 +2602,7 @@ ${dependencyTs.content}`); file: dependencyTs.path, line: 1, offset: 1, endLine: 1, endOffset: 1, insertString: `function fooBar() { } `} }); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2659,7 +2659,7 @@ ${dependencyTs.content}`); it("when projects are not built", () => { const host = createServerHost(files); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([mainTs, dependencyTs, randomFile], session); verifyAllFnAction( session, @@ -2716,12 +2716,12 @@ ${dependencyTs.content}`); // Edit it(`when usage file changes, document position mapper doesnt change, when timeout occurs before request`, () => { // Create DocumentPositionMapper - const { host, session, dependencyMap, documentPositionMapper } = setupWithAction(); + const { session, dependencyMap, documentPositionMapper } = setupWithAction(); // change makeChangeToMainTs(session); makeChangeToDependencyTs(session); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2778,7 +2778,7 @@ ${dependencyTs.content}`); // change changeDtsFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action @@ -2834,7 +2834,7 @@ ${dependencyTs.content}`); // change changeDtsMapFile(host); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); verifyDocumentPositionMapperEqual(session, dependencyMap, documentPositionMapper); // action diff --git a/src/testRunner/unittests/tsserver/projects.ts b/src/testRunner/unittests/tsserver/projects.ts index 7a166dc1abbb2..fb4f19ec0f034 100644 --- a/src/testRunner/unittests/tsserver/projects.ts +++ b/src/testRunner/unittests/tsserver/projects.ts @@ -7,7 +7,7 @@ namespace ts.projectSystem { let x = y` }; const host = createServerHost([file1, libFile]); - const session = createSession(host, { logger: createLoggerWithInMemoryLogs() }); + const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) }); openFilesForSession([file1], session); const getErrRequest = makeSessionRequest( @@ -19,7 +19,7 @@ namespace ts.projectSystem { session.executeCommand(getErrRequest); host.writeFile(commonFile2.path, commonFile2.content); - host.runQueuedTimeoutCallbacks(); + session.runQueuedTimeoutCallbacks(); session.executeCommand(getErrRequest); baselineTsserverLogs("projects", "handles the missing files added with tripleslash ref", session); }); @@ -861,7 +861,7 @@ namespace ts.projectSystem { content: `