MCPcopy Create free account
hub / github.com/aeroxy/chrome-devtools-cli / test_telemetry_log_command

Function test_telemetry_log_command

tests/telemetry_tests.rs:12–42  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10/// Test that TelemetryLogger writes a valid JSON entry and cleans up.
11#[test]
12fn test_telemetry_log_command() {
13 use chrome_devtools_cli::telemetry::{init_logger_once, log_command};
14 use std::time::Duration;
15
16 let tmp = tempfile::tempdir().expect("failed to create temp dir");
17 init_logger_once(tmp.path().to_path_buf());
18
19 log_command("test-command", Duration::from_millis(42), true, None);
20
21 // Give the background thread a moment to write
22 std::thread::sleep(Duration::from_millis(200));
23
24 // Find the log file — it's date-based so there should be exactly one
25 let log_files: Vec<_> = std::fs::read_dir(tmp.path())
26 .expect("temp dir should exist")
27 .filter_map(|e| e.ok())
28 .collect();
29 assert_eq!(log_files.len(), 1, "expected exactly one log file");
30
31 let content =
32 std::fs::read_to_string(log_files[0].path()).expect("should be able to read log file");
33
34 // The entry should be valid JSON with the command we logged
35 let parsed: serde_json::Value =
36 serde_json::from_str(content.trim()).expect("log entry should be valid JSON");
37 assert_eq!(parsed["command"], "test-command");
38 assert_eq!(parsed["duration_ms"], 42);
39 assert_eq!(parsed["success"], true);
40
41 // tmp (TempDir) is dropped here, cleaning up the directory
42}
43
44/// Test that default_dir produces a path under the home directory.
45#[test]

Callers

nothing calls this directly

Calls 2

init_logger_onceFunction · 0.85
log_commandFunction · 0.85

Tested by

no test coverage detected