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

feat: make node-notifier an optional dependency #8918

Merged
merged 2 commits into from
Sep 12, 2019

Conversation

everett1992
Copy link
Contributor

Summary

notify is an optional feature that is disabled by default. Its implementation requires node-notifier, which distributes snoreToast, a LGPL-3.0 executable. node-notifier also includes terminal-notifier and notifu which are not MIT licensed.

My employer will not import node-notifier to our npm repository due to the LGPL executable which means we cannot use jest.

This pull request make node-notifier an optional dependency, so jest install will not fail if node-notifier cannot be found. jest will throw an error if notifications are enabled and node-notifier cannot be found.

Test plan

Tested by running jest --notify after removing node-notifier from node_modules.

jest errors with 'notify reporter requires optional dependency node-notifier but it was not found'

Tested by running jest after removing node-notifier

jest completes successfully

Tested by running jest --notify without removing node-notifier.

jest completes successfully with notifications.

@facebook-github-bot
Copy link
Contributor

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@codecov-io
Copy link

codecov-io commented Sep 6, 2019

Codecov Report

Merging #8918 into master will increase coverage by 0.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8918      +/-   ##
==========================================
+ Coverage   64.23%   64.25%   +0.01%     
==========================================
  Files         276      276              
  Lines       11700    11706       +6     
  Branches     2864     2865       +1     
==========================================
+ Hits         7516     7522       +6     
  Misses       3552     3552              
  Partials      632      632
Impacted Files Coverage Δ
packages/jest-reporters/src/notify_reporter.ts 75% <88.88%> (+3.26%) ⬆️

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 736edd2...3cd3ee6. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

This works for me. Doesn't seem like it'll affect most users, so happy to make the change so you can adopt Jest.

Could you add a unit test? I haven't tried before, but I assume you can throw inside of the factory of jest.mock.

Also, please update the changelog and sign the CLA

@everett1992 everett1992 force-pushed the notifier branch 2 times, most recently from f59358d to 965a4f9 Compare September 6, 2019 19:27
@everett1992
Copy link
Contributor Author

  • Amazon has a corporate relationship with Facebook, I'm waiting on an internal response to the CLA
  • What kind of changelog update makes sense to you? I think it's a fix.

@SimenB
Copy link
Member

SimenB commented Sep 7, 2019

What kind of changelog update makes sense to you? I think it's a fix.

Yeah, I think so

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

If we can avoid the duplicated types, I think this is good to go!

CHANGELOG.md Outdated Show resolved Hide resolved
packages/jest-reporters/src/notify_impl.ts Outdated Show resolved Hide resolved
packages/jest-reporters/src/notify_impl.ts Outdated Show resolved Hide resolved
@everett1992
Copy link
Contributor Author

The node-notifier typedefs are nasty so I switched to loadNotifier returning typeof import('node-notifier').

loadNotifier is almost a generic require-with-nice-message-on-optional-dependency except the type is typeof import('node-notifier').

Typescript doesn't allow typeof import(generic), it must have a string literal.

// error :(
function requireOptional<M extends string>(path: M): typeof import(M) | null {
  try {
    return require(path);
  } catch (err) {
    return null;
  }
}

I created an issue against Typescript asking for this feature a while ago with a different usecase.
microsoft/TypeScript#32705

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Awesome, thanks! Just need the CLA and we can merge

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@millette
Copy link

millette commented Mar 25, 2020

I just upgraded to 25.2.0 (from 25.1.0) where in my config notify: true. I'm not seeing notifications anymore.

npm ls node-notifier shows it's installed under @jest/[email protected] but I also installed it manually in my project. Still, no notifications, even when I jest --notify.

Details: #9701

@SimenB
Copy link
Member

SimenB commented Mar 25, 2020

This change was in 25.1.0 as well. Could be #9567? Could you revert that inside node_modules manually?
Regardless, please open up a separate issue with a reproduction 🙂

