From a9b7f33a714ca950172ff02b53f1a1dc75a807c5 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 12 Nov 2026 20:02:37 -0800 Subject: [PATCH 1/2] Restore fourslash marker selection and native JS test discovery Marker iteration tested its freshly allocated result instead of the requested names. Subsets were ignored and missing names went unchecked. Give the import-path rename test real markers and recognize resource operations in rename assertions now that those callbacks actually run. Go treats a trailing _js_test.go as a platform constraint. Rename the thirteen affected tests without changing their identities, and record the newly exercised reference baselines. Rewrite the CommonJS fixture using supported class expandos rather than mixed export assignments, keeping its module-reference assertion and error checks intact. --- tsc/internal/fourslash/fourslash.go | 12 +++- tsc/internal/fourslash/fourslash_test.go | 70 +++++++++++++++++++ ...tPackageJsonImportsPattern_jsFile_test.go} | 0 ...ckageJsonImportsPattern_ts_jsFile_test.go} | 0 ...toImportPackageJsonImports_jsFile_test.go} | 0 ...lateFunctionWithParameters_jsFile_test.go} | 0 ...RefsJsDocTemplateTag_class_jsFile_test.go} | 0 ...sJsDocTemplateTag_function_jsFile_test.go} | 0 ...=> findAllRefsJsDocTypeDef_jsFile_test.go} | 0 ... => findAllRefs_importType_jsFile_test.go} | 7 +- .../importAllowRenameOfImportPath_test.go | 6 +- ...sPackageJsonImportsPattern_jsFile_test.go} | 0 ...ckageJsonImportsPattern_ts_jsFile_test.go} | 0 ...pletionsPackageJsonImports_jsFile_test.go} | 0 ...o => importNameCodeFix_all_jsFile_test.go} | 0 ...importStatementCompletions_jsFile_test.go} | 0 ...fsJsDocTemplateTag_class_js.baseline.jsonc | 19 +++++ ...sDocTemplateTag_function_js.baseline.jsonc | 17 +++++ .../findAllRefsJsDocTypeDef_js.baseline.jsonc | 55 +++++++++++++++ .../findAllRefs_importType_js.baseline.jsonc | 11 +++ 20 files changed, 188 insertions(+), 9 deletions(-) create mode 100644 tsc/internal/fourslash/fourslash_test.go rename tsc/internal/fourslash/tests/{autoImportPackageJsonImportsPattern_js_test.go => autoImportPackageJsonImportsPattern_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{autoImportPackageJsonImportsPattern_ts_js_test.go => autoImportPackageJsonImportsPattern_ts_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{autoImportPackageJsonImports_js_test.go => autoImportPackageJsonImports_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{docCommentTemplateFunctionWithParameters_js_test.go => docCommentTemplateFunctionWithParameters_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{findAllRefsJsDocTemplateTag_class_js_test.go => findAllRefsJsDocTemplateTag_class_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{findAllRefsJsDocTemplateTag_function_js_test.go => findAllRefsJsDocTemplateTag_function_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{findAllRefsJsDocTypeDef_js_test.go => findAllRefsJsDocTypeDef_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{findAllRefs_importType_js_test.go => findAllRefs_importType_jsFile_test.go} (84%) rename tsc/internal/fourslash/tests/{importCompletionsPackageJsonImportsPattern_js_test.go => importCompletionsPackageJsonImportsPattern_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{importCompletionsPackageJsonImportsPattern_ts_js_test.go => importCompletionsPackageJsonImportsPattern_ts_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{importCompletionsPackageJsonImports_js_test.go => importCompletionsPackageJsonImports_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{importNameCodeFix_all_js_test.go => importNameCodeFix_all_jsFile_test.go} (100%) rename tsc/internal/fourslash/tests/{importStatementCompletions_js_test.go => importStatementCompletions_jsFile_test.go} (100%) create mode 100644 tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_class_js.baseline.jsonc create mode 100644 tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_function_js.baseline.jsonc create mode 100644 tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTypeDef_js.baseline.jsonc create mode 100644 tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefs_importType_js.baseline.jsonc diff --git a/tsc/internal/fourslash/fourslash.go b/tsc/internal/fourslash/fourslash.go index b2ffb1c33606d..a70264613d833 100644 --- a/tsc/internal/fourslash/fourslash.go +++ b/tsc/internal/fourslash/fourslash.go @@ -879,7 +879,7 @@ func (f *FourslashTest) goToPosition(t *testing.T, position lsproto.Position) { func (f *FourslashTest) GoToEachMarker(t *testing.T, markerNames []string, action func(marker *Marker, index int)) { var markers []*Marker - if len(markers) == 0 { + if len(markerNames) == 0 { markers = f.Markers() } else { markers = make([]*Marker, 0, len(markerNames)) @@ -4896,7 +4896,10 @@ func (f *FourslashTest) VerifyRenameSucceeded(t *testing.T, preferences *lsutil. Position: f.currentCaretPosition, NewName: "RENAME_SUCCEEDED_TEST", }) - if renameResult.WorkspaceEdit == nil || renameResult.WorkspaceEdit.Changes == nil || len(*renameResult.WorkspaceEdit.Changes) == 0 { + edit := renameResult.WorkspaceEdit + if edit == nil || + ((edit.Changes == nil || len(*edit.Changes) == 0) && + (edit.DocumentChanges == nil || len(*edit.DocumentChanges) == 0)) { t.Fatal(prefix + "prepareRename succeeded but textDocument/rename returned no changes") } } @@ -5229,7 +5232,10 @@ func (f *FourslashTest) VerifyRenameFailed(t *testing.T, preferences *lsutil.Use if renameMsg != nil && renameMsg.AsResponse().Error != nil { return } - if renameResult.WorkspaceEdit != nil && renameResult.WorkspaceEdit.Changes != nil && len(*renameResult.WorkspaceEdit.Changes) > 0 { + edit := renameResult.WorkspaceEdit + if edit != nil && + ((edit.Changes != nil && len(*edit.Changes) > 0) || + (edit.DocumentChanges != nil && len(*edit.DocumentChanges) > 0)) { t.Fatalf("%sprepareRename returned null but textDocument/rename returned changes", prefix) } } diff --git a/tsc/internal/fourslash/fourslash_test.go b/tsc/internal/fourslash/fourslash_test.go new file mode 100644 index 0000000000000..741e6e955cf1f --- /dev/null +++ b/tsc/internal/fourslash/fourslash_test.go @@ -0,0 +1,70 @@ +package fourslash + +import ( + "os" + "os/exec" + "slices" + "strings" + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" +) + +func newMarkerTest(t *testing.T) *FourslashTest { + data := ParseTestData(t, `const /*first*/x = /*second*/1; /*third*/`, "markers.ts") + return &FourslashTest{ + testData: &data, + activeFilename: data.Markers[0].FileName(), + } +} + +func TestGoToEachMarker(t *testing.T) { + t.Parallel() + for _, tt := range []struct { + name string + selected []string + want []string + }{ + {name: "all", want: []string{"first", "second", "third"}}, + {name: "empty", selected: []string{}, want: []string{"first", "second", "third"}}, + {name: "subset", selected: []string{"second"}, want: []string{"second"}}, + {name: "ordered duplicates", selected: []string{"third", "first", "third"}, want: []string{"third", "first", "third"}}, + } { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + f := newMarkerTest(t) + var visited []string + f.GoToEachMarker(t, tt.selected, func(marker *Marker, index int) { + if index != len(visited) { + t.Errorf("callback index = %d, want %d", index, len(visited)) + } + if f.currentCaretPosition != marker.LSPos() || f.lastKnownMarkerName != marker.GetName() || f.selectionEnd != nil { + t.Error("callback did not observe navigation to its marker") + } + visited = append(visited, *marker.Name) + f.selectionEnd = new(lsproto.Position{}) + }) + if !slices.Equal(visited, tt.want) { + t.Fatalf("visited %v, want %v", visited, tt.want) + } + }) + } +} + +func TestGoToEachMarkerMissing(t *testing.T) { + t.Parallel() + const helperEnv = "FOURSLASH_MISSING_MARKER_HELPER" + if os.Getenv(helperEnv) == "1" { + f := newMarkerTest(t) + f.GoToEachMarker(t, []string{"first", "missing"}, func(marker *Marker, index int) { + t.Error("unexpected marker callback") + }) + return + } + cmd := exec.Command(os.Args[0], "-test.run=^TestGoToEachMarkerMissing$") + cmd.Env = append(os.Environ(), helperEnv+"=1") + output, err := cmd.CombinedOutput() + if err == nil || !strings.Contains(string(output), "Marker 'missing' not found") || strings.Contains(string(output), "unexpected marker callback") { + t.Fatalf("expected missing marker failure before any callbacks; got %v\n%s", err, output) + } +} diff --git a/tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_js_test.go b/tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_js_test.go rename to tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_ts_js_test.go b/tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_ts_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_ts_js_test.go rename to tsc/internal/fourslash/tests/autoImportPackageJsonImportsPattern_ts_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/autoImportPackageJsonImports_js_test.go b/tsc/internal/fourslash/tests/autoImportPackageJsonImports_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/autoImportPackageJsonImports_js_test.go rename to tsc/internal/fourslash/tests/autoImportPackageJsonImports_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/docCommentTemplateFunctionWithParameters_js_test.go b/tsc/internal/fourslash/tests/docCommentTemplateFunctionWithParameters_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/docCommentTemplateFunctionWithParameters_js_test.go rename to tsc/internal/fourslash/tests/docCommentTemplateFunctionWithParameters_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_class_js_test.go b/tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_class_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_class_js_test.go rename to tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_class_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_function_js_test.go b/tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_function_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_function_js_test.go rename to tsc/internal/fourslash/tests/findAllRefsJsDocTemplateTag_function_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/findAllRefsJsDocTypeDef_js_test.go b/tsc/internal/fourslash/tests/findAllRefsJsDocTypeDef_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/findAllRefsJsDocTypeDef_js_test.go rename to tsc/internal/fourslash/tests/findAllRefsJsDocTypeDef_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/findAllRefs_importType_js_test.go b/tsc/internal/fourslash/tests/findAllRefs_importType_jsFile_test.go similarity index 84% rename from tsc/internal/fourslash/tests/findAllRefs_importType_js_test.go rename to tsc/internal/fourslash/tests/findAllRefs_importType_jsFile_test.go index 08d2b655e1b52..16d75c16a85a6 100644 --- a/tsc/internal/fourslash/tests/findAllRefs_importType_js_test.go +++ b/tsc/internal/fourslash/tests/findAllRefs_importType_jsFile_test.go @@ -13,12 +13,13 @@ func TestFindAllRefs_importType_js(t *testing.T) { const content = `// @allowJs: true // @checkJs: true // @Filename: /a.js -/**/module.exports = class C {}; -module.exports.D = class D {}; +class C {} +C.D = class D {}; +/**/module.exports = C; // @Filename: /b.js /** @type {import("./a")} */ const x = 0; -/** @type {import("./a").D} */ +/** @type {InstanceType} */ const y = 0;` f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) defer done() diff --git a/tsc/internal/fourslash/tests/importAllowRenameOfImportPath_test.go b/tsc/internal/fourslash/tests/importAllowRenameOfImportPath_test.go index 6465cfa65b4b5..5e0c4e80e087a 100644 --- a/tsc/internal/fourslash/tests/importAllowRenameOfImportPath_test.go +++ b/tsc/internal/fourslash/tests/importAllowRenameOfImportPath_test.go @@ -17,9 +17,9 @@ export const x = 0; // @Filename: /dir/index.ts export const x = 0; // @Filename: /b.ts -import * as a from "./[|a|]"; -import * as dir from "./[|dir|]"; -import * as dir2 from "./dir/[|index|]"; +import * as a from "./[|/*a*/a|]"; +import * as dir from "./[|/*dir*/dir|]"; +import * as dir2 from "./dir/[|/*index*/index|]"; // @Filename: /c.js const a = require("./[|a|]"); ` diff --git a/tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_js_test.go b/tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_js_test.go rename to tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_ts_js_test.go b/tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_ts_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_ts_js_test.go rename to tsc/internal/fourslash/tests/importCompletionsPackageJsonImportsPattern_ts_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/importCompletionsPackageJsonImports_js_test.go b/tsc/internal/fourslash/tests/importCompletionsPackageJsonImports_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/importCompletionsPackageJsonImports_js_test.go rename to tsc/internal/fourslash/tests/importCompletionsPackageJsonImports_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/importNameCodeFix_all_js_test.go b/tsc/internal/fourslash/tests/importNameCodeFix_all_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/importNameCodeFix_all_js_test.go rename to tsc/internal/fourslash/tests/importNameCodeFix_all_jsFile_test.go diff --git a/tsc/internal/fourslash/tests/importStatementCompletions_js_test.go b/tsc/internal/fourslash/tests/importStatementCompletions_jsFile_test.go similarity index 100% rename from tsc/internal/fourslash/tests/importStatementCompletions_js_test.go rename to tsc/internal/fourslash/tests/importStatementCompletions_jsFile_test.go diff --git a/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_class_js.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_class_js.baseline.jsonc new file mode 100644 index 0000000000000..4067d0f90d156 --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_class_js.baseline.jsonc @@ -0,0 +1,19 @@ +// === findAllReferences === +// === /a.js === +// /** @template /*FIND ALL REFS*/T */ +// class C { +// constructor() { +// /** @type {T} */ +// --- (line: 5) skipped --- + + + +// === findAllReferences === +// === /a.js === +// /** @template T */ +// class C { +// constructor() { +// /** @type {/*FIND ALL REFS*/[|T|]} */ +// this.x = null; +// } +// } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_function_js.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_function_js.baseline.jsonc new file mode 100644 index 0000000000000..1e85c2d93fca0 --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTemplateTag_function_js.baseline.jsonc @@ -0,0 +1,17 @@ +// === findAllReferences === +// === /a.js === +// /** +// * @template /*FIND ALL REFS*/T +// * @return {T} +// */ +// function f() {} + + + +// === findAllReferences === +// === /a.js === +// /** +// * @template T +// * @return {/*FIND ALL REFS*/[|T|]} +// */ +// function f() {} \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTypeDef_js.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTypeDef_js.baseline.jsonc new file mode 100644 index 0000000000000..477f7f8c79270 --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefsJsDocTypeDef_js.baseline.jsonc @@ -0,0 +1,55 @@ +// === findAllReferences === +// === /a.js === +// /** /*FIND ALL REFS*/@typedef {number} T */ +// +// /** +// * @return {T} +// --- (line: 5) skipped --- + + + +// === findAllReferences === +// === /a.js === +// /** @typedef {number} /*FIND ALL REFS*/[|T|] */ +// +// /** +// * @return {[|T|]} +// */ +// function f(obj) { return 0; } +// +// /** +// * @return {[|T|]} +// */ +// function f2(obj) { return 0; } + + + +// === findAllReferences === +// === /a.js === +// /** @typedef {number} [|T|] */ +// +// /** +// * @return {/*FIND ALL REFS*/[|T|]} +// */ +// function f(obj) { return 0; } +// +// /** +// * @return {[|T|]} +// */ +// function f2(obj) { return 0; } + + + +// === findAllReferences === +// === /a.js === +// /** @typedef {number} [|T|] */ +// +// /** +// * @return {[|T|]} +// */ +// function f(obj) { return 0; } +// +// /** +// * @return {/*FIND ALL REFS*/[|T|]} +// */ +// function f2(obj) { return 0; } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefs_importType_js.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefs_importType_js.baseline.jsonc new file mode 100644 index 0000000000000..2aa830a1f8517 --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/findAllReferences/findAllRefs_importType_js.baseline.jsonc @@ -0,0 +1,11 @@ +// === findAllReferences === +// === /a.js === +// class C {} +// C.D = class D {}; +// /*FIND ALL REFS*/[|module|].exports = C; + +// === /b.js === +// /** @type {import("[|./a|]")} */ +// const x = 0; +// /** @type {InstanceType} */ +// const y = 0; \ No newline at end of file From 5c673a569cf27880fb0f66f162fd57297817b2d7 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 09:40:52 -0800 Subject: [PATCH 2/2] Remove subprocess-only missing-marker test WASI cannot launch the subprocess used to test a missing marker. Keep the direct marker-selection tests without the process-based check. --- tsc/internal/fourslash/fourslash_test.go | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/tsc/internal/fourslash/fourslash_test.go b/tsc/internal/fourslash/fourslash_test.go index 741e6e955cf1f..e5dbd025ebf8d 100644 --- a/tsc/internal/fourslash/fourslash_test.go +++ b/tsc/internal/fourslash/fourslash_test.go @@ -1,10 +1,7 @@ package fourslash import ( - "os" - "os/exec" "slices" - "strings" "testing" "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" @@ -50,21 +47,3 @@ func TestGoToEachMarker(t *testing.T) { }) } } - -func TestGoToEachMarkerMissing(t *testing.T) { - t.Parallel() - const helperEnv = "FOURSLASH_MISSING_MARKER_HELPER" - if os.Getenv(helperEnv) == "1" { - f := newMarkerTest(t) - f.GoToEachMarker(t, []string{"first", "missing"}, func(marker *Marker, index int) { - t.Error("unexpected marker callback") - }) - return - } - cmd := exec.Command(os.Args[0], "-test.run=^TestGoToEachMarkerMissing$") - cmd.Env = append(os.Environ(), helperEnv+"=1") - output, err := cmd.CombinedOutput() - if err == nil || !strings.Contains(string(output), "Marker 'missing' not found") || strings.Contains(string(output), "unexpected marker callback") { - t.Fatalf("expected missing marker failure before any callbacks; got %v\n%s", err, output) - } -}