feat: support concurrent in Jest Each#9326
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9326 +/- ##
==========================================
- Coverage 64.77% 64.74% -0.03%
==========================================
Files 280 280
Lines 11987 12002 +15
Branches 2956 2957 +1
==========================================
+ Hits 7764 7771 +7
- Misses 3591 3599 +8
Partials 632 632
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Sorry about the slow response, I've been away for the holidays.
This looks great! Missing changelog, docs and integration tests, but I'm sure you're aware of that already 🙂
Only thing is that I wonder if test.concurrent.each makes more sense than test.each.concurrent?
e.g.
test.concurrent.each`
thing | otherThing
${'1'} | ${'2'}
`('%s %s')(({ thing, otherThing }) => {
expect(thing).not.toEqual(otherThing);
});It would look weird to add the concurrent modifier at the end here, methinks, like so
test.each`
thing | otherThing
${'1'} | ${'2'}
`('%s %s').concurrent(({ thing, otherThing }) => {
expect(thing).not.toEqual(otherThing);
});Is this
test.each.concurrent.onlyvalid?
Should be, yes
Is this
test.concurrent.eachvalid?
As mentioned, I think that's the way it should be written.
There does not seem to be tests for concurrent both in
jest-jasmineandjest-circus, tests injest-circusare usingexecafor running the tests I can't seem to run a test which hastest.concurrent
Yeah, .concurrent isn't really well tested. I'd add an integration test showing that the tests run/skip as expected. In https://github.com/facebook/jest/blob/9419034d6b575fe2c157453fe8b7d2000be66aad/e2e/__tests__/jasmineAsync.test.ts seems sensible (although maybe the jasmine part of the name is a bit misleading)
|
@SimenB Hope you had a good vacation.
The current behavior right now in both Is there a reason I'll check out the test and add it |
I had a wonderful vacation, thank you!
Not as far as I know, that seems like an oversight. We can address that in a separate PR though - if they're no supported now there's not need to add support for |
|
Hey all, I've just taken a look over this and the associated issue - I'm in agreement with @SimenB that the API should be: This is inline with what we have for In addition to As for the code changes, I don't think we should duplicate I've knocked up a proof of concept with the types here: #9390 Let me know your thoughts and happy to answer any questions 😄 |
|
I was hacking around with this signature to have a single bind function, seem to be getting issues elsewhere. export default function bind<
T extends GlobalCallback | GlobalCallbackConcurrent
>(cb: T, supportsDone: boolean = true) {
return (
table: Global.EachTable,
...taggedTemplateData: Global.TemplateData
) =>
function eachBind(
title: string,
test: T extends GlobalCallbackConcurrent
? Global.ConcurrentEachTestFn
: Global.EachTestFn,
timeout?: number,
): void {};
}I'll explore @mattphillips 's approach |
d0981c8 to
2f9de45
Compare
| return originalFn.call(env, specName, () => promise, timeout); | ||
| }; | ||
|
|
||
| // @ts-ignore |
There was a problem hiding this comment.
I'm not sure about this line.
The return of this function seems to be ItConcurrentBase and needs an each function to be present.
We bind the each after calling jasmineAsyncInstall, so I added the ts-ignore.
Or would an empty each function be better than ts-ignore
There was a problem hiding this comment.
Maybe the each install should happen in here? cc/ @SimenB
(Not to familiar with this section of the codebase)
| describe('jest-each', () => { | ||
| [ | ||
| ['test'], | ||
| ['test', 'concurrent'], |
There was a problem hiding this comment.
Probably want to add test cases for
test.concurrent.skip and test.concurrent.only
There was a problem hiding this comment.
An example on how to test skip would be great
There was a problem hiding this comment.
@Mark1626 these comments are addressed, right? The tests on line 45 and 46
| describe('jest-each', () => { | ||
| [ | ||
| ['test'], | ||
| ['test', 'concurrent'], |
There was a problem hiding this comment.
Same as above comment
|
@mattphillips @SimenB Tests inside the each are not counted. test.each(
[
[1, 1, 2],
[1, 2, 3],
[2, 1, 3]
],
"returns the result of adding %d to %d",
async (a, b, expected) => {
expect(a + b).toBe(expected);
}
);A simple test file with this test results in |
|
Hi! Would very much like this PR to be merged :) What's the current status? |
|
@jimmycallin Got busy a bit with work I'll continue the work |
|
This is great! 🙌 Thank you |
2134ef4 to
2c65b21
Compare
|
I had to squash the commits as rebase was a major nightmare. Summing up so far: Currently supported
|
|
Sorry, but bump |
SimenB
left a comment
There was a problem hiding this comment.
Thanks! I believe this is pretty much ready to go, pending some doc updates with the new APIs.
@mattphillips wanna look over again?
packages/jest-each/src/bind.ts
Outdated
| table: Global.EachTable, | ||
| ...taggedTemplateData: Global.TemplateData | ||
| ) => | ||
| export default <A extends Global.TestCallback>( |
There was a problem hiding this comment.
What is A? Can you give it a more descriptive name?
There was a problem hiding this comment.
Renamed it to EachCallback
mattphillips
left a comment
There was a problem hiding this comment.
Looks good to me, GJ!
- Change generic to meaningful name - Update CHANGELOG
47fc1c8 to
0af6632
Compare
|
|
||
| Even though the call to `test` will return right away, the test doesn't complete until the promise resolves as well. | ||
|
|
||
| ### `test.concurrent(name, fn, timeout)` |
There was a problem hiding this comment.
I had forgotten this is undocumented... Can you add something like
Note:
test.concurrentis considered experimental - see https://github.com/facebook/jest/labels/Area%3A%20Concurrent for details on missing features and other issues
|
Ignore the leak failures on node 14, it's a regression in node: nodejs/node#34636 |
|
|
||
| return spec; | ||
| }; | ||
| concurrentFn.each = () => {}; |
There was a problem hiding this comment.
In jest-jasmine2 each is binded after the function is made concurrent, so I had it as a no-op as it will eventually be added. In the previous iterations I had to do a ts-ignore. I'm open to change it
There was a problem hiding this comment.
a code comment explaining why makes sense to me
concurrent in Jest Each
|
Thanks @Mark1626! |
|
Yay! Thanks @Mark1626! |
|
@SimenB @mattphillips Thanks for the support and opportunity |
|
@SimenB Any idea on when this might be released? |
|
@SimenB @Mark1626 I have been testing out Another issue I noticed (not sure if it's related), once the run is complete and the report is printed to the console, the elapsed time (in ms) that typically show up like so None of this behavior is reproducible when simply switching to |
|
@nickhodaly I'll check what's the problem, do you have a repl/repo I can use to recreate this |
Before you waste your time looking into let me double check I am not making some newbie JS related mistake. First time using JS so still grasping async/await. I will let you know what I find soon. Really appreciate your quick response though. @Mark1626 |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Fixes #8985.
Supported .concurrent in test.each
Open Points need to discuss
test.each.concurrent.onlyvalid?test.concurrent.eachvalid?jest-jasmineandjest-circus, tests injest-circusare usingexecafor running the tests I can't seem to run a test which hastest.concurrentNotes on implementation
each.concurrentjest-eachbindConcurrentjest-each, will remove it raising as draft PR for now to get clarificationsbindConcurrentinjest-jasmineandjest-circusExample
Test plan
Have added tests in
jest-each,jest-jasmine, as forjest-circusI've added an open point regarding this\ cc @SimenB