From d7f4298015bd98ba5806ec48ee35e4be61a4143e Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Fri, 16 Dec 2022 14:53:30 +0100 Subject: [PATCH] fix(lsp): handle template literal as first arg in test function (#17076) --- cli/lsp/testing/collectors.rs | 113 ++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 26 deletions(-) diff --git a/cli/lsp/testing/collectors.rs b/cli/lsp/testing/collectors.rs index d338ac0888..4f511937cb 100644 --- a/cli/lsp/testing/collectors.rs +++ b/cli/lsp/testing/collectors.rs @@ -153,9 +153,7 @@ fn check_call_expr( // (e.g. `test name`) ast::Expr::Tpl(tpl) => { if tpl.quasis.len() == 1 { - if let Some(tpl_element) = tpl.quasis.get(0) { - maybe_name = Some(tpl_element.raw.to_string()); - } + maybe_name = Some(tpl.quasis[0].raw.to_string()); } } _ => (), @@ -205,6 +203,24 @@ fn check_call_expr( } Some((name, steps)) } + ast::Expr::Tpl(tpl) => { + if tpl.quasis.len() == 1 { + let mut steps = vec![]; + match node.args.get(1).map(|es| es.expr.as_ref()) { + Some(ast::Expr::Fn(fn_expr)) => { + steps = fn_to_steps(parent, level, &fn_expr.function); + } + Some(ast::Expr::Arrow(arrow_expr)) => { + steps = arrow_to_steps(parent, level, arrow_expr); + } + _ => (), + } + + Some((tpl.quasis[0].raw.to_string(), steps)) + } else { + None + } + } _ => None, } } else { @@ -511,17 +527,31 @@ pub mod tests { } }); + Deno.test({ + name: `test b`, + async fn(t) { + await t.step(`b step`, ({ step }) => { + await step({ + name: `sub step`, + fn() {} + }) + }); + } + }); + Deno.test(async function useFnName({ step: s }) { await s("step c", () => {}); }); - Deno.test("test b", () => {}); + Deno.test("test c", () => {}); + + Deno.test(`test d`, () => {}); const { test } = Deno; - test("test c", () => {}); + test("test e", () => {}); const t = Deno.test; - t("test d", () => {}); + t("test f", () => {}); "#; let parsed_module = deno_ast::parse_module(deno_ast::ParseParams { @@ -561,42 +591,73 @@ pub mod tests { } ], }, - TestDefinition { - id: "86b4c821900e38fc89f24bceb0e45193608ab3f9d2a6019c7b6a5aceff5d7df2".to_string(), - level: 0, - name: "useFnName".to_string(), - range: new_range(254, 258), - steps: vec![ - TestDefinition { - id: "67a390d0084ae5fb88f3510c470a72a553581f1d0d5ba5fa89aee7a754f3953a".to_string(), - level: 1, - name: "step c".to_string(), - range: new_range(313, 314), - steps: vec![], - } - ] - }, TestDefinition { id: "580eda89d7f5e619774c20e13b7d07a8e77c39cba101d60565144d48faa837cb".to_string(), level: 0, name: "test b".to_string(), - range: new_range(358, 362), - steps: vec![], + range: new_range(254, 258), + steps: vec![ + TestDefinition { + id: "888e28419fc6c00cadfaad26e1e3e16e09e4322b3579fdfa9cc3fdb75976704a".to_string(), + level: 1, + name: "b step".to_string(), + range: new_range(325, 329), + steps: vec![ + TestDefinition { + id: "abf356f59139b77574089615f896a6f501c010985d95b8a93abeb0069ccb2201".to_string(), + level: 2, + name: "sub step".to_string(), + range: new_range(374, 378), + steps: vec![], + } + ] + } + ], + }, + TestDefinition { + id: "86b4c821900e38fc89f24bceb0e45193608ab3f9d2a6019c7b6a5aceff5d7df2".to_string(), + level: 0, + name: "useFnName".to_string(), + range: new_range(496, 500), + steps: vec![ + TestDefinition { + id: + "67a390d0084ae5fb88f3510c470a72a553581f1d0d5ba5fa89aee7a754f3953a".to_string(), + level: 1, + name: "step c".to_string(), + range: new_range(555, 556), + steps: vec![], + } + ], }, TestDefinition { id: "0b7c6bf3cd617018d33a1bf982a08fe088c5bb54fcd5eb9e802e7c137ec1af94".to_string(), level: 0, name: "test c".to_string(), - range: new_range(420, 424), + range: new_range(600, 604), steps: vec![], }, TestDefinition { id: "69d9fe87f64f5b66cb8b631d4fd2064e8224b8715a049be54276c42189ff8f9f".to_string(), level: 0, name: "test d".to_string(), - range: new_range(480, 481), + range: new_range(638, 642), steps: vec![], - } + }, + TestDefinition { + id: "b2fd155c2a5e468eddf77a5eb13f97ddeeeafab322f0fc223ec0810ab2a29d42".to_string(), + level: 0, + name: "test e".to_string(), + range: new_range(700, 704), + steps: vec![], + }, + TestDefinition { + id: "6387faad3a1f27fb3078a7d350040f4e6b516994076c855a0446943927461f58".to_string(), + level: 0, + name: "test f".to_string(), + range: new_range(760, 761), + steps: vec![], + }, ] ); }