|
7 | 7 |
|
8 | 8 | "github.com/microsoft/typescript-go/internal/bundled" |
9 | 9 | "github.com/microsoft/typescript-go/internal/lsp/lsproto" |
| 10 | + "github.com/microsoft/typescript-go/internal/project" |
10 | 11 | "github.com/microsoft/typescript-go/internal/testutil/projecttestutil" |
11 | 12 | "gotest.tools/v3/assert" |
12 | 13 | ) |
@@ -618,4 +619,48 @@ func TestATA(t *testing.T) { |
618 | 619 | emberComponentTypesFile := program.GetSourceFile(projecttestutil.TestTypingsLocation + "/node_modules/@types/ember__component/index.d.ts") |
619 | 620 | assert.Assert(t, emberComponentTypesFile != nil, "ember__component types should be installed") |
620 | 621 | }) |
| 622 | + |
| 623 | + // Test that ATA works correctly when `WatchEnabled` is false but `TypingsLocation` is set. |
| 624 | + // Previously if `WatchEnabled` was false but `TypingsLocation` was set, ATA would run but |
| 625 | + // crash when cloning file-watcher data for a new snapshot. |
| 626 | + t.Run("ATA with WatchEnabled false should not panic", func(t *testing.T) { |
| 627 | + t.Parallel() |
| 628 | + |
| 629 | + files := map[string]any{ |
| 630 | + "/user/username/projects/project/app.js": ``, |
| 631 | + "/user/username/projects/project/package.json": `{ |
| 632 | + "name": "test", |
| 633 | + "dependencies": { |
| 634 | + "jquery": "^3.1.0" |
| 635 | + } |
| 636 | + }`, |
| 637 | + } |
| 638 | + |
| 639 | + session, utils := projecttestutil.SetupWithOptionsAndTypingsInstaller(files, &project.SessionOptions{ |
| 640 | + CurrentDirectory: "/", |
| 641 | + DefaultLibraryPath: bundled.LibPath(), |
| 642 | + TypingsLocation: projecttestutil.TestTypingsLocation, |
| 643 | + PositionEncoding: lsproto.PositionEncodingKindUTF8, |
| 644 | + WatchEnabled: false, |
| 645 | + LoggingEnabled: true, |
| 646 | + }, &projecttestutil.TypingsInstallerOptions{ |
| 647 | + PackageToFile: map[string]string{ |
| 648 | + "jquery": `declare const $: { x: number }`, |
| 649 | + }, |
| 650 | + }) |
| 651 | + |
| 652 | + // Open a file to trigger project creation and ATA. |
| 653 | + session.DidOpenFile(context.Background(), lsproto.DocumentUri("file:///user/username/projects/project/app.js"), 1, files["/user/username/projects/project/app.js"].(string), lsproto.LanguageKindJavaScript) |
| 654 | + session.WaitForBackgroundTasks() |
| 655 | + |
| 656 | + // ATA should have run |
| 657 | + calls := utils.NpmExecutor().NpmInstallCalls() |
| 658 | + assert.Equal(t, 2, len(calls), "Expected exactly 2 npm install calls") |
| 659 | + |
| 660 | + // Getting the language service should not panic after |
| 661 | + // applying ATA changes and grabbing the latest snapshot. |
| 662 | + ls, err := session.GetLanguageService(context.Background(), lsproto.DocumentUri("file:///user/username/projects/project/app.js")) |
| 663 | + assert.NilError(t, err) |
| 664 | + assert.Assert(t, ls != nil) |
| 665 | + }) |
621 | 666 | } |
0 commit comments