facebook-github-bot pushed a commit to facebook/metro that referenced this pull request Apr 20, 2020
Summary:
This diff upgrades Jest to the latest version which fixes a bunch of issues with snapshots (therefore allowing me to enable the Pressable-test again). Note that this also affects Metro and various other tooling as they all depend on packages like `jest-worker`, `jest-haste-map` etc.

Breaking changes: https://github.com/facebook/jest/blob/master/CHANGELOG.md

This diff increases node_modules by 3 MiB, primarily because it causes more duplicates of `source-map` (0.8 MiB for each copy) and packages like `chalk` 3.x (vs 2.x). The base install was 15 MiB bigger and I reduced it to this size by playing around with various manual yarn.lock optimizations. However, D21085929 reduces node_modules by 11 MiB and the Babel upgrade reduced node_modules by 13 MiB. I will subsequently work on reducing the size through other packages as well and I'm working with the Jest folks to get rid of superfluous TypeScript stuff for Jest 26.

Other changes in this diff:
* Fixed Pressable-test
* Blackhole node-notifier: It's large and we don't need it, and also the license may be problematic, see: jestjs/jest#8918
* Updated jest-junit (not a Jest package) but blackholed it internally because it is only used for open source CI.
* Updated some API calls we use from Jest to account for breaking changes
* Made two absolutely egrigious changes to existing product code tests to make them still pass as our match of async/await, fake timers and then/promise using `setImmediate` is tripping up `regenerator` with `Generator is already run` errors in Jest 25. These tests should probably be rewritten.
* Locked everything to the same `resolve` version that we were already using, otherwise it was somehow pulling in 1.16 even though nothing internally uses it.

Changelog: [General] Update Jest

Reviewed By: rickhanlonii

Differential Revision: D21064825

fbshipit-source-id: d0011a51355089456718edd84ea0af21fd923a58
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Apr 20, 2020
Summary:
This diff upgrades Jest to the latest version which fixes a bunch of issues with snapshots (therefore allowing me to enable the Pressable-test again). Note that this also affects Metro and various other tooling as they all depend on packages like `jest-worker`, `jest-haste-map` etc.

Breaking changes: https://github.com/facebook/jest/blob/master/CHANGELOG.md

This diff increases node_modules by 3 MiB, primarily because it causes more duplicates of `source-map` (0.8 MiB for each copy) and packages like `chalk` 3.x (vs 2.x). The base install was 15 MiB bigger and I reduced it to this size by playing around with various manual yarn.lock optimizations. However, D21085929 reduces node_modules by 11 MiB and the Babel upgrade reduced node_modules by 13 MiB. I will subsequently work on reducing the size through other packages as well and I'm working with the Jest folks to get rid of superfluous TypeScript stuff for Jest 26.

Other changes in this diff:
* Fixed Pressable-test
* Blackhole node-notifier: It's large and we don't need it, and also the license may be problematic, see: jestjs/jest#8918
* Updated jest-junit (not a Jest package) but blackholed it internally because it is only used for open source CI.
* Updated some API calls we use from Jest to account for breaking changes
* Made two absolutely egrigious changes to existing product code tests to make them still pass as our match of async/await, fake timers and then/promise using `setImmediate` is tripping up `regenerator` with `Generator is already run` errors in Jest 25. These tests should probably be rewritten.
* Locked everything to the same `resolve` version that we were already using, otherwise it was somehow pulling in 1.16 even though nothing internally uses it.

Changelog: [General] Update Jest

Reviewed By: rickhanlonii

Differential Revision: D21064825

fbshipit-source-id: d0011a51355089456718edd84ea0af21fd923a58
@winnemucca
Copy link

I am reading through the conversation about node-notifier. To be clear the optional flag was added in 25.1.0? With notify: false I will no longer have a dependency on node-notifier? This will also not be included in my node_modules?

@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 11, 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.

7 participants