Skip to content

Commit b0f43f9

Browse files
committed
fix(formatter): test call difference (#15356)
Align this part with Prettier rather than Biome
1 parent 33ad374 commit b0f43f9

File tree

5 files changed

+83
-12
lines changed

5 files changed

+83
-12
lines changed

crates/oxc_formatter/src/utils/call_expression.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use crate::ast_nodes::{AstNode, AstNodes};
2424
/// [arrow function expression]: ArrowFunctionExpression
2525
/// [function expression]: Function
2626
pub fn is_test_call_expression(call: &AstNode<CallExpression<'_>>) -> bool {
27-
// TODO: This is not compatible with Biome, but compatible with Prettier.
2827
if call.optional {
2928
return false;
3029
}

crates/oxc_formatter/src/utils/member_chain/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ impl<'a> Format<'a> for MemberChain<'a, '_> {
214214
if self.tail.len() <= 1 && !has_comment && !has_new_line_or_comment_between {
215215
return if is_long_curried_call(self.root) {
216216
write!(f, [format_one_line])
217-
} else if is_test_call_expression(self.root) && self.head.members().len() >= 2 {
218-
write!(f, [self.head, soft_line_indent_or_space(&self.tail)])
219217
} else {
220218
write!(f, [group(&format_one_line)])
221219
};

crates/oxc_formatter/src/write/mod.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,14 @@ impl<'a> FormatWrite<'a> for AstNode<'a, CallExpression<'a>> {
223223
is_multiline_template_starting_on_same_line(expr, f.source_text())
224224
});
225225

226-
if !is_simple_module_import(self.arguments(), f.comments())
227-
&& !is_template_literal_single_arg
228-
&& callee.as_member_expression().is_some_and(|e| {
229-
matches!(
230-
e,
231-
MemberExpression::StaticMemberExpression(_)
232-
| MemberExpression::ComputedMemberExpression(_)
233-
)
234-
})
226+
if !is_template_literal_single_arg
227+
&& matches!(
228+
callee.as_ref(),
229+
Expression::StaticMemberExpression(_) | Expression::ComputedMemberExpression(_)
230+
)
235231
&& !callee.needs_parentheses(f)
232+
&& !is_simple_module_import(self.arguments(), f.comments())
233+
&& !is_test_call_expression(self)
236234
{
237235
MemberChain::from_call_expression(self, f).fmt(f)
238236
} else {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Test patterns with multiple levels should not break incorrectly
2+
test.describe.serial("My test suite", () => {
3+
// test content
4+
});
5+
6+
test.describe.serial("Import glossary from JSON", () => {
7+
// more test content
8+
});
9+
10+
test.describe.parallel("Another test suite", () => {
11+
// test content
12+
});
13+
14+
test.describe.serial.only("Test with only", () => {});
15+
16+
test.describe.parallel.only("Parallel only", () => {});
17+
18+
test.describe.only("Describe only", () => {});
19+
20+
// These simpler patterns should still work
21+
test.only("Test only", () => {});
22+
describe.only("Describe only", () => {});
23+
it.only("It only", () => {});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
// Test patterns with multiple levels should not break incorrectly
6+
test.describe.serial("My test suite", () => {
7+
// test content
8+
});
9+
10+
test.describe.serial("Import glossary from JSON", () => {
11+
// more test content
12+
});
13+
14+
test.describe.parallel("Another test suite", () => {
15+
// test content
16+
});
17+
18+
test.describe.serial.only("Test with only", () => {});
19+
20+
test.describe.parallel.only("Parallel only", () => {});
21+
22+
test.describe.only("Describe only", () => {});
23+
24+
// These simpler patterns should still work
25+
test.only("Test only", () => {});
26+
describe.only("Describe only", () => {});
27+
it.only("It only", () => {});
28+
==================== Output ====================
29+
// Test patterns with multiple levels should not break incorrectly
30+
test.describe.serial("My test suite", () => {
31+
// test content
32+
});
33+
34+
test.describe.serial("Import glossary from JSON", () => {
35+
// more test content
36+
});
37+
38+
test.describe.parallel("Another test suite", () => {
39+
// test content
40+
});
41+
42+
test.describe.serial.only("Test with only", () => {});
43+
44+
test.describe.parallel.only("Parallel only", () => {});
45+
46+
test.describe.only("Describe only", () => {});
47+
48+
// These simpler patterns should still work
49+
test.only("Test only", () => {});
50+
describe.only("Describe only", () => {});
51+
it.only("It only", () => {});
52+
53+
===================== End =====================

0 commit comments

Comments
 (0)