mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-20 15:40:29 +01:00
bcd79331b9
- construct the correct path to the test library based on the location of package.json - run scripts from the package root where they were defined - run tests in the directory of the defining file Release Notes: - Debugger Beta: fixed running JS tests when the worktree root is above the location of package.json. --------- Co-authored-by: Anthony <anthony@zed.dev> Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
83 lines
2.6 KiB
Rust
83 lines
2.6 KiB
Rust
use std::{borrow::Cow, path::PathBuf};
|
|
|
|
use anyhow::{Result, bail};
|
|
use async_trait::async_trait;
|
|
use dap::{DapLocator, DebugRequest, adapters::DebugAdapterName};
|
|
use gpui::SharedString;
|
|
|
|
use task::{DebugScenario, SpawnInTerminal, TaskTemplate, VariableName};
|
|
|
|
pub(crate) struct NodeLocator;
|
|
|
|
const TYPESCRIPT_RUNNER_VARIABLE: VariableName =
|
|
VariableName::Custom(Cow::Borrowed("TYPESCRIPT_RUNNER"));
|
|
|
|
#[async_trait]
|
|
impl DapLocator for NodeLocator {
|
|
fn name(&self) -> SharedString {
|
|
SharedString::new_static("Node")
|
|
}
|
|
|
|
/// Determines whether this locator can generate debug target for given task.
|
|
fn create_scenario(
|
|
&self,
|
|
build_config: &TaskTemplate,
|
|
resolved_label: &str,
|
|
adapter: DebugAdapterName,
|
|
) -> Option<DebugScenario> {
|
|
if adapter.0.as_ref() != "JavaScript" {
|
|
return None;
|
|
}
|
|
if build_config.command != TYPESCRIPT_RUNNER_VARIABLE.template_value() {
|
|
return None;
|
|
}
|
|
let test_library = build_config.args.first()?;
|
|
let program_path_base: PathBuf = match test_library.as_str() {
|
|
"jest" => "${ZED_CUSTOM_TYPESCRIPT_JEST_PACKAGE_PATH}".to_owned(),
|
|
"mocha" => "${ZED_CUSTOM_TYPESCRIPT_MOCHA_PACKAGE_PATH}".to_owned(),
|
|
"vitest" => "${ZED_CUSTOM_TYPESCRIPT_VITEST_PACKAGE_PATH}".to_owned(),
|
|
"jasmine" => "${ZED_CUSTOM_TYPESCRIPT_JASMINE_PACKAGE_PATH}".to_owned(),
|
|
_ => VariableName::WorktreeRoot.template_value(),
|
|
}
|
|
.into();
|
|
|
|
let program_path = program_path_base
|
|
.join("node_modules")
|
|
.join(".bin")
|
|
.join(test_library);
|
|
|
|
let mut args = if test_library == "jest" {
|
|
vec!["--runInBand".to_owned()]
|
|
} else {
|
|
vec![]
|
|
};
|
|
args.extend(build_config.args[1..].iter().cloned());
|
|
|
|
let config = serde_json::json!({
|
|
"request": "launch",
|
|
"type": "pwa-node",
|
|
"runtimeExecutable": program_path,
|
|
"args": args,
|
|
"cwd": build_config.cwd.clone(),
|
|
"env": {
|
|
"VITEST_MIN_FORKS": "0",
|
|
"VITEST_MAX_FORKS": "1"
|
|
},
|
|
"runtimeArgs": ["--inspect-brk"],
|
|
"console": "integratedTerminal",
|
|
});
|
|
|
|
Some(DebugScenario {
|
|
adapter: adapter.0,
|
|
label: resolved_label.to_string().into(),
|
|
build: None,
|
|
config,
|
|
tcp_connection: None,
|
|
})
|
|
}
|
|
|
|
async fn run(&self, _: SpawnInTerminal) -> Result<DebugRequest> {
|
|
bail!("JavaScript locator should not require DapLocator::run to be ran");
|
|
}
|
|
}
|