58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
package fourslash_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/microsoft/typescript-go/internal/fourslash"
|
|
. "github.com/microsoft/typescript-go/internal/fourslash/tests/util"
|
|
"github.com/microsoft/typescript-go/internal/ls"
|
|
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
|
|
"github.com/microsoft/typescript-go/internal/testutil"
|
|
)
|
|
|
|
// TestAutoImportNodeBuiltinNodenext is a regression test for
|
|
// https://github.com/microsoft/typescript-go/issues/2555, where auto-imports
|
|
// for Node.js built-in modules (e.g. "fs") were not appearing when using
|
|
// module: nodenext and types: ["node"].
|
|
func TestAutoImportNodeBuiltinNodenext(t *testing.T) {
|
|
t.Parallel()
|
|
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
|
|
const content = `// @Filename: /tsconfig.json
|
|
{ "compilerOptions": { "module": "nodenext", "types": ["node"] } }
|
|
// @Filename: /package.json
|
|
{ "type": "module" }
|
|
// @Filename: /node_modules/@types/node/package.json
|
|
{ "name": "@types/node", "version": "22.0.0" }
|
|
// @Filename: /node_modules/@types/node/index.d.ts
|
|
declare module "fs" {
|
|
export function existsSync(path: string): boolean;
|
|
export function mkdirSync(path: string, options?: { recursive?: boolean }): void;
|
|
}
|
|
declare module "node:fs" { export * from "fs"; }
|
|
// @Filename: /index.ts
|
|
existsSync/**/`
|
|
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
|
|
defer done()
|
|
f.VerifyCompletions(t, "", &fourslash.CompletionsExpectedList{
|
|
IsIncomplete: false,
|
|
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
|
|
CommitCharacters: &DefaultCommitCharacters,
|
|
EditRange: Ignored,
|
|
},
|
|
Items: &fourslash.CompletionsExpectedItems{
|
|
Includes: []fourslash.CompletionsExpectedItem{
|
|
&lsproto.CompletionItem{
|
|
Label: "existsSync",
|
|
Data: &lsproto.CompletionItemData{
|
|
AutoImport: &lsproto.AutoImportFix{
|
|
ModuleSpecifier: "node:fs",
|
|
},
|
|
},
|
|
AdditionalTextEdits: fourslash.AnyTextEdits,
|
|
SortText: new(string(ls.SortTextAutoImportSuggestions)),
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|