Skip to content

Commit

Permalink
fix(noFocusedTests): checking test call expressions (#3793)
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Sep 5, 2024
1 parent be6c6b5 commit d754371
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

- Allow `aria-label` on heading to prevent `useHeadingContent` diagnostic ([#3767](https://github.com/biomejs/biome/pull/3767)). Contributed by @anthonyshew

- Fix edge case [#3791](https://github.com/biomejs/biome/issues/3791) for rule `noFocusedTests` being used with non-string-like expressions ([#3793](https://github.com/biomejs/biome/pull/3793)). Contributed by @h-a-n-a

### Configuration

- Add support for loading configuration from `.editorconfig` files ([#1724](https://github.com/biomejs/biome/issues/1724)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@ test["only"]("bar", function () {});

fdescribe("foo", () => {});
fit("foo", () => {});

describe.only(bar, () => {});
it.only(bar, () => {});
test.only(bar, () => {});

describe.only(foo.bar, () => {});
it.only(foo.bar, () => {});
test.only(foo.bar, () => {});

describe.only(name = name || "bar", () => {});
it.only(name = name || "bar", () => {});
test.only(name = name || "bar", () => {});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ test["only"]("bar", function () {});
fdescribe("foo", () => {});
fit("foo", () => {});

describe.only(bar, () => {});
it.only(bar, () => {});
test.only(bar, () => {});

describe.only(foo.bar, () => {});
it.only(foo.bar, () => {});
test.only(foo.bar, () => {});

describe.only(name = name || "bar", () => {});
it.only(name = name || "bar", () => {});
test.only(name = name || "bar", () => {});

```

# Diagnostics
Expand Down Expand Up @@ -261,6 +273,7 @@ invalid.js:14:1 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━
> 14 │ fit("foo", () => {});
│ ^^^
15 │
16 │ describe.only(bar, () => {});
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Expand All @@ -273,6 +286,210 @@ invalid.js:14:1 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━
14 │ - fit("foo",·()·=>·{});
14 │ + it("foo",·()·=>·{});
15 15 │
16 16 │ describe.only(bar, () => {});
```

```
invalid.js:16:10 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
14 │ fit("foo", () => {});
15 │
> 16 │ describe.only(bar, () => {});
│ ^^^^
17 │ it.only(bar, () => {});
18 │ test.only(bar, () => {});
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
16 │ describe.only(bar,·()·=>·{});
│ -----
```

```
invalid.js:17:4 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
16 │ describe.only(bar, () => {});
> 17 │ it.only(bar, () => {});
│ ^^^^
18 │ test.only(bar, () => {});
19 │
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
17 │ it.only(bar,·()·=>·{});
│ -----
```

```
invalid.js:18:6 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
16 │ describe.only(bar, () => {});
17 │ it.only(bar, () => {});
> 18 │ test.only(bar, () => {});
│ ^^^^
19 │
20 │ describe.only(foo.bar, () => {});
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
18 │ test.only(bar,·()·=>·{});
│ -----
```

```
invalid.js:20:10 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
18 │ test.only(bar, () => {});
19 │
> 20 │ describe.only(foo.bar, () => {});
│ ^^^^
21 │ it.only(foo.bar, () => {});
22 │ test.only(foo.bar, () => {});
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
20 │ describe.only(foo.bar,·()·=>·{});
│ -----
```

```
invalid.js:21:4 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
20 │ describe.only(foo.bar, () => {});
> 21 │ it.only(foo.bar, () => {});
│ ^^^^
22 │ test.only(foo.bar, () => {});
23 │
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
21 │ it.only(foo.bar,·()·=>·{});
│ -----
```

```
invalid.js:22:6 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
20 │ describe.only(foo.bar, () => {});
21 │ it.only(foo.bar, () => {});
> 22 │ test.only(foo.bar, () => {});
│ ^^^^
23 │
24 │ describe.only(name = name || "bar", () => {});
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
22 │ test.only(foo.bar,·()·=>·{});
│ -----
```

```
invalid.js:24:10 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
22 │ test.only(foo.bar, () => {});
23 │
> 24 │ describe.only(name = name || "bar", () => {});
│ ^^^^
25 │ it.only(name = name || "bar", () => {});
26 │ test.only(name = name || "bar", () => {});
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
24 │ describe.only(name·=·name·||·"bar",·()·=>·{});
│ -----
```

```
invalid.js:25:4 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
24 │ describe.only(name = name || "bar", () => {});
> 25 │ it.only(name = name || "bar", () => {});
│ ^^^^
26 │ test.only(name = name || "bar", () => {});
27 │
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
25 │ it.only(name·=·name·||·"bar",·()·=>·{});
│ -----
```

```
invalid.js:26:6 lint/suspicious/noFocusedTests FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Don't focus the test.
24 │ describe.only(name = name || "bar", () => {});
25 │ it.only(name = name || "bar", () => {});
> 26 │ test.only(name = name || "bar", () => {});
│ ^^^^
27 │
i The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
i Consider removing 'only' to ensure all tests are executed.
i Unsafe fix: Remove focus from test.
26 │ test.only(name·=·name·||·"bar",·()·=>·{});
│ -----
```
37 changes: 27 additions & 10 deletions crates/biome_js_syntax/src/expr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,16 +1814,10 @@ impl JsCallExpression {
}

// it("description", ..)
(
Some(Ok(AnyJsCallArgument::AnyJsExpression(
JsTemplateExpression(_)
| AnyJsLiteralExpression(
self::AnyJsLiteralExpression::JsStringLiteralExpression(_),
),
))),
Some(Ok(second)),
third,
) if arguments.args().len() <= 3 && callee.contains_a_test_pattern()? => {
// it(Test.name, ..)
(Some(Ok(AnyJsCallArgument::AnyJsExpression(_))), Some(Ok(second)), third)
if arguments.args().len() <= 3 && callee.contains_a_test_pattern()? =>
{
// it('name', callback, duration)
if !matches!(
third,
Expand Down Expand Up @@ -2067,6 +2061,29 @@ mod test {
);
}

#[test]
fn matches_test_call_expression() {
let call_expression = extract_call_expression("test.only(name, () => {});");
assert_eq!(call_expression.is_test_call_expression(), Ok(true));

let call_expression = extract_call_expression("test.only(Test.name, () => {});");
assert_eq!(call_expression.is_test_call_expression(), Ok(true));

let call_expression =
extract_call_expression("test.only(name = name || 'test', () => {});");
assert_eq!(call_expression.is_test_call_expression(), Ok(true));

let call_expression = extract_call_expression("describe.only(name, () => {});");
assert_eq!(call_expression.is_test_call_expression(), Ok(true));

let call_expression = extract_call_expression("describe.only(Test.name, () => {});");
assert_eq!(call_expression.is_test_call_expression(), Ok(true));

let call_expression =
extract_call_expression("describe.only(name = name || 'test', () => {});");
assert_eq!(call_expression.is_test_call_expression(), Ok(true));
}

#[test]
fn matches_simple_each() {
let template = extract_template("describe.each``");
Expand Down

0 comments on commit d754371

Please sign in to comment.