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

JS/TS default rules #8

Open
elado opened this issue Mar 28, 2018 · 4 comments
Open

JS/TS default rules #8

elado opened this issue Mar 28, 2018 · 4 comments
Labels
feature New feature or request triage Needs to be looked at

Comments

@elado
Copy link

elado commented Mar 28, 2018

this is what I use:

    "findrelated.applyRulesets": [
        "js"
    ],
    "findrelated.rulesets": [
        {
            "name": "js",
            "rules": [
                {
                    "pattern": "(.+)\/([^\/]+?)\\.([tj]sx?)$",
                    "locators": [
                        "$1\/{tests,__tests__,__test__}/$2.spec.$3"
                    ]
                },
                {
                    "pattern": "(.+)\/(?:tests|__tests__|__test__)\/([^\/]+?)\\.spec\\.([tj]sx?)$",
                    "locators": [
                        "$1\/$2.$3"
                    ]
                }
            ]
        }
    ],

works for my projects, can probably be improved, but a good start.

@eamodio
Copy link
Owner

eamodio commented Apr 22, 2018

@elado why the tests,__tests__,__test__ to handle differently named test folders?

@eamodio eamodio added the needs-more-info Needs further information, steps, details, etc. label Apr 22, 2018
@forivall
Copy link

yeah, they cover different common patterns for the defaults used by javascript test runners (i typically use ava and jest).

I modified the rules to:

"rules": [
      {
        "pattern": "(.+)\/([^\/]+?)\\.([tj]sx?)$",
        "locators": [
          "$1/{test,tests,__tests__,__test__}/$2{.spec,.test,}.$3"
        ]
      },
      {
        "pattern": "src/(.+)\/([^\/]+?)\\.([tj]sx?)$",
        "locators": [
          "src/$1/{test,tests,__tests__,__test__}/$2{.spec,.test,}.$3",
          "{test,tests,__tests__,__test__}/$1/$2{.spec,.test,}.$3",
        ]
      },
      {
        "pattern": "(.+)\/(?:tests?|__tests?__)\/((?:.+?/)?(?:[^\/]+?))(?:\\.spec|\\.test)?\\.([tj]sx?)$",
        "locators": [
          "$1/$2.$3",
          "src/$1/$2.$3"
        ]
      },
      {
        "pattern": "(?:tests?|__tests?__)\/((?:.+?/)?(?:[^\/]+?))(?:\\.spec|\\.test)?\\.([tj]sx?)$",
        "locators": [
          "$1.$2",
          "src/$1.$2"
        ]
      }
    ]

@diminutivesloop
Copy link

This new ruleset should also handle the common pattern of including spec files in the same directory as the code under test. This is pattern is widely followed in the Angular community (see here for an example).

I'm using the following ruleset for javascript files in my Angular projects:

{
  "name": "javascript",
  "rules": [
    {
      "pattern": "(.*)\\.spec\\.([tj]sx?)$",
      "locators": [
        "$1.$2",
      ]
    },
    {
      "pattern": "(.*)\\.([tj]sx?)$",
      "locators": [
        "$1.spec.$2",
      ]
    }
  ]
}

Also I'm no regex wizard but the patterns mentioned before look like they might be more complicated than they need to be.

@github-actions
Copy link

github-actions bot commented Apr 9, 2023

This issue needs more information and has not had recent activity. Please provide the missing information or it will be closed in 7 days. Thanks!

@eamodio eamodio added feature New feature or request triage Needs to be looked at and removed needs-more-info Needs further information, steps, details, etc. inactive labels Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request triage Needs to be looked at
Projects
None yet
Development

No branches or pull requests

4 participants