Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(linter): add more Vitest compatible Jest rules #8445

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 84 additions & 2 deletions crates/oxc_linter/src/rules/jest/max_expects.rs
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ impl MaxExpects {
fn test() {
use crate::tester::Tester;

let pass = vec![
let mut pass = vec![
("test('should pass')", None),
("test('should pass', () => {})", None),
("test.skip('should pass', () => {})", None),
@@ -358,7 +358,7 @@ fn test() {
),
];

let fail = vec![
let mut fail = vec![
(
"
test('should not pass', function () {
@@ -471,6 +471,88 @@ fn test() {
),
];

let pass_vitest = vec![
("test('should pass')", None),
("test('should pass', () => {})", None),
("test.skip('should pass', () => {})", None),
(
"test('should pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});",
None,
),
(
"test('should pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});",
None,
),
(
" test('should pass', async () => {
expect.hasAssertions();

expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toEqual(expect.any(Boolean));
});",
None,
),
];

let fail_vitest = vec![
(
"test('should not pass', function () {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
",
None,
),
(
"test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});
test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
expect(true).toBeDefined();
});",
None,
),
(
"test('should not pass', () => {
expect(true).toBeDefined();
expect(true).toBeDefined();
});",
Some(serde_json::json!([{ "max": 1 }])),
),
];

pass.extend(pass_vitest);
fail.extend(fail_vitest);

Tester::new(MaxExpects::NAME, MaxExpects::PLUGIN, pass, fail)
.with_jest_plugin(true)
.test_and_snapshot();
89 changes: 87 additions & 2 deletions crates/oxc_linter/src/rules/jest/max_nested_describe.rs
Original file line number Diff line number Diff line change
@@ -181,7 +181,7 @@ impl MaxNestedDescribe {
fn test() {
use crate::tester::Tester;

let pass = vec![
let mut pass = vec![
(
"
describe('foo', function() {
@@ -287,7 +287,7 @@ fn test() {
),
];

let fail = vec![
let mut fail = vec![
(
"
describe('foo', function() {
@@ -397,6 +397,91 @@ fn test() {
),
];

let pass_vitest = vec![
(
"
describe('another suite', () => {
describe('another suite', () => {
it('skipped test', () => {
// Test skipped, as tests are running in Only mode
assert.equal(Math.sqrt(4), 3)
})

it.only('test', () => {
// Only this test (and others marked with only) are run
assert.equal(Math.sqrt(4), 2)
})
})
})
",
None,
),
(
"
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {

})
})
})
})
",
None,
),
];

let fail_vitest = vec![
(
"
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {

})
})
})
})
})
})
",
None,
),
(
"
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
describe('another suite', () => {
it('skipped test', () => {
// Test skipped, as tests are running in Only mode
assert.equal(Math.sqrt(4), 3)
})

it.only('test', () => {
// Only this test (and others marked with only) are run
assert.equal(Math.sqrt(4), 2)
})
})
})
})
})
})
})
",
None,
),
];

pass.extend(pass_vitest);
fail.extend(fail_vitest);

Tester::new(MaxNestedDescribe::NAME, MaxNestedDescribe::PLUGIN, pass, fail)
.with_jest_plugin(true)
.test_and_snapshot();
Loading
Loading