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

Throw on module collision #1750

Merged
merged 5 commits into from
Sep 22, 2016
Merged

Throw on module collision #1750

merged 5 commits into from
Sep 22, 2016

Conversation

matryoshcow
Copy link
Contributor

Summary

Add throwOnModuleCollision option to jest-haste-map. Setting this to true will cause it to throw an error (rather than output a warning to console) when a module name collision is detected. This is useful for scenarios where determinism is critical.

Test plan

npm test

Ovidiu Viorel Iepure added 2 commits September 20, 2016 16:49
…an error when a module name collision is detected (as opposed to simply printing a warning)
@codecov-io
Copy link

codecov-io commented Sep 20, 2016

Current coverage is 87.41% (diff: 100%)

Merging #1750 into master will decrease coverage by 0.30%

@@             master      #1750   diff @@
==========================================
  Files            31         38     +7   
  Lines          1181       1200    +19   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits           1036       1049    +13   
- Misses          145        151     +6   
  Partials          0          0          

Powered by Codecov. Last update 047144b...767bfc9

@@ -273,6 +275,16 @@ class HasteMap {
getPlatformExtension(module[H.PATH]) || H.GENERIC_PLATFORM;
const existingModule = moduleMap[platform];
if (existingModule && existingModule[H.PATH] !== module[H.PATH]) {
if (this._options.throwOnModuleCollision) {
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.

it looks like we are duplicating the entire message twice now with the only difference being error and warning. Can we instead assign the message to a variable only once and do one of these:

  • Instead of warning and error, use message.
  • Use ${this._options.throwOnModuleCollision ? 'error' : 'message'} :)

@@ -49,6 +49,7 @@ type Options = {
retainAllFiles: boolean,
roots: Array<string>,
useWatchman?: boolean,
throwOnModuleCollision?: boolean,
Copy link
Member

Choose a reason for hiding this comment

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

please alphabetize the items in this list, we try to be consistent wherever we can :)

@@ -189,6 +190,7 @@ class HasteMap {
roots: options.roots,
useWatchman:
options.useWatchman == null ? true : options.useWatchman,
throwOnModuleCollision: options.throwOnModuleCollision,
Copy link
Member

Choose a reason for hiding this comment

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

alphabetize here too within the context of this._options :)

Copy link
Member

Choose a reason for hiding this comment

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

Because this option is optional, we should do !!options.throwOnModuleCollision

Copy link
Member

@cpojer cpojer left a comment

Choose a reason for hiding this comment

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

Looks good! Just a few minor nits to clean up the code a tiny bit.

@cpojer cpojer merged commit a5832d8 into jestjs:master Sep 22, 2016
@cpojer
Copy link
Member

cpojer commented Sep 22, 2016

nice work!

mthmulders pushed a commit to mthmulders/jest that referenced this pull request Oct 10, 2016
* add throwOnModuleCollision option that, when set to true, will throw an error when a module name collision is detected (as opposed to simply printing a warning)

* fix lint errors

* alphabetize options; made code more compact

* Update index.js

* Update index-test.js.snap
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
* add throwOnModuleCollision option that, when set to true, will throw an error when a module name collision is detected (as opposed to simply printing a warning)

* fix lint errors

* alphabetize options; made code more compact

* Update index.js

* Update index-test.js.snap
@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 14, 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