Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

consistent-data-testid: Wrong {fileName} value in testIdPattern on Windows #782

Copy link
Copy link
Open
@pierrecholhot

Description

@pierrecholhot
Issue body actions

Have you read the Troubleshooting section?

Yes

Plugin version

v5.11.0

ESLint version

v8.35.0

Node.js version

v16.20.1

package manager and version

v8.19.4

Operating system

Windows 11

Bug description

Context

In the plugin consistent-data-testid we are able to use the following placeholder {fileName} inside the testIdPattern so that the test ids include the file name.

Issue

On Windows 11, the value of the fileName is wrong as it contains the full path to the file.

Example value

Example of the wrong file name:

C:\workspace\projectX\src\components\Link\Link

Expected value

Expected file name:

Link

Possible cause

This might be due to the way the fileName is parsed by the plugin.

const splitPath = getFilename().split('/');

When I test with the following on Windows, it works:

const splitPath = getFilename().split('\\');

Steps to reproduce

See bug description

Error output/screenshots

No response

ESLint configuration

{
  "root": true,
  "env": {
    "browser": true,
    "node": true
  },
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "parser": "@typescript-eslint/parser",
  "plugins": ["prettier", "@typescript-eslint", "react"],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:react/recommended",
    "plugin:react-hooks/recommended",
    "plugin:prettier/recommended",
    "plugin:testing-library/react",
    "plugin:jest-dom/recommended"
  ],
  "settings": {
    "react": { "version": "detect" }
  },
  "rules": {
    "testing-library/consistent-data-testid": [
      "error",
      {
        "testIdAttribute": "data-testid",
        "testIdPattern": "^{fileName}__([A-Z]+[a-z])+$", /* <--- fileName here */
      }
    ]
  }
}

Rule(s) affected

testing-library/consistent-data-testid

Anything else?

No response

Do you want to submit a pull request to fix this bug?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.