Skip to content

Commit 4f1094d

Browse files
committed
Add failing test for watching file outside of tsconfig root files
1 parent 31e58bf commit 4f1094d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

internal/project/session_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"testing"
77

88
"github.com/microsoft/typescript-go/internal/bundled"
9+
"github.com/microsoft/typescript-go/internal/core"
10+
"github.com/microsoft/typescript-go/internal/glob"
911
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
1012
"github.com/microsoft/typescript-go/internal/testutil/projecttestutil"
1113
"github.com/microsoft/typescript-go/internal/tspath"
@@ -548,6 +550,55 @@ func TestSession(t *testing.T) {
548550
assert.Check(t, lsAfter.GetProgram() != programBefore)
549551
})
550552

553+
t.Run("change program file not in tsconfig root files", func(t *testing.T) {
554+
t.Parallel()
555+
files := map[string]any{
556+
"/home/projects/TS/p1/tsconfig.json": `{
557+
"compilerOptions": {
558+
"noLib": true,
559+
"module": "nodenext",
560+
"strict": true
561+
},
562+
"files": ["src/index.ts"]
563+
}`,
564+
"/home/projects/TS/p1/src/index.ts": `import { x } from "../../x";`,
565+
"/home/projects/TS/x.ts": `export const x = 1;`,
566+
}
567+
568+
session, utils := projecttestutil.Setup(files)
569+
session.DidOpenFile(context.Background(), "file:///home/projects/TS/p1/src/index.ts", 1, files["/home/projects/TS/p1/src/index.ts"].(string), lsproto.LanguageKindTypeScript)
570+
lsBefore, err := session.GetLanguageService(context.Background(), "file:///home/projects/TS/p1/src/index.ts")
571+
assert.NilError(t, err)
572+
programBefore := lsBefore.GetProgram()
573+
session.WaitForBackgroundTasks()
574+
575+
var xWatched bool
576+
outer:
577+
for _, call := range utils.Client().WatchFilesCalls() {
578+
for _, watcher := range call.Watchers {
579+
if core.Must(glob.Parse(*watcher.GlobPattern.Pattern)).Match("/home/projects/TS/x.ts") {
580+
xWatched = true
581+
break outer
582+
}
583+
}
584+
}
585+
assert.Check(t, xWatched)
586+
587+
err = utils.FS().WriteFile("/home/projects/TS/x.ts", `export const x = 2;`, false)
588+
assert.NilError(t, err)
589+
590+
session.DidChangeWatchedFiles(context.Background(), []*lsproto.FileEvent{
591+
{
592+
Type: lsproto.FileChangeTypeChanged,
593+
Uri: "file:///home/projects/TS/x.ts",
594+
},
595+
})
596+
597+
lsAfter, err := session.GetLanguageService(context.Background(), "file:///home/projects/TS/p1/src/index.ts")
598+
assert.NilError(t, err)
599+
assert.Check(t, lsAfter.GetProgram() != programBefore)
600+
})
601+
551602
t.Run("change config file", func(t *testing.T) {
552603
t.Parallel()
553604
files := map[string]any{

0 commit comments

Comments
 (0)