neotest-jest icon indicating copy to clipboard operation
neotest-jest copied to clipboard

The extra `'` in `testNamePattern` causes my tests to be ignored

Open mikaoelitiana opened this issue 1 year ago • 2 comments

https://github.com/nvim-neotest/neotest-jest/blob/e60280f53ef9f84fd827aecae1e2f732ba4326b1/lua/neotest-jest/init.lua#L359-L365

I have set a custom jestCommand in my adapter configuration, something specific to my project like yarn run custom-script .... Now when I one single test, the test name pattern in the output is not correct, it has extra ' like this :

 '--testNamePattern='\''^Class someMethod should return something$'\'

If I directly run this command in the shell, no test is matching. But if I remove the extra ', it runs as expected.

'--testNamePattern=^Class someMethod should return something$'

I have locally updated the plugin as so and it works fine now:

local testNamePattern = ".*"

  if pos.type == "test" or pos.type == "namespace" then
    -- pos.id in form "path/to/file::Describe text::test text"
    local testName = string.sub(pos.id, string.find(pos.id, "::") + 2)
    testName, _ = string.gsub(testName, "::", " ")
    testNamePattern = "^" .. escapeTestPattern(testName)
    if pos.type == "test" then
      testNamePattern = testNamePattern .. "$"
    else
      testNamePattern = testNamePattern .. "'"
    end
  end

Do you think it could break things if the ' is completely removed?

mikaoelitiana avatar Aug 03 '23 08:08 mikaoelitiana

I've created a PR that includes this fix. Again, not sure if this is the fix but it helps me to run the tests for now. Thanks for the suggestion and saving debugging time @mikaoelitiana :)

JaapBarnhoorn avatar Aug 30 '23 13:08 JaapBarnhoorn

Thanks @JaapBarnhoorn 🙏🏽. @haydenmeade wdyt?

mikaoelitiana avatar Aug 31 '23 07:08 mikaoelitiana