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

Make "weak" optional dependency and check it at runtime #4984

Merged
merged 2 commits into from
Nov 29, 2017
Merged

Make "weak" optional dependency and check it at runtime #4984

merged 2 commits into from
Nov 29, 2017

Conversation

mjesun
Copy link
Contributor

@mjesun mjesun commented Nov 29, 2017

On systems that do not support Node bindings, adding weak as a dependency will make it crash. Since most of the times jest-leak-detector is not used at all, making the dependency optional and delaying its instantiation will fix the issue.

Tested by running ./jest jest-leak-detector.

@codecov-io
Copy link

codecov-io commented Nov 29, 2017

Codecov Report

Merging #4984 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #4984      +/-   ##
=========================================
+ Coverage   60.27%   60.3%   +0.02%     
=========================================
  Files         198     198              
  Lines        6659    6661       +2     
  Branches        3       3              
=========================================
+ Hits         4014    4017       +3     
+ Misses       2645    2644       -1
Impacted Files Coverage Δ
packages/jest-leak-detector/src/index.js 72.72% <100%> (+7.72%) ⬆️

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 ef55e89...c92a513. Read the comment docs.

@cpojer cpojer merged commit e00529d into jestjs:master Nov 29, 2017
try {
weak = require('weak');
} catch (err) {
throw new Error(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hides all sorts of errors. can we do an explicit check for MODULE_NOT_FOUND, and if not, rethrow original error?

(can use https://www.npmjs.com/package/optional and rethrow, but rolling our own should not be an issue)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for convenience, optional would be something like

const weak = optional('weak', { rethrow: true });

if (!weak) {
  throw new Error(
    'The leaking detection mechanism requires the "weak" package to work. ' +
      'Please make sure that you can install the native dependency on your platform.',
  );
}

current usage is just an if away, so might not be worth the extra dep 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the stricter check, let me add that into a new PR but as our own custom check; checking error.code should not require a new dependency 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #5010.

mjesun added a commit that referenced this pull request Dec 4, 2017
mjesun added a commit that referenced this pull request Dec 4, 2017
cpojer pushed a commit that referenced this pull request Dec 4, 2017
* Revert "docs: update expect.anything() example (#5007)"

This reverts commit ea3fabc.

* Revert "Emphasise required return (#4999)"

This reverts commit 4f1113c.

* Revert "Makes NPM a link like Yarn is (#4998)"

This reverts commit aa4f09d.

* Revert "Update Timeout error message to `jest.timeout` and display current timeout value (#4990)"

This reverts commit 08f8394.

* Revert "fix: jest-util should not depend on jest-mock (#4992)"

This reverts commit 4e2f41f.

* Revert "Update Troubleshooting.md (#4988)"

This reverts commit 6414f28.

* Revert "Revert "Add the Yammer logo to the 'who is using this' section of the website." (#4987)"

This reverts commit 91b104f.

* Revert "Make "weak" optional dependency and check it at runtime (#4984)"

This reverts commit e00529d.

* Revert "Re-inject native Node modules (#4970)"

This reverts commit ef55e89.
@mjesun mjesun deleted the make-weak-optional branch December 6, 2017 11:46
@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.

5 participants