David-Kunz / jester

A Neovim plugin to easily run and debug Jest tests
The Unlicense
202 stars 12 forks source link

The escaping characters in $file breaks the run command on MacOS #19

Closed fastndead closed 1 year ago

fastndead commented 2 years ago

The character escaping breaks the run command for me on MacOS. Escaping probably makes sense on Windows, but on MacOS it seems to be redundant and unneeded. I think it would be great to add a special option to not escape characters in cmd.

This is probably related to the #7 issue

David-Kunz commented 2 years ago

Hi @fastndead ,

Interesting, I'm also using macOS and it works for me. Can you provide an example test so I can check? I also like to know which shell and terminal you're using.

Thanks!

fastndead commented 2 years ago

Hey there @David-Kunz, thanks for the extremely quick response!

so, i don't think it's related to the test itself, rather I'd say it's related to the test file's name.

so in my case I'm trying to test the file with the path ~/Desktop/project/src/test/app.test.js my Jester setup looks like this:

 require("jester").setup({
  cmd = "jest --colors --verbose --testNamePattern=$result --runTestsByPath $file",
})

when I run the run command it resolves in following command:

jest --colors --verbose --testNamePattern=^App --runTestsByPath Users/<my username>/Desktop/project/src/test/app\\.
test\\.js

which ultimately resolves in following output:

Screenshot 2022-10-14 at 11 49 17

When I locally removed all the all the places where escaping occurs in the plugin code everything works as expected – the only difference is that it runs this command (no backslashes):

jest --colors --verbose --testNamePattern=^App --runTestsByPath Users/<my username>/Desktop/project/src/test/app.test.js

almost forgot to mention, that i use zshell and Alacritty terminal

fastndead commented 2 years ago

Actually I figured this out, I think the issue was in my jest cmd config, --runTestsByPath seems to not accept the path with escaped characters, but config that is default in the plugin does. So i just replaces --runTestsByPath $file with -- $file and it worked, might be a good idea still to add an option to not escape characters but definitely not a critical issue. My problem is resolved

David-Kunz commented 2 years ago

Awesome, thanks for the feedback @fastndead , glad it works!

Gauserr commented 1 year ago

Hi David,

I am also having this issue, exactly as described. Any test using a special character in the description is being skipped. If I remove the special character, the tests run as normal. I can run the entire file just find, but using the 'nearest test' commands won't work for the ones with special characters.

Any thoughts?

Gauserr commented 1 year ago

Hi David,

I am also having this issue, exactly as described. Any test using a special character in the description is being skipped. If I remove the special character, the tests run as normal. I can run the entire file just find, but using the 'nearest test' commands won't work for the ones with special characters.

Any thoughts?

Note: I'm using the default configuration

David-Kunz commented 1 year ago

Hi @Gauserr ,

Can you provide a simple example?

Thanks and best regards, David

Gauserr commented 1 year ago

Hi @Gauserr ,

Can you provide a simple example?

Thanks and best regards, David

Hi David,

Here's an example:

If I'm running this test

    describe('non-positive n', () => {
        it('should draw no star for n = 0', () => {
            drawStar(0);
            expect(logOutput).toBe(``);
        });

it does not work because of the hyphen in 'non-positive n'.

The Jest log reads

Ran all test suites matching /\/Users\/ryan\/dev\/codeSmith\/
ptri9\/hackHour\/hack\-hour\-ptri\-9\/__tests__\/draw\-stairs
\.js/i with tests matching "^drawStar test non\\-positive n".

and all tests within this 'describe' block are skipped.

If instead I remove the hyphen

    describe('non positive n', () => {
        it('should draw no star for n = 0', () => {
            drawStar(0);
            expect(logOutput).toBe(``);
        });

The tests run. They say I've passed rather than skipped. The log says

Ran all test suites matching /\/Users\/ryan\/dev\/codeSmith\/
ptri9\/hackHour\/hack\-hour\-ptri\-9\/__tests__\/draw\-stairs
\.js/i with tests matching "^drawStar test non positive n".

This occurs for any 'describe' block that is using a special character, including backslashes, commas, etc.

Hope my formatting was ok here. I'm haven't posted code in comments very often

Gauserr commented 1 year ago

Also, to add to this...

This issue only occurs when using the 'run' command, with my cursor on the 'describe' line. If I use the 'run file' command, the entire file executes as expected, including the tests with the special characters.

David-Kunz commented 1 year ago

Hi @Gauserr ,

Thanks for this example! I tried to reproduce it, but it works in my case. What's your environment (OS, terminal, shell)?