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

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

Open
pierrecholhot opened this issue Jul 26, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@pierrecholhot
Copy link

pierrecholhot commented Jul 26, 2023

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

@pierrecholhot pierrecholhot added bug Something isn't working triage Pending to be triaged by a maintainer labels Jul 26, 2023
@pierrecholhot pierrecholhot changed the title consistent-data-testid > wrong {filename} on windows consistent-data-testid: Wrong {fileName} value in testIdPattern on Windows Jul 26, 2023
@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants