-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.only
valid?
Should be, yes
Is this
test.concurrent.each
valid?
As mentioned, I think that's the way it should be written.
There does not seem to be tests for concurrent both in
jest-jasmine
andjest-circus
, tests injest-circus
are usingexeca
for 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
@@ -170,6 +174,9 @@ function makeConcurrent( | |||
|
|||
return originalFn.call(env, specName, () => promise, timeout); | |||
}; | |||
|
|||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the each install should happen in here? cc/ @SimenB
(Not to familiar with this section of the codebase)
return globals; | ||
}; | ||
|
||
describe('jest-each', () => { | ||
[ | ||
['test'], | ||
['test', 'concurrent'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to add test cases for
test.concurrent.skip
and test.concurrent.only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example on how to test skip
would be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mark1626 these comments are addressed, right? The tests on line 45 and 46
return globals; | ||
}; | ||
|
||
describe('jest-each', () => { | ||
[ | ||
['test'], | ||
['test', 'concurrent'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is A
? Can you give it a more descriptive name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed it to EachCallback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, GJ!
- Change generic to meaningful name - Update CHANGELOG
47fc1c8
to
0af6632
Compare
@@ -465,6 +465,170 @@ test('has lemon in it', () => { | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had forgotten this is undocumented... Can you add something like
Note:
test.concurrent
is 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 |
@@ -187,6 +191,8 @@ function makeConcurrent( | |||
|
|||
return spec; | |||
}; | |||
concurrentFn.each = () => {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.only
valid?test.concurrent.each
valid?jest-jasmine
andjest-circus
, tests injest-circus
are usingexeca
for running the tests I can't seem to run a test which hastest.concurrent
Notes on implementation
each.concurrent
jest-each
bindConcurrent
jest-each
, will remove it raising as draft PR for now to get clarificationsbindConcurrent
injest-jasmine
andjest-circus
Example
Test plan
Have added tests in
jest-each
,jest-jasmine
, as forjest-circus
I've added an open point regarding this\ cc @SimenB