question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reduce dependency count

See original GitHub issue

Describe the feature you’d like:

Reduce the number of dependencies installed when installing dom-testing-library. The feature set of this package is fantastic for anyone writing tests against the DOM.

Being able to query against the DOM in the language of your users and using waitFor & other techniques to deal with asynchronous frameworks is really really nice.

Currently when I install this library I get

β”œβ”€β”¬ @testing-library/dom@7.5.2
β”‚ β”œβ”€β”¬ @babel/runtime@7.9.6
β”‚ β”‚ └── regenerator-runtime@0.13.5
β”‚ β”œβ”€β”¬ aria-query@4.0.2
β”‚ β”‚ β”œβ”€β”€ @babel/runtime@7.9.6 deduped
β”‚ β”‚ └─┬ @babel/runtime-corejs3@7.9.6
β”‚ β”‚   β”œβ”€β”€ core-js-pure@3.6.5
β”‚ β”‚   └── regenerator-runtime@0.13.5 deduped
β”‚ β”œβ”€β”€ dom-accessibility-api@0.4.3
β”‚ └─┬ pretty-format@26.0.1
β”‚   β”œβ”€β”¬ @jest/types@26.0.1
β”‚   β”‚ β”œβ”€β”€ @types/istanbul-lib-coverage@2.0.1
β”‚   β”‚ β”œβ”€β”¬ @types/istanbul-reports@1.1.1
β”‚   β”‚ β”‚ β”œβ”€β”€ @types/istanbul-lib-coverage@2.0.1 deduped
β”‚   β”‚ β”‚ └─┬ @types/istanbul-lib-report@3.0.0
β”‚   β”‚ β”‚   └── @types/istanbul-lib-coverage@2.0.1 deduped
β”‚   β”‚ β”œβ”€β”¬ @types/yargs@15.0.4
β”‚   β”‚ β”‚ └── @types/yargs-parser@15.0.0
β”‚   β”‚ └─┬ chalk@4.0.0
β”‚   β”‚   β”œβ”€β”€ ansi-styles@4.2.1 deduped
β”‚   β”‚   └─┬ supports-color@7.1.0
β”‚   β”‚     └── has-flag@4.0.0
β”‚   β”œβ”€β”€ ansi-regex@5.0.0
β”‚   β”œβ”€β”¬ ansi-styles@4.2.1
β”‚   β”‚ β”œβ”€β”€ @types/color-name@1.1.1
β”‚   β”‚ └─┬ color-convert@2.0.1
β”‚   β”‚   └── color-name@1.1.4 deduped
β”‚   └── react-is@16.13.1

29 dependencies, from these it looks like only ( @testing-library/dom ; dom-accessibility-api ; aria-query ; pretty-format ; ansi-styles ; color-convert ; color-name ) are useful dependencies.

It would be great if installing this library only installed 3 dependencies and if it had 4 optional dependencies ( pretty-format & ansi-* make great optional dependencies )

Suggested implementation:

To reduce dependency count the following could be implemented

  • Removing babel dependency
  • Remove nested babel dependency from aria-query
  • Make pretty-format an optional dependencies
  • Remove @jest/types from pretty-format or replace pretty-format with a smaller library.

Describe alternatives you’ve considered:

🀷

Teachability, Documentation, Adoption, Migration Strategy:

Having an optional dependency does require teaching users that pretty-format can be installed to pretty print the errors and warnings generated by dom-testing-library.

Your tests will work fine as is but might not be as pretty when looking at the output of a test failure without having installed pretty-format

An optional dependency looks like

let prettyFormat
try {
  prettyFormat = require('pretty-format')
} catch (err) {
  console.warn('If you would like a pretty error; please npm install pretty-format')
}

/* ... */

// In the library itself; wrap every usage of `prettyFormat` in a ternary or if statement
console.log(prettyFormat ? prettyFormat(x) : x)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kentcdoddscommented, May 12, 2020

Thanks for sharing your opinions @Raynos, but I think there’s a values misalignment here so I don’t expect this to go anywhere. Sorry.

1reaction
eps1loncommented, May 12, 2020

As an alternative to an optional dependency we could vendor it.

So we would need to maintain it rather than the folks over at jest? That doesn’t sound like a solution to me.

I understand the general concern but I don’t agree with the extreme step to simply cut it. All of the listed dependencies (with the exception of dom-accessibility-api maybe) are maintained either by large orgs or long term OSS maintainers.

The security risk they pose seems to be on the same level as using testing-library itself. It sounds like there is some subtext here I’m not getting. Could you explain why pretty-format is such an issue for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are good ways to reduce the number of dependencies?
One way to handle those is to refactor towards Aggregates (or Facades). Mark Seemann wrote a good article on it, check it out...
Read more >
Removing Dependencies: One Weird Trick for Increasing ...
Code in an unmaintained dependency may either stop compiling or, more often, cause compilation warnings because of deprecations. TheseΒ ...
Read more >
How to Prevent Dependency Confusion - ActiveState
Click to learn the simple best practices you can implement to mitigate the risk of dependency confusion supply chain attacks.
Read more >
solid - How to reduce dependency on IOC Framework ...
The easiest way to avoid dependencies on a framework is to not use a framework. Abstracting frameworks just doesn't work in practice.
Read more >
Blog: Wide Haskell - Reducing your Dependencies - Reddit
Is there any easy way to list immediate dependencies of a (stack) project with count of the transitive dependencies for each?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found