Skip to content

Commit 660975b

Browse files
authored
Use a global test client for all unit tests (#130)
* Gather test utilities into a single `test/` folder And rename a few files to reflect new location * Only register capabilities if the client supports at least one Otherwise we end up sending our test client a request here that it isn't expecting at this time, since it didn't say it supported these capabilities * Return comparable `Id`s, and add `initialized()` support This is definitely required for lsp-server, otherwise it can't proceed, but is also the right thing to do as a client in general * Move initialization/shutdown test to integration test With new support for sending `initialized()` too * Use a single global test client in all unit tests * Enforce single tracing subscriber even during tests * Remove `--test-threads 1` from CI
1 parent f7ac7e4 commit 660975b

File tree

16 files changed

+312
-264
lines changed

16 files changed

+312
-264
lines changed

.github/workflows/test-linux.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ jobs:
5454
env:
5555
AIR_LOG_LEVEL: trace
5656
# `--nocapture` to see our own `tracing` logs
57-
# `--test-threads 1` to ensure `tracing` logs aren't interleaved
58-
run: cargo test -- --nocapture --test-threads 1
57+
run: cargo test -- --nocapture

.github/workflows/test-mac.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ jobs:
3232
env:
3333
AIR_LOG_LEVEL: trace
3434
# `--nocapture` to see our own `tracing` logs
35-
# `--test-threads 1` to ensure `tracing` logs aren't interleaved
36-
run: cargo test -- --nocapture --test-threads 1
35+
run: cargo test -- --nocapture

.github/workflows/test-windows.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ jobs:
3232
env:
3333
AIR_LOG_LEVEL: trace
3434
# `--nocapture` to see our own `tracing` logs
35-
# `--test-threads 1` to ensure `tracing` logs aren't interleaved
36-
run: cargo test -- --nocapture --test-threads 1
35+
run: cargo test -- --nocapture

crates/lsp/src/documents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Document {
9191

9292
#[cfg(test)]
9393
pub fn doodle_and_range(contents: &str) -> (Self, biome_text_size::TextRange) {
94-
let (contents, range) = crate::test_utils::extract_marked_range(contents);
94+
let (contents, range) = crate::test::extract_marked_range(contents);
9595
let doc = Self::new(contents, None, PositionEncoding::Utf8);
9696
(doc, range)
9797
}

crates/lsp/src/handlers.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ pub(crate) async fn handle_initialized(
7373
registrations.push(watch_air_toml_registration);
7474
}
7575

76-
client
77-
.register_capability(registrations)
78-
.instrument(span.exit())
79-
.await?;
76+
if !registrations.is_empty() {
77+
client
78+
.register_capability(registrations)
79+
.instrument(span.exit())
80+
.await?;
81+
}
82+
8083
Ok(())
8184
}
8285

0 commit comments

Comments
 (0)