Skip to content

Commit e306958

Browse files
committed
fix(formatter): regression case for test call (#15760)
I found this mismatch case in the oxc-ecosystem-ci. This is a regression that was introduced in #15238. In that PR, I mistakenly removed some checks related to test declaration.
1 parent c42d983 commit e306958

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

crates/oxc_formatter/src/write/call_arguments.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,17 @@ impl<'a> Format<'a> for AstNode<'a, ArenaVec<'a, Argument<'a>>> {
6969

7070
if is_simple_module_import
7171
|| call_expression.is_some_and(|call| {
72-
is_commonjs_or_amd_call(self, call, f) || is_test_call_expression(call)
72+
is_commonjs_or_amd_call(self, call, f)
73+
|| ((self.len() != 2
74+
|| matches!(
75+
arguments.first(),
76+
Some(
77+
Argument::StringLiteral(_)
78+
| Argument::TemplateLiteral(_)
79+
| Argument::TaggedTemplateExpression(_)
80+
)
81+
))
82+
&& is_test_call_expression(call))
7383
})
7484
|| is_multiline_template_only_args(self, f.source_text())
7585
|| is_react_hook_with_deps_array(self, f.comments())

crates/oxc_formatter/tests/fixtures/js/calls/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ test.describe.only("Describe only", () => {});
2020
// These simpler patterns should still work
2121
test.only("Test only", () => {});
2222
describe.only("Describe only", () => {});
23-
it.only("It only", () => {});
23+
it.only("It only", () => {});
24+
25+
test(code.replace((c) => ""), () => {});

crates/oxc_formatter/tests/fixtures/js/calls/test.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ test.describe.only("Describe only", () => {});
2525
test.only("Test only", () => {});
2626
describe.only("Describe only", () => {});
2727
it.only("It only", () => {});
28+
29+
test(code.replace((c) => ""), () => {});
2830
==================== Output ====================
2931
// Test patterns with multiple levels should not break incorrectly
3032
test.describe.serial("My test suite", () => {
@@ -50,4 +52,9 @@ test.only("Test only", () => {});
5052
describe.only("Describe only", () => {});
5153
it.only("It only", () => {});
5254

55+
test(
56+
code.replace((c) => ""),
57+
() => {},
58+
);
59+
5360
===================== End =====================

0 commit comments

Comments
 (0)