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

Change Request: Rule Tester omit specific properties for duplicate test case detection #18173

Closed
1 task done
DMartens opened this issue Mar 6, 2024 · 2 comments · Fixed by #18235
Closed
1 task done
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint

Comments

@DMartens
Copy link
Contributor

DMartens commented Mar 6, 2024

ESLint version

8.57.0

What problem do you want to solve?

The RuleTester currently stringifies all test case properties for each test case to check for duplicate test cases (see here).
This means some duplicate test cases are not discovered.
Test cases with different names:

ruleTester.run('rule', rule, {
	valid: [
		{ code: 'code' },
		{ name: 'name', code: 'code' },
	],
	invalid: [],
}),

Test cases with a different error matcher:

ruleTester.run('rule', rule, {
	valid: [],
	invalid: [	
		{ code: 'code', errors: 1 },
		{ code: 'code', errors: [{ messageId: 'id' }] },
	],
}

Not fixable test cases one specifying output and the other not:

ruleTester.run('rule', rule, {
	valid: [],
	invalid: [	
		{ code: 'code', errors: 1, output: null },
		{ code: 'code', errors: 1 },
	],
}

What do you think is the correct solution?

The used serialize package offers a replacer method which could exclude the properties name, errors and output.
The other Rule Tester specific property is only but I do not think that developers want to be warned about duplicate test cases when focusing on a test case.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

No response

@DMartens DMartens added core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint labels Mar 6, 2024
@nzakas
Copy link
Member

nzakas commented Mar 6, 2024

Ah, good catch! This seems like a bug to me. The goal of duplicate test detection is to make sure you're not running the rule on the same code using the same options multiple times, and we're clearly not doing that. Marking as accepted.

@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label Mar 6, 2024
@bmish
Copy link
Sponsor Member

bmish commented Mar 8, 2024

Makes sense to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants