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

Doesn't work with test.each #55

Closed
zyy7259 opened this issue Dec 30, 2019 · 12 comments
Closed

Doesn't work with test.each #55

zyy7259 opened this issue Dec 30, 2019 · 12 comments
Labels

Comments

@zyy7259
Copy link

zyy7259 commented Dec 30, 2019

Right clicking in the body of a test.each and selecting Run Jest doesn't trigger jest.

@firsttris firsttris added the bug label Jan 3, 2020
@firsttris
Copy link
Owner

hey @zyy7259, i did not consinder this case, will provide support with the next version.
thx for your issue.

@firsttris
Copy link
Owner

firsttris commented Jan 21, 2020

hey @zyy7259

the issue is that with
jest-editor-support (https://github.com/jest-community/jest-editor-support)
the jest test parser for vscode addons its not possible to get the name of a test.each element.

BUT

if you highlight/select the name of the test and right-click - it will not use the parser instead what you actually have seleced.
(some kind of fallback logic)

image

@firsttris
Copy link
Owner

created an issue in jest-editor-support

@PizzaPartyInc
Copy link

Hi!
First, Thanks for the great Extension!

I wanted to add that even if related bugs are fixed, I'm having some doubts that it will be possible to fully fix this. The case which would probably not be possible to cover is when placeholders are used in the title of the test, e.g.

it.each([
    [1, 1, 2],
    [1, 2, 3],
    [2, 1, 3],
])('wtf %i %i %i', (a, b, expected) => {
    expect(a + b).toBe(expected);
});

This will print tests like:
wtf 1 1 2
wtf 1 2 3
wtf 2 1 3

And passing a parameter to jest CLI like -t ''wtf %i %i %i'' will not work, while passing -t "wtf 1 1 2" will call a test only once and 2 other times will be skipped.

Is such case something that can be worked around by anything except by highlighting just the 'wtf' part?

Highlighting just part of the test title without placeholder parts actually works fine =)

@firsttris
Copy link
Owner

firsttris commented Jul 16, 2020

@PizzaPartyInc thats absolutly correct. but we could probably achieve the something like "-t wtf" without the need of highlighting it, if this can be parsed by the jest parser of jest-editor-support. which means you can just right-click without the need of highlighting. highlighting is more like a fallback if the jest parser fails.

this featue has now been implemented in jest-editor-support v28.0.0-beta.0 https://github.com/jest-community/jest-editor-support/releases/tag/v28.0.0-beta.0

Test Example:
https://github.com/jest-community/jest-editor-support/blob/master/fixtures/parser_tests.js#L374

@Cellule
Copy link
Contributor

Cellule commented Sep 6, 2020

One thing to note is that if a test file contains a single test.each all the Run|Debug buttons disappear
jest-runner-each

@Cellule
Copy link
Contributor

Cellule commented Sep 22, 2020

One thing to note is that if a test file contains a single test.each all the Run|Debug buttons disappear

I've confirmed that jest-editor-support v28.0.0-beta.0 fixes that issue, but it still has the problem where formatting elements remain in the test name

$ node "…\jest\bin\jest.js" "…/__tests__/testfile.spec.ts" -t "test with .each: %s" --runInBand --forceExit
Test Suites: 1 skipped, 0 of 1 total
Tests:       7 skipped, 7 total
Snapshots:   0 total
Time:        6.352s, estimated 8s

@dcrystalj
Copy link

@Cellule can you try again? looks like this was addressed recently jest-community/jest-editor-support#57

@Cellule
Copy link
Contributor

Cellule commented Jan 8, 2021

Like I said last time, it is already mostly working with v28, however this extension needs to update to it because it's a major version it won't automatically update
That PR you linked might make additional fixes, but I haven't tried it out yet

@firsttris
Copy link
Owner

test.each is supported now

@Cellule
Copy link
Contributor

Cellule commented Apr 11, 2021

Just tested it and it works perfectly ! Thanks

@PizzaPartyInc
Copy link

Yep! Works nicely! Thanks!
Found just one small issue. You cannot quote placeholders in test title. e.g. This works

it.each([1, 2, 3])('wrap something into quotes: %s', async (num) => {
   expect(num).toBe(num);
});

And this throws an error:

it.each([1, 2, 3])('wrap something into quotes: "%s"', async (num) => {
   expect(num).toBe(num);
});
PS C:\Project_Name> node "C:\Project_Name/node_modules/jest/bin/jest.js" "C:\Project_Name/test_file.spec.ts" -c "C:\Project_Name/jest.config.js" -t "wrap something into quotes: "(.*?)""
.*? : The term '.*?' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:337
+ ... wrap something into quotes: "(.*?)""
+                                                                    ~~~
    + CategoryInfo          : ObjectNotFound: (.*?:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Not sure if having quoted placeholders is a good approach or not... =)
Also, maybe it's just a Windows thing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants