@@ -4565,6 +4565,79 @@ describe("RuleTester", () => {
45654565 } , "detected duplicate test case" ) ;
45664566 } ) ;
45674567
4568+ it ( "throws with duplicate object test cases when they are the same object" , ( ) => {
4569+ const test = { code : "foo" } ;
4570+ assert . throws ( ( ) => {
4571+ ruleTester . run (
4572+ "foo" ,
4573+ {
4574+ meta : { } ,
4575+ create ( ) {
4576+ return { } ;
4577+ } ,
4578+ } ,
4579+ {
4580+ valid : [ test , test ] ,
4581+ invalid : [ ] ,
4582+ } ,
4583+ ) ;
4584+ } , "detected duplicate test case" ) ;
4585+ } ) ;
4586+
4587+ it ( "throws with duplicate object test cases that have multiple references to the same object" , ( ) => {
4588+ const obj1 = { foo : { bar : "baz" } } ;
4589+ const obj2 = { foo : { bar : "baz" } } ;
4590+
4591+ assert . throws ( ( ) => {
4592+ ruleTester . run (
4593+ "foo" ,
4594+ {
4595+ meta : { } ,
4596+ create ( ) {
4597+ return { } ;
4598+ } ,
4599+ } ,
4600+ {
4601+ valid : [
4602+ {
4603+ code : "foo" ,
4604+ settings : { qux : obj1 , quux : obj1 } ,
4605+ } ,
4606+ {
4607+ code : "foo" ,
4608+ settings : { qux : obj2 , quux : obj2 } ,
4609+ } ,
4610+ ] ,
4611+ invalid : [ ] ,
4612+ } ,
4613+ ) ;
4614+ } , "detected duplicate test case" ) ;
4615+ } ) ;
4616+
4617+ it ( "does not throw with duplicate object test cases that have circular references" , ( ) => {
4618+ const obj1 = { foo : "bar" } ;
4619+ obj1 . circular = obj1 ;
4620+ const obj2 = { foo : "bar" } ;
4621+ obj2 . circular = obj2 ;
4622+
4623+ ruleTester . run (
4624+ "foo" ,
4625+ {
4626+ meta : { } ,
4627+ create ( ) {
4628+ return { } ;
4629+ } ,
4630+ } ,
4631+ {
4632+ valid : [
4633+ { code : "foo" , settings : { baz : obj1 } } ,
4634+ { code : "foo" , settings : { baz : obj2 } } ,
4635+ ] ,
4636+ invalid : [ ] ,
4637+ } ,
4638+ ) ;
4639+ } ) ;
4640+
45684641 it ( "throws with string and object test cases" , ( ) => {
45694642 assert . throws ( ( ) => {
45704643 ruleTester . run (
@@ -4683,6 +4756,105 @@ describe("RuleTester", () => {
46834756 } , "detected duplicate test case" ) ;
46844757 } ) ;
46854758
4759+ it ( "throws with duplicate object test cases when they are the same object" , ( ) => {
4760+ const test = {
4761+ code : "const x = 123;" ,
4762+ errors : [ { message : "foo bar" } ] ,
4763+ } ;
4764+
4765+ assert . throws ( ( ) => {
4766+ ruleTester . run (
4767+ "foo" ,
4768+ {
4769+ meta : { } ,
4770+ create ( context ) {
4771+ return {
4772+ VariableDeclaration ( node ) {
4773+ context . report ( node , "foo bar" ) ;
4774+ } ,
4775+ } ;
4776+ } ,
4777+ } ,
4778+ {
4779+ valid : [ "foo" ] ,
4780+ invalid : [ test , test ] ,
4781+ } ,
4782+ ) ;
4783+ } , "detected duplicate test case" ) ;
4784+ } ) ;
4785+
4786+ it ( "throws with duplicate object test cases that have multiple references to the same object" , ( ) => {
4787+ const obj1 = { foo : { bar : "baz" } } ;
4788+ const obj2 = { foo : { bar : "baz" } } ;
4789+
4790+ assert . throws ( ( ) => {
4791+ ruleTester . run (
4792+ "foo" ,
4793+ {
4794+ meta : { } ,
4795+ create ( context ) {
4796+ return {
4797+ VariableDeclaration ( node ) {
4798+ context . report ( node , "foo bar" ) ;
4799+ } ,
4800+ } ;
4801+ } ,
4802+ } ,
4803+ {
4804+ valid : [ "foo" ] ,
4805+ invalid : [
4806+ {
4807+ code : "const x = 123;" ,
4808+ settings : { qux : obj1 , quux : obj1 } ,
4809+ errors : [ { message : "foo bar" } ] ,
4810+ } ,
4811+ {
4812+ code : "const x = 123;" ,
4813+ settings : { qux : obj2 , quux : obj2 } ,
4814+ errors : [ { message : "foo bar" } ] ,
4815+ } ,
4816+ ] ,
4817+ } ,
4818+ ) ;
4819+ } , "detected duplicate test case" ) ;
4820+ } ) ;
4821+
4822+ it ( "does not throw with duplicate object test cases that have circular references" , ( ) => {
4823+ const obj1 = { foo : "bar" } ;
4824+ obj1 . circular = obj1 ;
4825+ const obj2 = { foo : "bar" } ;
4826+ obj2 . circular = obj2 ;
4827+
4828+ ruleTester . run (
4829+ "foo" ,
4830+ {
4831+ meta : { } ,
4832+ create ( context ) {
4833+ return {
4834+ VariableDeclaration ( node ) {
4835+ context . report ( node , "foo bar" ) ;
4836+ } ,
4837+ } ;
4838+ } ,
4839+ } ,
4840+ {
4841+ valid : [ "foo" ] ,
4842+ invalid : [
4843+ {
4844+ code : "const x = 123;" ,
4845+ settings : { baz : obj1 } ,
4846+ errors : [ { message : "foo bar" } ] ,
4847+ } ,
4848+ {
4849+ code : "const x = 123;" ,
4850+ settings : { baz : obj2 } ,
4851+ errors : [ { message : "foo bar" } ] ,
4852+ } ,
4853+ ] ,
4854+ } ,
4855+ ) ;
4856+ } ) ;
4857+
46864858 it ( "throws with duplicate object test cases when options is a primitive" , ( ) => {
46874859 assert . throws ( ( ) => {
46884860 ruleTester . run (
0 commit comments