|
| 1 | +package lsp_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "io" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/microsoft/TypeScript/tsc/internal/bundled" |
| 10 | + "github.com/microsoft/TypeScript/tsc/internal/lsp" |
| 11 | + "github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto" |
| 12 | + "github.com/microsoft/TypeScript/tsc/internal/testutil/lsptestutil" |
| 13 | + "github.com/microsoft/TypeScript/tsc/internal/vfs/vfstest" |
| 14 | + "gotest.tools/v3/assert" |
| 15 | +) |
| 16 | + |
| 17 | +func TestFlakyDiagnosticTrackingParallelEmit(t *testing.T) { |
| 18 | + t.Parallel() |
| 19 | + if !bundled.Embedded { |
| 20 | + t.Skip("bundled files are not embedded") |
| 21 | + } |
| 22 | + |
| 23 | + for _, noEmitOnError := range []bool{false, true} { |
| 24 | + t.Run(fmt.Sprintf("noEmitOnError=%t", noEmitOnError), func(t *testing.T) { |
| 25 | + t.Parallel() |
| 26 | + files := map[string]string{ |
| 27 | + "/src/tsconfig.json": fmt.Sprintf(`{ |
| 28 | + "compilerOptions": { "strict": true, "declaration": true, "noEmitOnError": %t, "outDir": "out" } |
| 29 | + }`, noEmitOnError), |
| 30 | + "/src/a.ts": `export function box<T>(value: T) { return { value }; }`, |
| 31 | + "/src/b.ts": `import { box } from "./a"; export const b = box("b");`, |
| 32 | + "/src/c.ts": `import { box } from "./a"; export const c = box(1);`, |
| 33 | + } |
| 34 | + client, closeClient := lsptestutil.NewLSPClient(t, lsp.ServerOptions{ |
| 35 | + Err: io.Discard, |
| 36 | + Cwd: "/src", |
| 37 | + FS: bundled.WrapFS(vfstest.FromMap(files, false)), |
| 38 | + DefaultLibraryPath: bundled.LibPath(), |
| 39 | + }, func(_ context.Context, req *lsproto.RequestMessage) *lsproto.ResponseMessage { |
| 40 | + switch req.Method { |
| 41 | + case lsproto.MethodClientRegisterCapability, lsproto.MethodClientUnregisterCapability, lsproto.MethodWindowWorkDoneProgressCreate: |
| 42 | + return &lsproto.ResponseMessage{ID: req.ID, JSONRPC: req.JSONRPC, Result: lsproto.Null{}} |
| 43 | + default: |
| 44 | + return nil |
| 45 | + } |
| 46 | + }) |
| 47 | + t.Cleanup(func() { _ = closeClient() }) |
| 48 | + |
| 49 | + msg, _, ok := client.SendRequest(t, lsproto.InitializeInfo, &lsproto.InitializeParams{ |
| 50 | + Capabilities: &lsproto.ClientCapabilities{}, |
| 51 | + InitializationOptions: &lsproto.InitializationOptionsOrNull{ |
| 52 | + InitializationOptions: &lsproto.InitializationOptions{TrackFlakyDiagnostics: new(lsproto.DiagnosticFlakeLogLevelPanic)}, |
| 53 | + }, |
| 54 | + }) |
| 55 | + assert.Assert(t, ok && msg.AsResponse().Error == nil, "initialize failed") |
| 56 | + client.SendNotification(t, lsproto.InitializedInfo, &lsproto.InitializedParams{}) |
| 57 | + <-client.Server.InitComplete() |
| 58 | + |
| 59 | + uri := lsproto.DocumentUri("file:///src/a.ts") |
| 60 | + client.SendNotification(t, lsproto.TextDocumentDidOpenInfo, &lsproto.DidOpenTextDocumentParams{ |
| 61 | + TextDocument: &lsproto.TextDocumentItem{Uri: uri, LanguageId: lsproto.LanguageKindTypeScript, Text: files["/src/a.ts"]}, |
| 62 | + }) |
| 63 | + msg, diagnostics, ok := client.SendRequest(t, lsproto.TextDocumentDiagnosticInfo, &lsproto.DocumentDiagnosticParams{ |
| 64 | + TextDocument: lsproto.TextDocumentIdentifier{Uri: uri}, |
| 65 | + }) |
| 66 | + assert.Assert(t, ok && msg.AsResponse().Error == nil, "diagnostics request failed") |
| 67 | + assert.Assert(t, diagnostics.FullDocumentDiagnosticReport != nil) |
| 68 | + assert.Equal(t, len(diagnostics.FullDocumentDiagnosticReport.Items), 0) |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
0 commit comments