diff --git a/src/rules/consistent-data-testid.ts b/src/rules/consistent-data-testid.ts index 50f90e44..89a0e1ad 100644 --- a/src/rules/consistent-data-testid.ts +++ b/src/rules/consistent-data-testid.ts @@ -15,6 +15,7 @@ export type Options = [ ]; const FILENAME_PLACEHOLDER = '{fileName}'; +const PATH_SEPARATOR_PATTERN = /[/\\]/u; export default createTestingLibraryRule({ name: RULE_NAME, @@ -82,7 +83,7 @@ export default createTestingLibraryRule({ const { testIdPattern, testIdAttribute: attr, customMessage } = options; function getFileNameData() { - const splitPath = getFilename(context).split('/'); + const splitPath = getFilename(context).split(PATH_SEPARATOR_PATTERN); const fileNameWithExtension = splitPath.pop() ?? ''; if ( fileNameWithExtension.includes('[') || diff --git a/tests/rules/consistent-data-testid.test.ts b/tests/rules/consistent-data-testid.test.ts index 2e3e2c24..9d64fa3b 100644 --- a/tests/rules/consistent-data-testid.test.ts +++ b/tests/rules/consistent-data-testid.test.ts @@ -77,6 +77,25 @@ const validTestCases: RuleValidTestCase[] = [ code: ` import React from 'react'; + const TestComponent = props => { + return ( +
+ Hello +
+ ) + }; + `, + options: [ + { + testIdPattern: '^{fileName}__([A-Z]+[a-z]*?)+$', + }, + ], + filename: 'C:\\workspace\\projectX\\src\\components\\Link\\Link.tsx', + }, + { + code: ` + import React from 'react'; + const TestComponent = props => { return (