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

Change Promise detection code in jest-circus to support non-global Promise implementations #4375

Merged
merged 2 commits into from
Aug 27, 2017

Conversation

suchipi
Copy link
Contributor

@suchipi suchipi commented Aug 27, 2017

Summary

This isn't related to any particular open issue with jest-circus, but I noticed it while reading through the code to familiarize myself with it, and so decided to submit it on the side as a small improvement.

To provide better interop for Promise libraries such as bluebird and Q, this changes
the part of jest-circus that detects a returned Promise from a test or hook to only
check that the value is an object with a then method on it, rather than checking that
the value is instanceof Promise. This is considered the standard way of checking for
a Promises/A+-compliant Promise. As an added bonus, this check works cross-realm.

Test plan

I think we should add an integration test to this that pulls in bluebird, Q, or jQuery deferred, and verifies that the test runs as expected, but I'm not sure how to add an integration test that has a dependency like that. Should it be a dev dependency of the whole project?

…omise implementations

To provide better interop for Promise libraries such as bluebird and Q, this changes
the part of jest-circus that detects a returned Promise from a test or hook to only
check that the value is an object with a then method on it, rather than checking that
the value is instanceof Promise. This is considered the standard way of checking for
a Promises/A+-compliant Promise. As an added bonus, this check works cross-realm.
@codecov-io
Copy link

codecov-io commented Aug 27, 2017

Codecov Report

Merging #4375 into master will decrease coverage by 0.35%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4375      +/-   ##
==========================================
- Coverage    56.2%   55.85%   -0.36%     
==========================================
  Files         191      189       -2     
  Lines        6421     6383      -38     
  Branches        6        6              
==========================================
- Hits         3609     3565      -44     
- Misses       2809     2815       +6     
  Partials        3        3
Impacted Files Coverage Δ
packages/jest-circus/src/utils.js 0% <0%> (ø) ⬆️
...ckages/jest-cli/src/reporters/get_result_header.js 78.57% <0%> (-3.79%) ⬇️
...ackages/jest-cli/src/reporters/default_reporter.js 91.04% <0%> (-0.39%) ⬇️
packages/jest-cli/src/reporters/Status.js 93.75% <0%> (-0.19%) ⬇️
packages/jest-config/src/normalize.js 78.26% <0%> (ø) ⬆️
packages/jest-config/src/index.js 0% <0%> (ø) ⬆️
...ges/jest-cli/src/reporters/get_snapshot_summary.js
...ages/jest-cli/src/reporters/get_snapshot_status.js
packages/jest-cli/src/reporters/utils.js 62.5% <0%> (+1.11%) ⬆️
...ackages/jest-cli/src/reporters/summary_reporter.js 19.69% <0%> (+7.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e535665...6374969. Read the comment docs.

@cpojer cpojer merged commit a3ed980 into jestjs:master Aug 27, 2017
@cpojer
Copy link
Member

cpojer commented Aug 27, 2017

Nice! I updated the comment a bit to not mention specific custom Promise implementations as those ones likely won't be relevant in the future.

@suchipi
Copy link
Contributor Author

suchipi commented Aug 27, 2017

Do we want to add a test for this?

@cpojer
Copy link
Member

cpojer commented Aug 27, 2017

Yes, if you want to add some. The old code already does this, so it's simply aligning the implementation but explicit tests are always good.

@suchipi
Copy link
Contributor Author

suchipi commented Aug 29, 2017

I started writing some tests for this but ran into some weirdness around #3785. I don't want to add tests that don't pass with jasmine, but pass with circus, so I'll defer adding tests for this until circus is the only runner.

@github-actions
Copy link

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.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants