debugger: Fix a few issues with JS debugging (#32918)

- Don't assume all located tasks come from our test runnables
- Run tests from the right working directory
- Scope forking behavior customization for jest and vitest more tightly,
to just our test runnables
- Standardize on `$PACKAGE_MANAGER exec -- $TEST_LIBRARY ...` to fix
runnables not working with npm

Release Notes:

- Debugger Beta: Fixed issues with debugging tasks from package.json and
test runnables.
This commit is contained in:
Cole Miller 2025-06-18 10:37:09 -04:00 committed by GitHub
parent 3e8a07f496
commit 2f52e2d285
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 48 additions and 45 deletions

View file

@ -164,28 +164,37 @@ impl PackageJsonData {
task_templates.0.push(TaskTemplate {
label: "jest file test".to_owned(),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec!["jest".to_owned(), VariableName::Filename.template_value()],
cwd: Some(VariableName::Dirname.template_value()),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"jest".to_owned(),
"--runInBand".to_owned(),
VariableName::File.template_value(),
],
cwd: Some(TYPESCRIPT_JEST_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
task_templates.0.push(TaskTemplate {
label: format!("jest test {}", VariableName::Symbol.template_value()),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"jest".to_owned(),
"--runInBand".to_owned(),
"--testNamePattern".to_owned(),
format!(
"\"{}\"",
TYPESCRIPT_JEST_TEST_NAME_VARIABLE.template_value()
),
VariableName::Filename.template_value(),
VariableName::File.template_value(),
],
tags: vec![
"ts-test".to_owned(),
"js-test".to_owned(),
"tsx-test".to_owned(),
],
cwd: Some(VariableName::Dirname.template_value()),
cwd: Some(TYPESCRIPT_JEST_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
}
@ -195,11 +204,15 @@ impl PackageJsonData {
label: format!("{} file test", "vitest".to_owned()),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"vitest".to_owned(),
"run".to_owned(),
VariableName::Filename.template_value(),
"--poolOptions.forks.minForks=0".to_owned(),
"--poolOptions.forks.maxForks=1".to_owned(),
VariableName::File.template_value(),
],
cwd: Some(VariableName::Dirname.template_value()),
cwd: Some(TYPESCRIPT_VITEST_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
task_templates.0.push(TaskTemplate {
@ -210,21 +223,25 @@ impl PackageJsonData {
),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"vitest".to_owned(),
"run".to_owned(),
"--poolOptions.forks.minForks=0".to_owned(),
"--poolOptions.forks.maxForks=1".to_owned(),
"--testNamePattern".to_owned(),
format!(
"\"{}\"",
TYPESCRIPT_VITEST_TEST_NAME_VARIABLE.template_value()
),
VariableName::Filename.template_value(),
VariableName::File.template_value(),
],
tags: vec![
"ts-test".to_owned(),
"js-test".to_owned(),
"tsx-test".to_owned(),
],
cwd: Some(VariableName::Dirname.template_value()),
cwd: Some(TYPESCRIPT_VITEST_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
}
@ -233,8 +250,13 @@ impl PackageJsonData {
task_templates.0.push(TaskTemplate {
label: format!("{} file test", "mocha".to_owned()),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec!["mocha".to_owned(), VariableName::Filename.template_value()],
cwd: Some(VariableName::Dirname.template_value()),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"mocha".to_owned(),
VariableName::File.template_value(),
],
cwd: Some(TYPESCRIPT_MOCHA_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
task_templates.0.push(TaskTemplate {
@ -245,17 +267,19 @@ impl PackageJsonData {
),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"mocha".to_owned(),
"--grep".to_owned(),
format!("\"{}\"", VariableName::Symbol.template_value()),
VariableName::Filename.template_value(),
VariableName::File.template_value(),
],
tags: vec![
"ts-test".to_owned(),
"js-test".to_owned(),
"tsx-test".to_owned(),
],
cwd: Some(VariableName::Dirname.template_value()),
cwd: Some(TYPESCRIPT_MOCHA_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
}
@ -265,10 +289,12 @@ impl PackageJsonData {
label: format!("{} file test", "jasmine".to_owned()),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"jasmine".to_owned(),
VariableName::Filename.template_value(),
VariableName::File.template_value(),
],
cwd: Some(VariableName::Dirname.template_value()),
cwd: Some(TYPESCRIPT_JASMINE_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
task_templates.0.push(TaskTemplate {
@ -279,17 +305,18 @@ impl PackageJsonData {
),
command: TYPESCRIPT_RUNNER_VARIABLE.template_value(),
args: vec![
"exec".to_owned(),
"--".to_owned(),
"jasmine".to_owned(),
format!("--filter={}", VariableName::Symbol.template_value()),
VariableName::Filename.template_value(),
VariableName::File.template_value(),
],
tags: vec![
"ts-test".to_owned(),
"js-test".to_owned(),
"tsx-test".to_owned(),
"jasmine-test".to_owned(),
],
cwd: Some(VariableName::Dirname.template_value()),
cwd: Some(TYPESCRIPT_JASMINE_PACKAGE_PATH_VARIABLE.template_value()),
..TaskTemplate::default()
});
}