diff --git a/cli/lsp/testing/server.rs b/cli/lsp/testing/server.rs index 638ab5b552..65a72bed43 100644 --- a/cli/lsp/testing/server.rs +++ b/cli/lsp/testing/server.rs @@ -109,6 +109,7 @@ impl TestServer { if let Some(Ok(parsed_source)) = document.maybe_parsed_source() { + let old_tds = tests.remove(specifier).unwrap_or_default(); let mut collector = TestCollector::new( specifier.clone(), parsed_source.text_info().clone(), @@ -127,6 +128,10 @@ impl TestServer { parsed_source.text_info(), ), ); + } else if !old_tds.is_empty() { + client.send_test_notification(as_delete_notification( + specifier.clone(), + )); } tests.insert(specifier.clone(), test_definitions); } diff --git a/cli/tests/integration/lsp_tests.rs b/cli/tests/integration/lsp_tests.rs index 665fa62758..218b1db40a 100644 --- a/cli/tests/integration/lsp_tests.rs +++ b/cli/tests/integration/lsp_tests.rs @@ -8549,6 +8549,32 @@ Deno.test({ _ => panic!("unexpected message {}", json!(notification)), } + // Regression test for https://github.com/denoland/vscode_deno/issues/899. + temp_dir.write("./test.ts", ""); + client.write_notification( + "textDocument/didChange", + json!({ + "textDocument": { + "uri": temp_dir.uri().join("test.ts").unwrap(), + "version": 2 + }, + "contentChanges": [{ "text": "" }], + }), + ); + + assert_eq!(client.read_diagnostics().all().len(), 0); + + let (method, notification) = client.read_notification::(); + assert_eq!(method, "deno/testModuleDelete"); + assert_eq!( + notification, + Some(json!({ + "textDocument": { + "uri": temp_dir.uri().join("test.ts").unwrap() + } + })) + ); + client.shutdown(); }