From 7c918fb76682e79e8fd460cf1c2da9f2f22c91a3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 8 Sep 2022 12:31:14 -0700 Subject: [PATCH] Baseline host state when baselining tsserver tests (#50678) * Some more formatting to have baselines similar to what we have in tsserver.log * Some refactor * Baselines * Baseline host details on each request * More formatting per tsserver log * More baselining of host state * Update Baselines and/or Applied Lint Fixes * Use utc time in logger for baselines Co-authored-by: TypeScript Bot --- .../tsserver/cachingFileSystemInformation.ts | 22 +- .../unittests/tsserver/configFileSearch.ts | 20 +- .../unittests/tsserver/configuredProjects.ts | 41 +- .../events/projectLanguageServiceState.ts | 6 +- .../events/projectUpdatedInBackground.ts | 8 +- .../forceConsistentCasingInFileNames.ts | 4 +- src/testRunner/unittests/tsserver/helpers.ts | 153 +- .../unittests/tsserver/inferredProjects.ts | 2 +- .../unittests/tsserver/moduleResolution.ts | 42 +- .../tsserver/moduleSpecifierCache.ts | 8 +- src/testRunner/unittests/tsserver/navTo.ts | 4 +- src/testRunner/unittests/tsserver/openFile.ts | 2 +- .../tsserver/partialSemanticServer.ts | 6 +- .../unittests/tsserver/projectErrors.ts | 44 +- .../tsserver/projectReferenceCompileOnSave.ts | 1394 +++----- .../unittests/tsserver/projectReferences.ts | 78 +- .../tsserver/projectReferencesSourcemap.ts | 94 +- src/testRunner/unittests/tsserver/projects.ts | 26 +- .../tsserver/projectsWithReferences.ts | 48 +- .../unittests/tsserver/resolutionCache.ts | 64 +- src/testRunner/unittests/tsserver/symLinks.ts | 24 +- .../unittests/tsserver/syntacticServer.ts | 2 +- .../unittests/tsserver/typingsInstaller.ts | 12 +- .../unittests/tsserver/watchEnvironment.ts | 221 +- .../loads-missing-files-from-disk.js | 142 +- ...-when-timeout-occurs-after-installation.js | 2644 ++++++++++---- ...n-timeout-occurs-inbetween-installation.js | 3000 ++++++++++++---- ...-file-with-case-insensitive-file-system.js | 237 +- ...ig-file-with-case-sensitive-file-system.js | 237 +- .../when-calling-goto-definition-of-module.js | 279 +- .../works-using-legacy-resolution-logic.js | 172 +- ...-searching-for-inferred-project-again-2.js | 192 +- ...en-searching-for-inferred-project-again.js | 198 +- .../tsconfig-for-the-file-does-not-exist.js | 349 +- .../tsconfig-for-the-file-exists.js | 346 +- .../when-projectRootPath-is-not-present.js | 80 +- ...esent-but-file-is-not-from-project-root.js | 80 +- ...oject-as-part-of-configured-file-update.js | 679 ++-- ...onfig-file-in-a-folder-with-loose-files.js | 418 ++- ...-a-configured-project-without-file-list.js | 167 +- ...on-reflected-when-specifying-files-list.js | 245 +- ...e-configured-project-with-the-file-list.js | 85 +- ...te-configured-project-without-file-list.js | 87 +- ...er-old-one-without-file-being-in-config.js | 811 ++++- ...invoked,-ask-errors-on-it-after-old-one.js | 541 ++- ...re-old-one-without-file-being-in-config.js | 811 ++++- ...nvoked,-ask-errors-on-it-before-old-one.js | 541 ++- ...er-old-one-without-file-being-in-config.js | 811 ++++- ...invoked,-ask-errors-on-it-after-old-one.js | 713 +++- ...re-old-one-without-file-being-in-config.js | 811 ++++- ...nvoked,-ask-errors-on-it-before-old-one.js | 783 ++++- ...uses-parent-most-node_modules-directory.js | 99 +- ...the-extended-configs-of-closed-projects.js | 428 +-- ...e-extended-configs-of-multiple-projects.js | 697 ++-- ...re-open-detects-correct-default-project.js | 639 +++- ...nging-module-name-with-different-casing.js | 538 ++- ...hen-renaming-file-with-different-casing.js | 849 ++++- .../create-inferred-project.js | 76 +- ...en-package-json-with-type-module-exists.js | 2378 +++++++++++-- .../package-json-file-is-edited.js | 2398 +++++++++++-- ...n-in-contained-node_modules-directories.js | 1141 +++++- ...ate-symbols-when-searching-all-projects.js | 255 +- .../navTo/should-de-duplicate-symbols.js | 308 +- ...-directives,-they-are-handled-correcrly.js | 714 +++- .../files-are-added-to-inferred-project.js | 268 +- ...ternal-module-name-resolution-is-reused.js | 246 +- ...-include-auto-type-reference-directives.js | 92 +- ...de-referenced-files-from-unopened-files.js | 89 +- ...t-go-to-definition-on-module-specifiers.js | 149 +- ...-diagnostics-are-returned-with-no-error.js | 195 +- .../throws-unsupported-commands.js | 113 +- ...-generated-when-the-config-file-changes.js | 327 +- ...when-the-config-file-doesnt-have-errors.js | 116 +- ...nerated-when-the-config-file-has-errors.js | 119 +- ...-file-opened-and-config-file-has-errors.js | 322 +- ...le-opened-and-doesnt-contain-any-errors.js | 324 +- ...rs-but-suppressDiagnosticEvents-is-true.js | 117 +- ...s-contains-the-project-reference-errors.js | 117 +- ...-same-ambient-module-and-is-also-module.js | 541 ++- ...project-structure-and-reports-no-errors.js | 619 +++- .../getting-errors-before-opening-file.js | 71 +- ...-when-timeout-occurs-after-installation.js | 1585 +++++++-- ...n-timeout-occurs-inbetween-installation.js | 1669 +++++++-- ...pened-right-after-closing-the-root-file.js | 1648 ++++++++- ...hen-json-is-root-file-found-by-tsconfig.js | 320 +- ...json-is-not-root-file-found-by-tsconfig.js | 320 +- ...esnt-exist-on-disk-yet-with-projectRoot.js | 256 +- ...t-exist-on-disk-yet-without-projectRoot.js | 233 +- ...-global-error-gerErr-with-sync-commands.js | 268 +- ...or-returns-includes-global-error-getErr.js | 270 +- ...-includes-global-error-geterrForProject.js | 268 +- ...large-file-size-is-determined-correctly.js | 81 +- ...-as-project-build-with-external-project.js | 412 +++ ...-on-dependency-and-change-to-dependency.js | 721 ++++ .../save-on-dependency-and-change-to-usage.js | 713 ++++ ...pendency-and-local-change-to-dependency.js | 717 ++++ ...on-dependency-and-local-change-to-usage.js | 713 ++++ ...y-with-project-and-change-to-dependency.js | 686 ++++ ...ndency-with-project-and-change-to-usage.js | 680 ++++ ...-project-and-local-change-to-dependency.js | 684 ++++ ...-with-project-and-local-change-to-usage.js | 680 ++++ .../save-on-dependency-with-project.js | 501 +++ ...-usage-project-and-change-to-dependency.js | 645 ++++ ...-with-usage-project-and-change-to-usage.js | 643 ++++ ...-project-and-local-change-to-dependency.js | 643 ++++ ...usage-project-and-local-change-to-usage.js | 643 ++++ .../save-on-dependency-with-usage-project.js | 463 +++ .../save-on-dependency.js | 533 +++ .../save-on-usage-and-change-to-dependency.js | 690 ++++ .../save-on-usage-and-change-to-usage.js | 690 ++++ ...nd-local-change-to-dependency-with-file.js | 662 ++++ ...on-usage-and-local-change-to-dependency.js | 690 ++++ ...-and-local-change-to-usage-with-project.js | 663 ++++ ...save-on-usage-and-local-change-to-usage.js | 688 ++++ ...e-with-project-and-change-to-dependency.js | 662 ++++ ...-usage-with-project-and-change-to-usage.js | 665 ++++ .../save-on-usage-with-project.js | 480 +++ .../save-on-usage.js | 505 +++ ...-on-dependency-and-change-to-dependency.js | 475 +++ ...-save-on-dependency-and-change-to-usage.js | 534 +++ ...pendency-and-local-change-to-dependency.js | 473 +++ ...on-dependency-and-local-change-to-usage.js | 534 +++ ...y-with-project-and-change-to-dependency.js | 462 +++ ...ndency-with-project-and-change-to-usage.js | 521 +++ ...-project-and-local-change-to-dependency.js | 460 +++ ...-with-project-and-local-change-to-usage.js | 521 +++ ...pen-and-save-on-dependency-with-project.js | 360 ++ ...ject-is-not-open-and-save-on-dependency.js | 373 ++ ...save-on-usage-and-change-to-depenedency.js | 492 +++ ...n-and-save-on-usage-and-change-to-usage.js | 556 +++ ...on-usage-and-local-change-to-dependency.js | 492 +++ ...save-on-usage-and-local-change-to-usage.js | 554 +++ ...-with-project-and-change-to-depenedency.js | 479 +++ ...-usage-with-project-and-change-to-usage.js | 543 +++ ...-project-and-local-change-to-dependency.js | 479 +++ ...-with-project-and-local-change-to-usage.js | 541 +++ ...not-open-and-save-on-usage-with-project.js | 377 ++ ...y-project-is-not-open-and-save-on-usage.js | 390 +++ ...t-is-not-open-gerErr-with-sync-commands.js | 1007 +++++- ...n-dependency-project-is-not-open-getErr.js | 400 ++- ...cy-project-is-not-open-geterrForProject.js | 954 ++++- ...-file-is-open-gerErr-with-sync-commands.js | 1367 +++++++- ...-when-the-depedency-file-is-open-getErr.js | 696 +++- ...depedency-file-is-open-geterrForProject.js | 925 ++++- ...t-is-not-open-gerErr-with-sync-commands.js | 948 ++++- ...n-dependency-project-is-not-open-getErr.js | 373 +- ...cy-project-is-not-open-geterrForProject.js | 887 ++++- ...-file-is-open-gerErr-with-sync-commands.js | 1292 ++++++- ...-when-the-depedency-file-is-open-getErr.js | 653 +++- ...depedency-file-is-open-geterrForProject.js | 866 ++++- .../ancestor-and-project-ref-management.js | 1282 +++++-- ...disableSourceOfProjectReferenceRedirect.js | 485 ++- ...port-with-referenced-project-when-built.js | 485 ++- .../auto-import-with-referenced-project.js | 344 +- ...ssfully-find-references-with-out-option.js | 666 +++- ...indirect-project-but-not-in-another-one.js | 510 ++- ...dProjectLoad-is-set-in-indirect-project.js | 508 ++- ...-if-disableReferencedProjectLoad-is-set.js | 512 ++- ...oes-not-error-on-container-only-project.js | 1804 +++++++++- ...-are-disabled-and-a-decl-map-is-missing.js | 444 ++- ...-are-disabled-and-a-decl-map-is-present.js | 504 ++- ...s-are-enabled-and-a-decl-map-is-missing.js | 489 ++- ...s-are-enabled-and-a-decl-map-is-present.js | 492 ++- ...-are-disabled-and-a-decl-map-is-missing.js | 444 ++- ...-are-disabled-and-a-decl-map-is-present.js | 504 ++- ...s-are-enabled-and-a-decl-map-is-missing.js | 489 ++- ...s-are-enabled-and-a-decl-map-is-present.js | 492 ++- ...-are-disabled-and-a-decl-map-is-missing.js | 299 +- ...-are-disabled-and-a-decl-map-is-present.js | 314 +- ...s-are-enabled-and-a-decl-map-is-missing.js | 303 +- ...s-are-enabled-and-a-decl-map-is-present.js | 306 +- ...-are-disabled-and-a-decl-map-is-missing.js | 299 +- ...-are-disabled-and-a-decl-map-is-present.js | 399 ++- ...s-are-enabled-and-a-decl-map-is-missing.js | 388 +- ...s-are-enabled-and-a-decl-map-is-present.js | 391 ++- .../sibling-projects.js | 450 ++- ...ding-references-in-overlapping-projects.js | 899 ++++- ...solution-is-built-with-preserveSymlinks.js | 1075 +++++- ...-and-has-index.ts-and-solution-is-built.js | 1075 +++++- ...tion-is-not-built-with-preserveSymlinks.js | 933 ++++- ...-has-index.ts-and-solution-is-not-built.js | 933 ++++- ...solution-is-built-with-preserveSymlinks.js | 1075 +++++- ...th-scoped-package-and-solution-is-built.js | 1075 +++++- ...tion-is-not-built-with-preserveSymlinks.js | 933 ++++- ...coped-package-and-solution-is-not-built.js | 933 ++++- ...solution-is-built-with-preserveSymlinks.js | 1075 +++++- ...le-from-subFolder-and-solution-is-built.js | 1075 +++++- ...tion-is-not-built-with-preserveSymlinks.js | 933 ++++- ...rom-subFolder-and-solution-is-not-built.js | 933 ++++- ...solution-is-built-with-preserveSymlinks.js | 1075 +++++- ...th-scoped-package-and-solution-is-built.js | 1075 +++++- ...tion-is-not-built-with-preserveSymlinks.js | 933 ++++- ...coped-package-and-solution-is-not-built.js | 933 ++++- ...disableSourceOfProjectReferenceRedirect.js | 687 +++- ...ect-when-referenced-project-is-not-open.js | 395 ++- ...disableSourceOfProjectReferenceRedirect.js | 968 +++-- ...project-when-referenced-project-is-open.js | 564 ++- ...ject-is-directly-referenced-by-solution.js | 1426 +++++--- ...ct-is-indirectly-referenced-by-solution.js | 1922 +++++++--- ...nced-project-and-using-declaration-maps.js | 663 +++- ...ot-file-is-file-from-referenced-project.js | 663 +++- ...indirect-project-but-not-in-another-one.js | 542 ++- ...dProjectLoad-is-set-in-indirect-project.js | 532 ++- ...-if-disableReferencedProjectLoad-is-set.js | 380 +- ...ces-open-file-through-project-reference.js | 1599 ++++++--- ...ct-is-indirectly-referenced-by-solution.js | 2072 +++++++---- ...nction-as-object-literal-property-types.js | 406 ++- ...row-function-as-object-literal-property.js | 324 +- ...ss-when-using-arrow-function-assignment.js | 406 ++- ...s-when-using-method-of-class-expression.js | 408 ++- ...ness-when-using-object-literal-property.js | 406 ++- ...cts-are-open-and-one-project-references.js | 859 ++++- ...ts-have-allowJs-and-emitDeclarationOnly.js | 534 ++- ...ng-solution-and-siblings-are-not-loaded.js | 242 +- ...dts-changes-with-timeout-before-request.js | 1237 ++++++- .../dependency-dts-changes.js | 1121 +++++- .../dependency-dts-created.js | 1629 ++++++++- .../dependency-dts-deleted.js | 1612 ++++++++- .../dependency-dts-not-present.js | 1444 +++++++- ...Map-changes-with-timeout-before-request.js | 1231 ++++++- .../dependency-dtsMap-changes.js | 1115 +++++- .../dependency-dtsMap-created.js | 1623 ++++++++- .../dependency-dtsMap-deleted.js | 1624 ++++++++- .../dependency-dtsMap-not-present.js | 1489 +++++++- .../configHasNoReference/rename-locations.js | 1492 +++++++- ...ile-changes-with-timeout-before-request.js | 1238 ++++++- .../usage-file-changes.js | 1182 ++++++- ...dts-changes-with-timeout-before-request.js | 1237 ++++++- .../dependency-dts-changes.js | 1121 +++++- .../dependency-dts-created.js | 1629 ++++++++- .../dependency-dts-deleted.js | 1612 ++++++++- .../dependency-dts-not-present.js | 1444 +++++++- ...Map-changes-with-timeout-before-request.js | 1231 ++++++- .../dependency-dtsMap-changes.js | 1115 +++++- .../dependency-dtsMap-created.js | 1623 ++++++++- .../dependency-dtsMap-deleted.js | 1624 ++++++++- .../dependency-dtsMap-not-present.js | 1489 +++++++- ...rce-changes-with-timeout-before-request.js | 1238 ++++++- .../dependency-source-changes.js | 1182 ++++++- .../configWithReference/rename-locations.js | 1492 +++++++- ...ile-changes-with-timeout-before-request.js | 1238 ++++++- .../configWithReference/usage-file-changes.js | 1182 ++++++- .../when-projects-are-not-built.js | 1317 ++++++- ...dts-changes-with-timeout-before-request.js | 1237 ++++++- .../dependency-dts-changes.js | 1121 +++++- .../dependency-dts-created.js | 1629 ++++++++- .../dependency-dts-deleted.js | 1612 ++++++++- .../dependency-dts-not-present.js | 1444 +++++++- ...Map-changes-with-timeout-before-request.js | 1231 ++++++- .../dependency-dtsMap-changes.js | 1115 +++++- .../dependency-dtsMap-created.js | 1623 ++++++++- .../dependency-dtsMap-deleted.js | 1624 ++++++++- .../dependency-dtsMap-not-present.js | 1489 +++++++- .../disabledSourceRef/rename-locations.js | 1492 +++++++- ...ile-changes-with-timeout-before-request.js | 1238 ++++++- .../disabledSourceRef/usage-file-changes.js | 1182 ++++++- ...dts-changes-with-timeout-before-request.js | 2510 +++++++++++-- .../dependency-dts-changes.js | 2352 ++++++++++++- .../dependency-dts-created.js | 3086 ++++++++++++++-- .../dependency-dts-deleted.js | 2919 ++++++++++++++-- .../dependency-dts-not-present.js | 2524 +++++++++++-- ...Map-changes-with-timeout-before-request.js | 2502 +++++++++++-- .../dependency-dtsMap-changes.js | 2344 ++++++++++++- .../dependency-dtsMap-created.js | 3094 ++++++++++++++-- .../dependency-dtsMap-deleted.js | 2947 ++++++++++++++-- .../dependency-dtsMap-not-present.js | 2625 ++++++++++++-- .../goToDef-and-rename-locations.js | 2813 +++++++++++++-- ...ile-changes-with-timeout-before-request.js | 2589 +++++++++++++- .../usage-file-changes.js | 2517 ++++++++++++- ...dts-changes-with-timeout-before-request.js | 2504 +++++++++++-- .../dependency-dts-changes.js | 2346 ++++++++++++- .../dependency-dts-created.js | 3107 ++++++++++++++-- .../dependency-dts-deleted.js | 3094 ++++++++++++++-- .../dependency-dts-not-present.js | 2725 +++++++++++++-- ...Map-changes-with-timeout-before-request.js | 2498 +++++++++++-- .../dependency-dtsMap-changes.js | 2340 ++++++++++++- .../dependency-dtsMap-created.js | 3107 ++++++++++++++-- .../dependency-dtsMap-deleted.js | 3108 +++++++++++++++-- .../dependency-dtsMap-not-present.js | 2774 +++++++++++++-- ...rce-changes-with-timeout-before-request.js | 2493 ++++++++++++- .../dependency-source-changes.js | 2421 ++++++++++++- .../gotoDef-and-rename-locations.js | 2777 +++++++++++++-- ...ile-changes-with-timeout-before-request.js | 2585 +++++++++++++- .../configWithReference/usage-file-changes.js | 2513 ++++++++++++- .../when-projects-are-not-built.js | 2598 ++++++++++++-- ...dts-changes-with-timeout-before-request.js | 2518 +++++++++++-- .../dependency-dts-changes.js | 2360 ++++++++++++- .../dependency-dts-created.js | 3094 ++++++++++++++-- .../dependency-dts-deleted.js | 2927 ++++++++++++++-- .../dependency-dts-not-present.js | 2532 ++++++++++++-- ...Map-changes-with-timeout-before-request.js | 2510 +++++++++++-- .../dependency-dtsMap-changes.js | 2352 ++++++++++++- .../dependency-dtsMap-created.js | 3102 ++++++++++++++-- .../dependency-dtsMap-deleted.js | 2955 ++++++++++++++-- .../dependency-dtsMap-not-present.js | 2633 ++++++++++++-- .../gotoDef-and-rename-locations.js | 2821 +++++++++++++-- ...ile-changes-with-timeout-before-request.js | 2597 +++++++++++++- .../disabledSourceRef/usage-file-changes.js | 2525 ++++++++++++- .../can-go-to-definition-correctly.js | 1537 +++++++- ...dts-changes-with-timeout-before-request.js | 1247 ++++++- .../dependency-dts-changes.js | 1123 +++++- .../dependency-dts-created.js | 1649 ++++++++- .../dependency-dts-deleted.js | 1614 ++++++++- .../dependency-dts-not-present.js | 1401 +++++++- ...Map-changes-with-timeout-before-request.js | 1239 ++++++- .../dependency-dtsMap-changes.js | 1115 +++++- .../dependency-dtsMap-created.js | 1665 ++++++++- .../dependency-dtsMap-deleted.js | 1658 ++++++++- .../dependency-dtsMap-not-present.js | 1494 +++++++- ...ile-changes-with-timeout-before-request.js | 1254 ++++++- .../usage-file-changes.js | 1190 ++++++- .../can-go-to-definition-correctly.js | 1559 ++++++++- ...dts-changes-with-timeout-before-request.js | 1193 ++++++- .../dependency-dts-changes.js | 1129 +++++- .../dependency-dts-created.js | 1679 ++++++++- .../dependency-dts-deleted.js | 1680 ++++++++- .../dependency-dts-not-present.js | 1551 +++++++- ...Map-changes-with-timeout-before-request.js | 1187 ++++++- .../dependency-dtsMap-changes.js | 1123 +++++- .../dependency-dtsMap-created.js | 1677 ++++++++- .../dependency-dtsMap-deleted.js | 1678 ++++++++- .../dependency-dtsMap-not-present.js | 1556 ++++++++- ...rce-changes-with-timeout-before-request.js | 1267 ++++++- .../dependency-source-changes.js | 1143 +++++- ...ile-changes-with-timeout-before-request.js | 1274 ++++++- .../configWithReference/usage-file-changes.js | 1210 ++++++- .../when-projects-are-not-built.js | 1424 +++++++- .../can-go-to-definition-correctly.js | 1639 ++++++++- ...dts-changes-with-timeout-before-request.js | 1323 ++++++- .../dependency-dts-changes.js | 1191 ++++++- .../dependency-dts-created.js | 1759 +++++++++- .../dependency-dts-deleted.js | 1724 ++++++++- .../dependency-dts-not-present.js | 1503 +++++++- ...Map-changes-with-timeout-before-request.js | 1315 ++++++- .../dependency-dtsMap-changes.js | 1183 ++++++- .../dependency-dtsMap-created.js | 1775 +++++++++- .../dependency-dtsMap-deleted.js | 1768 +++++++++- .../dependency-dtsMap-not-present.js | 1596 ++++++++- ...ile-changes-with-timeout-before-request.js | 1338 ++++++- .../disabledSourceRef/usage-file-changes.js | 1266 ++++++- ...he-session-and-project-is-at-root-level.js | 276 +- ...ession-and-project-is-not-at-root-level.js | 408 ++- ...oundUpdate-and-project-is-at-root-level.js | 290 +- ...Update-and-project-is-not-at-root-level.js | 426 ++- ...oundUpdate-and-project-is-at-root-level.js | 292 +- ...Update-and-project-is-not-at-root-level.js | 414 ++- ...configured-project-that-will-be-removed.js | 521 ++- ...-and-closed-affecting-multiple-projects.js | 479 ++- ...ith-mixed-content-are-handled-correctly.js | 67 +- ...getting-project-from-orphan-script-info.js | 221 +- ...directory-watch-invoke-on-file-creation.js | 1244 +++++-- ...issing-files-added-with-tripleslash-ref.js | 296 +- .../projectsWithReferences/sample-project.js | 521 ++- ...es-with-deleting-referenced-config-file.js | 394 ++- ...ing-transitively-referenced-config-file.js | 380 +- ...ces-with-edit-in-referenced-config-file.js | 410 ++- ...ive-references-with-edit-on-config-file.js | 498 ++- ...ansitive-references-with-non-local-edit.js | 246 +- ...es-with-deleting-referenced-config-file.js | 436 ++- ...ing-transitively-referenced-config-file.js | 414 ++- ...les-with-edit-in-referenced-config-file.js | 434 ++- ...-without-files-with-edit-on-config-file.js | 518 ++- ...ences-without-files-with-non-local-edit.js | 262 +- ...unnecessary-lookup-invalidation-on-save.js | 205 +- ...an-load-typings-that-are-proper-modules.js | 86 +- .../disable-suggestion-diagnostics.js | 235 +- ...le-name-from-files-in-different-folders.js | 385 +- ...e-module-name-from-files-in-same-folder.js | 265 +- ...ative-module-name-from-inferred-project.js | 480 ++- .../npm-install-@types-works.js | 538 ++- ...le-name-from-files-in-different-folders.js | 347 +- ...e-module-name-from-files-in-same-folder.js | 221 +- ...tore-the-states-for-configured-projects.js | 512 ++- ...estore-the-states-for-inferred-projects.js | 521 ++- ...hould-remove-the-module-not-found-error.js | 315 +- .../resolutionCache/suggestion-diagnostics.js | 214 +- .../suppressed-diagnostic-events.js | 158 +- .../resolutionCache/when-resolution-fails.js | 119 +- .../when-resolves-to-ambient-module.js | 116 +- ...tion-when-project-compiles-from-sources.js | 1136 +++++- ...s-in-typings-folder-and-then-recompiles.js | 869 ++++- ...mpiles-after-deleting-generated-folders.js | 1305 ++++++- ...ping-when-project-compiles-from-sources.js | 1234 ++++++- ...s-in-typings-folder-and-then-recompiles.js | 985 +++++- ...mpiles-after-deleting-generated-folders.js | 1429 +++++++- ...name-in-common-file-renames-all-project.js | 638 +++- ...ed-project-and-semantic-operations-fail.js | 500 ++- ...-include-auto-type-reference-directives.js | 96 +- .../throws-on-unsupported-commands.js | 115 +- ...projects-discover-from-bower_components.js | 213 +- .../typingsInstaller/configured-projects.js | 164 +- ...utions-pointing-to-js-on-typing-install.js | 168 +- .../external-project-watch-options-errors.js | 80 + ...ect-watch-options-in-host-configuration.js | 183 +- .../external-project-watch-options.js | 152 +- .../watchEnvironment/files-at-root.js | 94 +- .../files-at-windows-style-root.js | 94 +- .../watchEnvironment/files-not-at-root.js | 98 +- .../files-not-at-windows-style-root.js | 98 +- .../inferred-project-watch-options-errors.js | 81 + ...ect-watch-options-in-host-configuration.js | 169 +- .../inferred-project-watch-options.js | 134 +- .../project-with-ascii-file-names-with-i.js | 85 +- .../project-with-ascii-file-names.js | 85 +- .../project-with-unicode-file-names.js | 85 +- ...files-starting-with-dot-in-node_modules.js | 143 +- ...polling-when-file-is-added-to-subfolder.js | 269 +- ...rectory-when-file-is-added-to-subfolder.js | 337 +- ...tchFile-when-file-is-added-to-subfolder.js | 305 +- ...watching-files-with-network-style-paths.js | 426 ++- ...en-watchFile-is-single-watcher-per-file.js | 105 +- ...excludeDirectories-option-in-configFile.js | 107 +- ...ludeDirectories-option-in-configuration.js | 142 +- ...ackPolling-option-as-host-configuration.js | 134 +- ...th-fallbackPolling-option-in-configFile.js | 134 +- ...hDirectory-option-as-host-configuration.js | 134 +- ...ith-watchDirectory-option-in-configFile.js | 101 +- ...-watchFile-option-as-host-configuration.js | 134 +- .../with-watchFile-option-in-configFile.js | 101 +- 419 files changed, 336503 insertions(+), 43072 deletions(-) create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/compile-on-save-emits-same-output-as-project-build-with-external-project.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-and-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-project-and-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-project-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-project-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-project-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-project.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-usage-project-and-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-usage-project-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-usage-project-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-usage-project-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency-with-usage-project.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-and-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-and-local-change-to-dependency-with-file.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-and-local-change-to-usage-with-project.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-with-project-and-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-with-project-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage-with-project.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/save-on-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-and-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-with-project-and-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-with-project-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-with-project-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-with-project-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency-with-project.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-and-change-to-depenedency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-with-project-and-change-to-depenedency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-with-project-and-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-with-project-and-local-change-to-dependency.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-with-project-and-local-change-to-usage.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage-with-project.js create mode 100644 tests/baselines/reference/tsserver/projectReferenceCompileOnSave/when-dependency-project-is-not-open-and-save-on-usage.js create mode 100644 tests/baselines/reference/tsserver/watchEnvironment/external-project-watch-options-errors.js create mode 100644 tests/baselines/reference/tsserver/watchEnvironment/inferred-project-watch-options-errors.js 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: `